зеркало из https://github.com/microsoft/clang-1.git
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172762 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
de03c15ad9
Коммит
cdbe1e0d85
|
@ -511,7 +511,7 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt,
|
|||
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:
|
||||
|
|
|
@ -223,4 +223,8 @@ void testSignedness(long i, unsigned long u) {
|
|||
// 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"
|
||||
}
|
||||
|
|
|
@ -22,6 +22,6 @@ int printf(const char *restrict, ...);
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ Csprintf(pMsgBuf,"\nEnter minimum anagram length (2-%1d): ", Cstrlen(pKeepBuf));
|
|||
// 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: {{^ \^}}
|
||||
|
|
|
@ -165,7 +165,7 @@ void test2() {
|
|||
// 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 @@ void test2() {
|
|||
// 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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче