[cfe-commits] r106275 - in /cfe/trunk: include/clang/Analysis/Analyses/PrintfFormatString.h lib/Analysis/PrintfFormatString.cpp test/Sema/format-strings-fixit.c
Tom Care
tcare at apple.com
Thu Jun 17 20:02:16 PDT 2010
Author: tcare
Date: Thu Jun 17 22:02:16 2010
New Revision: 106275
URL: http://llvm.org/viewvc/llvm-project?rev=106275&view=rev
Log:
Printf format strings: Added some more tests and fixed some minor bugs.
- Precision toStrings shouldn't print a dot when they have no value.
- Length of char length modifier is now returned correctly.
- Added several fixit tests.
Note: fixit tests are currently broken due to a bug in HighlightRange. Marking as XFAIL for now.
M test/Sema/format-strings-fixit.c
M include/clang/Analysis/Analyses/PrintfFormatString.h
M lib/Analysis/PrintfFormatString.cpp
Modified:
cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/test/Sema/format-strings-fixit.c
Modified: cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h?rev=106275&r1=106274&r2=106275&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h Thu Jun 17 22:02:16 2010
@@ -166,6 +166,7 @@
default:
return 1;
case AsLongLong:
+ case AsChar:
return 2;
case None:
return 0;
@@ -218,12 +219,13 @@
}
const char *getStart() const {
- return start;
+ // We include the . character if it is given.
+ return start - UsesDotPrefix;
}
unsigned getConstantLength() const {
assert(hs == Constant);
- return length;
+ return length + UsesDotPrefix;
}
ArgTypeResult getArgType(ASTContext &Ctx) const;
Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=106275&r1=106274&r2=106275&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Thu Jun 17 22:02:16 2010
@@ -611,20 +611,21 @@
//===----------------------------------------------------------------------===//
void OptionalAmount::toString(llvm::raw_ostream &os) const {
- if (UsesDotPrefix)
- os << ".";
-
switch (hs) {
case Invalid:
case NotSpecified:
return;
case Arg:
+ if (UsesDotPrefix)
+ os << ".";
if (usesPositionalArg())
os << "*" << getPositionalArgIndex() << "$";
else
os << "*";
break;
case Constant:
+ if (UsesDotPrefix)
+ os << ".";
os << amt;
break;
}
Modified: cfe/trunk/test/Sema/format-strings-fixit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-fixit.c?rev=106275&r1=106274&r2=106275&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-fixit.c (original)
+++ cfe/trunk/test/Sema/format-strings-fixit.c Thu Jun 17 22:02:16 2010
@@ -1,6 +1,9 @@
// RUN: cp %s %t
// RUN: %clang_cc1 -pedantic -Wall -fixit %t || true
// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
+// XFAIL: *
+// FIXME: Some of these tests currently fail due to a bug in the HighlightRange
+// function in lib/Frontend/TextDiagnosticPrinter.cpp.
/* This is a test of the various code modification hints that are
provided as part of warning or extension diagnostics. All of the
@@ -25,7 +28,19 @@
// Flag handling
printf("%0+s", (unsigned) 31337); // flags should stay
printf("%0f", "test"); // flag should be removed
+ printf("%#p", (void *) 0);
// Positional arguments
printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4);
+
+ // Precision
+ printf("%10.5d", 1l); // (bug 7394)
+ printf("%.2c", 'a');
+
+ // Ignored flags
+ printf("%0-f", 1.23);
+
+ // Bad length modifiers
+ printf("%hhs", "foo");
+ printf("%1$zp", (void *)0);
}
More information about the cfe-commits
mailing list