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

Ted Kremenek kremenek at apple.com
Mon Apr 25 15:32:59 PDT 2011


Author: kremenek
Date: Mon Apr 25 17:32:59 2011
New Revision: 130164

URL: http://llvm.org/viewvc/llvm-project?rev=130164&view=rev
Log:
When generating printf fixits, preserve the original formating for unsigned integers (e.g., 'x', 'o').

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=130164&r1=130163&r2=130164&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Mon Apr 25 17:32:59 2011
@@ -441,7 +441,9 @@
     HasAlternativeForm = 0;
   }
   else if (QT->isUnsignedIntegerType()) {
-    CS.setKind(ConversionSpecifier::uArg);
+    // Preserve the original formatting, e.g. 'X', 'o'.
+    if (!cast<PrintfConversionSpecifier>(CS).isUIntArg())
+      CS.setKind(ConversionSpecifier::uArg);
     HasAlternativeForm = 0;
     HasPlusPrefix = 0;
   }

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=130164&r1=130163&r2=130164&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-fixit.c (original)
+++ cfe/trunk/test/Sema/format-strings-fixit.c Mon Apr 25 17:32:59 2011
@@ -1,6 +1,7 @@
 // RUN: cp %s %t
 // RUN: %clang_cc1 -pedantic -Wall -fixit %t || true
 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
+// RUN: %clang_cc1 -E -o - %t | FileCheck %s
 
 /* This is a test of the various code modification hints that are
    provided as part of warning or extension diagnostics. All of the
@@ -41,4 +42,29 @@
   // 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);
 }
+
+// Validate the fixes...
+// CHECK: printf("%d", (int) 123);
+// CHECK: printf("abc%s", "testing testing 123");
+// CHECK: printf("%ld", (long) -12);
+// CHECK: printf("%d", 123);
+// CHECK: printf("%s\n", "x");
+// CHECK: printf("%f\n", 1.23);
+// CHECK: printf("%.2llu", (unsigned long long) 123456);
+// CHECK: printf("%1Lf", (long double) 1.23);
+// CHECK: printf("%0u", (unsigned) 31337);
+// CHECK: printf("%p", (void *) 0);
+// CHECK: printf("%+f", 1.23);
+// CHECK: printf("%-f", 1.23);
+// CHECK: printf("%1$d:%2$.*3$d:%4$.*3$d\n", 1, 2, 3, 4);
+// CHECK: printf("%10.5ld", 1l);
+// CHECK: printf("%c", 'a');
+// CHECK: printf("%-f", 1.23);
+// CHECK: printf("%s", "foo");
+// CHECK: printf("%1$p", (void *)0);
+// CHECK: printf("%lX", val);





More information about the cfe-commits mailing list