Skip to content

Commit ef99801

Browse files
committed
[Sema] Fix missing warnings for unused args with invalid printf specs.
1 parent 5719fb8 commit ef99801

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

clang/lib/AST/PrintfFormatString.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ bool clang::analyze_format_string::ParsePrintfString(FormatStringHandler &H,
440440
// Did a fail-stop error of any kind occur when parsing the specifier?
441441
// If so, don't do any more processing.
442442
if (FSR.shouldStop())
443-
return true;
443+
return false;
444444
// Did we exhaust the string or encounter an error that
445445
// we can recover from?
446446
if (!FSR.hasValue())

clang/test/Sema/format-strings.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ void check_invalid_specifier(FILE* fp, char *buf)
207207

208208
void check_null_char_string(char* b)
209209
{
210-
printf("\0this is bogus%d",1); // expected-warning {{string contains '\0'}}
211-
snprintf(b,10,"%%%%%d\0%d",1,2); // expected-warning {{string contains '\0'}}
212-
printf("%\0d",1); // expected-warning {{string contains '\0'}}
210+
printf("\0this is bogus%d",1); // expected-warning {{string contains '\0'}} expected-warning {{data argument not used by format string}}
211+
snprintf(b,10,"%%%%%d\0%d",1,2); // expected-warning {{string contains '\0'}} expected-warning {{data argument not used by format string}}
212+
printf("%\0d",1); // expected-warning {{string contains '\0'}} expected-warning {{data argument not used by format string}}
213213
}
214214

215215
void check_empty_format_string(char* buf, ...)
@@ -297,7 +297,7 @@ void test10(int x, float f, int i, long long lli) {
297297
printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 'W'}} expected-warning {{data argument not used by format string}}
298298
printf("%"); // expected-warning{{incomplete format specifier}}
299299
printf("%.d", x); // no-warning
300-
printf("%.", x); // expected-warning{{incomplete format specifier}}
300+
printf("%.", x); // expected-warning{{incomplete format specifier}} expected-warning {{data argument not used by format string}}
301301
printf("%f", 4); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
302302
printf("%qd", lli); // no-warning
303303
printf("%qd", x); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
@@ -390,8 +390,8 @@ void test_unicode_conversions(wchar_t *s) {
390390
// This is an IEEE extension (IEEE Std 1003.1).
391391
// FIXME: This is probably not portable everywhere.
392392
void test_positional_arguments(void) {
393-
printf("%0$", (int)2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
394-
printf("%1$*0$d", (int) 2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
393+
printf("%0$", (int)2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} expected-warning{{data argument not used by format string}}
394+
printf("%1$*0$d", (int) 2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} expected-warning{{data argument not used by format string}}
395395
printf("%1$d", (int) 2); // no-warning
396396
printf("%1$d", (int) 2, 2); // expected-warning{{data argument not used by format string}}
397397
printf("%1$d%1$f", (int) 2); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
@@ -595,16 +595,16 @@ void pr9751(void) {
595595
printf("%y", 5); // expected-warning{{invalid conversion specifier 'y'}}
596596

597597
const char kFormat5[] = "%."; // expected-note{{format string is defined here}}
598-
printf(kFormat5, 5); // expected-warning{{incomplete format specifier}}
599-
printf("%.", 5); // expected-warning{{incomplete format specifier}}
598+
printf(kFormat5, 5); // expected-warning{{incomplete format specifier}} expected-warning{{data argument not used by format string}}
599+
printf("%.", 5); // expected-warning{{incomplete format specifier}} expected-warning{{data argument not used by format string}}
600600

601601
const char kFormat6[] = "%s"; // expected-note{{format string is defined here}}
602602
printf(kFormat6, 5); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
603603
printf("%s", 5); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
604604

605605
const char kFormat7[] = "%0$"; // expected-note{{format string is defined here}}
606-
printf(kFormat7, 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
607-
printf("%0$", 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}}
606+
printf(kFormat7, 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} expected-warning{{data argument not used by format string}}
607+
printf("%0$", 5); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} expected-warning{{data argument not used by format string}}
608608

609609
const char kFormat8[] = "%1$d %d"; // expected-note{{format string is defined here}}
610610
printf(kFormat8, 4, 4); // expected-warning{{cannot mix positional and non-positional arguments in format string}}
@@ -615,8 +615,8 @@ void pr9751(void) {
615615
printf("", 4, 4); // expected-warning{{format string is empty}}
616616

617617
const char kFormat10[] = "\0%d"; // expected-note{{format string is defined here}}
618-
printf(kFormat10, 4); // expected-warning{{format string contains '\0' within the string body}}
619-
printf("\0%d", 4); // expected-warning{{format string contains '\0' within the string body}}
618+
printf(kFormat10, 4); // expected-warning{{format string contains '\0' within the string body}} expected-warning{{data argument not used by format string}}
619+
printf("\0%d", 4); // expected-warning{{format string contains '\0' within the string body}} expected-warning{{data argument not used by format string}}
620620

621621
const char kFormat11[] = "%*d"; // expected-note{{format string is defined here}}
622622
printf(kFormat11); // expected-warning{{'*' specified field width is missing a matching 'int' argument}}
@@ -720,8 +720,8 @@ extern void test14_bar(const char *, const char *, ...)
720720
__attribute__((__format__(__printf__, 1, 3)));
721721

722722
void test14_zed(int *p) {
723-
test14_foo("%", "%d", p); // expected-warning{{incomplete format specifier}}
724-
test14_bar("%", "%d", p); // expected-warning{{incomplete format specifier}}
723+
test14_foo("%", "%d", p); // expected-warning{{incomplete format specifier}} expected-warning{{data argument not used by format string}}
724+
test14_bar("%", "%d", p); // expected-warning{{incomplete format specifier}} expected-warning{{data argument not used by format string}}
725725
}
726726

727727
#if !defined(__ANDROID__) && !defined(__Fuchsia__)

clang/test/SemaObjC/format-strings-objc.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ void testUnicode(void) {
274274

275275
// Test Objective-C modifier flags.
276276
void testObjCModifierFlags(void) {
277-
NSLog(@"%[]@", @"Foo"); // expected-warning {{missing object format flag}}
278-
NSLog(@"%[", @"Foo"); // expected-warning {{incomplete format specifier}}
279-
NSLog(@"%[tt", @"Foo"); // expected-warning {{incomplete format specifier}}
277+
NSLog(@"%[]@", @"Foo"); // expected-warning {{missing object format flag}} expected-warning{{data argument not used by format string}}
278+
NSLog(@"%[", @"Foo"); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
279+
NSLog(@"%[tt", @"Foo"); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
280280
NSLog(@"%[tt]@", @"Foo"); // no-warning
281281
NSLog(@"%[tt]@ %s", @"Foo", "hello"); // no-warning
282282
NSLog(@"%s %[tt]@", "hello", @"Foo"); // no-warning
283-
NSLog(@"%[blark]@", @"Foo"); // expected-warning {{'blark' is not a valid object format flag}}
283+
NSLog(@"%[blark]@", @"Foo"); // expected-warning {{'blark' is not a valid object format flag}} expected-warning{{data argument not used by format string}}
284284
NSLog(@"%2$[tt]@ %1$[tt]@", @"Foo", @"Bar"); // no-warning
285-
NSLog(@"%2$[tt]@ %1$[tt]s", @"Foo", @"Bar"); // expected-warning {{object format flags cannot be used with 's' conversion specifier}}
285+
NSLog(@"%2$[tt]@ %1$[tt]s", @"Foo", @"Bar"); // expected-warning {{object format flags cannot be used with 's' conversion specifier}} expected-warning{{data argument not used by format string}}
286286
}
287287

288288
@interface RD23622446_Tester: NSObject

clang/test/SemaOpenCL/printf-format-strings.cl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,18 @@ kernel void format_v4f32(float4 arg)
9696

9797
kernel void format_only_v(int arg)
9898
{
99-
printf("%v", arg); // expected-warning {{incomplete format specifier}}
99+
printf("%v", arg); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
100100
}
101101

102102
kernel void format_missing_num(int arg)
103103
{
104-
printf("%v4", arg); // expected-warning {{incomplete format specifier}}
104+
printf("%v4", arg); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
105105
}
106106

107107
kernel void format_not_num(int arg)
108108
{
109-
printf("%vNd", arg); // expected-warning {{incomplete format specifier}}
110-
printf("%v*d", arg); // expected-warning {{incomplete format specifier}}
109+
printf("%vNd", arg); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
110+
printf("%v*d", arg); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
111111
}
112112

113113
kernel void format_v16i32(int16 arg)
@@ -127,7 +127,7 @@ kernel void format_v4i32_wrong_num_elts_2_to_4(int2 arg)
127127

128128
kernel void format_missing_num_elts_format(int4 arg)
129129
{
130-
printf("%vd\n", arg); // expected-warning {{incomplete format specifier}}
130+
printf("%vd\n", arg); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
131131
}
132132

133133
kernel void format_v4f32_scalar(float arg)
@@ -142,7 +142,7 @@ kernel void format_v4f32_wrong_num_elts(float2 arg)
142142

143143
kernel void format_missing_num_elts(float4 arg)
144144
{
145-
printf("%vf\n", arg); // expected-warning {{incomplete format specifier}}
145+
printf("%vf\n", arg); // expected-warning {{incomplete format specifier}} expected-warning{{data argument not used by format string}}
146146
}
147147

148148
kernel void vector_precision_modifier_v4i32_to_v4f32(int4 arg)

0 commit comments

Comments
 (0)