[cfe-commits] r146252 - in /cfe/trunk: lib/Analysis/PrintfFormatString.cpp test/Sema/format-strings-fixit.c

Hans Wennborg hans at hanshq.net
Fri Dec 9 02:51:30 PST 2011


Author: hans
Date: Fri Dec  9 04:51:29 2011
New Revision: 146252

URL: http://llvm.org/viewvc/llvm-project?rev=146252&view=rev
Log:
fix format specifier fixit for printf("%ld", "foo");

It should reset the length modifier (unless it's a wchar_t string).

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=146252&r1=146251&r2=146252&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Fri Dec  9 04:51:29 2011
@@ -366,6 +366,8 @@
     // Set the long length modifier for wide characters
     if (QT->getPointeeType()->isWideCharType())
       LM.setKind(LengthModifier::AsWideChar);
+    else
+      LM.setKind(LengthModifier::None);
 
     return true;
   }

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=146252&r1=146251&r2=146252&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-fixit.c (original)
+++ cfe/trunk/test/Sema/format-strings-fixit.c Fri Dec  9 04:51:29 2011
@@ -42,7 +42,7 @@
   // Bad length modifiers
   printf("%hhs", "foo");
   printf("%1$zp", (void *)0);
-  
+
   // Perserve the original formatting for unsigned integers.
   unsigned long val = 42;
   printf("%X", val);
@@ -57,6 +57,9 @@
   printf("%f", (intmax_t) 42);
   printf("%f", (uintmax_t) 42);
   printf("%f", (ptrdiff_t) 42);
+
+  // string
+  printf("%ld", "foo");
 }
 
 // Validate the fixes...
@@ -83,3 +86,4 @@
 // CHECK: printf("%jd", (intmax_t) 42);
 // CHECK: printf("%ju", (uintmax_t) 42);
 // CHECK: printf("%td", (ptrdiff_t) 42);
+// CHECK: printf("%s", "foo");





More information about the cfe-commits mailing list