[cfe-commits] r172762 - in /cfe/trunk: lib/Analysis/PrintfFormatString.cpp test/FixIt/format.m test/Index/fix-its.c test/Misc/caret-diags-macros.c test/Sema/format-strings-fixit.c

Jordan Rose jordan_rose at apple.com
Thu Jan 17 14:34:10 PST 2013


Author: jrose
Date: Thu Jan 17 16:34:10 2013
New Revision: 172762

URL: http://llvm.org/viewvc/llvm-project?rev=172762&view=rev
Log:
Format strings: don't ever convert %+d to %lu.

Presumably, if the printf format has the sign explicitly requested, the user
wants to treat the data as signed.

This is a fix-up for r172739, and also includes several test changes that
didn't make it into that commit.

Modified:
    cfe/trunk/lib/Analysis/PrintfFormatString.cpp
    cfe/trunk/test/FixIt/format.m
    cfe/trunk/test/Index/fix-its.c
    cfe/trunk/test/Misc/caret-diags-macros.c
    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=172762&r1=172761&r2=172762&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Thu Jan 17 16:34:10 2013
@@ -511,7 +511,7 @@
     case ConversionSpecifier::dArg:
     case ConversionSpecifier::DArg:
     case ConversionSpecifier::iArg:
-      if (QT->isUnsignedIntegerType())
+      if (QT->isUnsignedIntegerType() && !HasPlusPrefix)
         CS.setKind(clang::analyze_format_string::ConversionSpecifier::uArg);
       break;
     default:

Modified: cfe/trunk/test/FixIt/format.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/format.m?rev=172762&r1=172761&r2=172762&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/format.m (original)
+++ cfe/trunk/test/FixIt/format.m Thu Jan 17 16:34:10 2013
@@ -223,4 +223,8 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%lu"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%lu"
   // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%ld"
+
+  printf("%+d", u); // expected-warning{{format specifies type 'int' but the argument has type 'unsigned long'}}
+
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld"
 }

Modified: cfe/trunk/test/Index/fix-its.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/fix-its.c?rev=172762&r1=172761&r2=172762&view=diff
==============================================================================
--- cfe/trunk/test/Index/fix-its.c (original)
+++ cfe/trunk/test/Index/fix-its.c Thu Jan 17 16:34:10 2013
@@ -22,6 +22,6 @@
 void f2() {
   unsigned long index;
   // CHECK: warning: format specifies type 'int' but the argument has type 'unsigned long'
-  // CHECK: FIX-IT: Replace [26:17 - 26:19] with "%ld"
+  // CHECK: FIX-IT: Replace [26:17 - 26:19] with "%lu"
   MACRO(printf("%d", index));
 }

Modified: cfe/trunk/test/Misc/caret-diags-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/caret-diags-macros.c?rev=172762&r1=172761&r2=172762&view=diff
==============================================================================
--- cfe/trunk/test/Misc/caret-diags-macros.c (original)
+++ cfe/trunk/test/Misc/caret-diags-macros.c Thu Jan 17 16:34:10 2013
@@ -218,7 +218,7 @@
 // CHECK:         {{.*}}:216:62: warning: format specifies type 'int' but the argument has type 'unsigned long'
 // CHECK-NEXT:    Csprintf(pMsgBuf,"\nEnter minimum anagram length (2-%1d): ", Cstrlen(pKeepBuf));
 // CHECK-NEXT: {{^                                                    ~~~      \^}}
-// CHECK-NEXT: {{^                                                    %1ld}}
+// CHECK-NEXT: {{^                                                    %1lu}}
 // CHECK-NEXT:    {{.*}}:213:21: note: expanded from macro 'Cstrlen'
 // CHECK-NEXT:    #define Cstrlen(a)  strlen_test(a)
 // CHECK-NEXT: {{^                    \^}}

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=172762&r1=172761&r2=172762&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-fixit.c (original)
+++ cfe/trunk/test/Sema/format-strings-fixit.c Thu Jan 17 16:34:10 2013
@@ -165,7 +165,7 @@
 // Validate the fixes.
 // CHECK: printf("%d", (int) 123);
 // CHECK: printf("abc%s", "testing testing 123");
-// CHECK: printf("%lu", (long) -12);
+// CHECK: printf("%ld", (long) -12);
 // CHECK: printf("%d", 123);
 // CHECK: printf("%s\n", "x");
 // CHECK: printf("%f\n", 1.23);
@@ -193,11 +193,11 @@
 // CHECK: printf("%d", (my_int_type) 42);
 // CHECK: printf("%s", "foo");
 // CHECK: printf("%lo", (long) 42);
-// CHECK: printf("%lu", (long) 42);
+// CHECK: printf("%ld", (long) 42);
 // CHECK: printf("%lx", (long) 42);
 // CHECK: printf("%lX", (long) 42);
-// CHECK: printf("%li", (unsigned long) 42);
-// CHECK: printf("%ld", (unsigned long) 42);
+// CHECK: printf("%lu", (unsigned long) 42);
+// CHECK: printf("%lu", (unsigned long) 42);
 // CHECK: printf("%LF", (long double) 42);
 // CHECK: printf("%Le", (long double) 42);
 // CHECK: printf("%LE", (long double) 42);





More information about the cfe-commits mailing list