[cfe-commits] r105807 - in /cfe/trunk: lib/Analysis/PrintfFormatString.cpp test/Sema/format-strings-fixit.c
Tom Care
tcare at apple.com
Thu Jun 10 21:22:02 PDT 2010
Author: tcare
Date: Thu Jun 10 23:22:02 2010
New Revision: 105807
URL: http://llvm.org/viewvc/llvm-project?rev=105807&view=rev
Log:
Small fixes regarding printf fix suggestions.
- Added some handling of flags that become invalid when changing the conversion specifier.
- Changed fixit behavior to remove unnecessary length modifiers.
- Separated some tests out and added some comments.
modified:
lib/Analysis/PrintfFormatString.cpp
test/Sema/format-strings-fixit.c
Modified:
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/test/Sema/format-strings-fixit.c
Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=105807&r1=105806&r2=105807&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Thu Jun 10 23:22:02 2010
@@ -686,6 +686,10 @@
if (QT->isPointerType() && (QT->getPointeeType()->isAnyCharacterType())) {
CS.setKind(ConversionSpecifier::CStrArg);
+ // Disable irrelevant flags
+ HasAlternativeForm = 0;
+ HasLeadingZeroes = 0;
+
// Set the long length modifier for wide characters
if (QT->getPointeeType()->isWideCharType())
LM.setKind(LengthModifier::AsWideChar);
@@ -699,10 +703,14 @@
// Everything else should be a base type
const BuiltinType *BT = QT->getAs<BuiltinType>();
+
// Set length modifier
switch (BT->getKind()) {
default:
+ // The rest of the conversions are either optional or for non-builtin types
+ LM.setKind(LengthModifier::None);
break;
+
case BuiltinType::WChar:
case BuiltinType::Long:
case BuiltinType::ULong:
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=105807&r1=105806&r2=105807&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-fixit.c (original)
+++ cfe/trunk/test/Sema/format-strings-fixit.c Thu Jun 10 23:22:02 2010
@@ -10,11 +10,19 @@
int printf(char const *, ...);
void test() {
- printf("%0s", (int) 123);
- printf("abc%f", "testing testing 123");
+ // Basic types
+ printf("%s", (int) 123);
+ printf("abc%0f", "testing testing 123");
printf("%u", (long) -12);
+
+ // Larger types
printf("%+.2d", (unsigned long long) 123456);
printf("%1d", (long double) 1.23);
- printf("%Ld", (long double) -4.56);
+
+ // Flag handling
+ printf("%0+s", (unsigned) 31337); // flags should stay
+ printf("%0f", "test"); // flag should be removed
+
+ // Positional arguments
printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4);
}
More information about the cfe-commits
mailing list