]> granicus.if.org Git - clang/commitdiff
Small fixes regarding printf fix suggestions.
authorTom Care <tcare@apple.com>
Fri, 11 Jun 2010 04:22:02 +0000 (04:22 +0000)
committerTom Care <tcare@apple.com>
Fri, 11 Jun 2010 04:22:02 +0000 (04:22 +0000)
- 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105807 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/PrintfFormatString.cpp
test/Sema/format-strings-fixit.c

index 03aff386c26a62c8710793c00f8c5bf8f151f8ee..99dc22901c75896620e009464c2e7d7ce022ee46 100644 (file)
@@ -686,6 +686,10 @@ bool FormatSpecifier::fixType(QualType QT) {
   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 @@ bool FormatSpecifier::fixType(QualType QT) {
 
   // 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:
index ba38973049cb51bea01e0876b290036475ba41e6..9a1fef0401ae8d8189009a131212c84c383c7d2f 100644 (file)
 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);
 }