Debian Codegraph @

clang/test/Sema/format-attr-missing.m

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-format-attribute %s
2 // RUN: %clang_cc1 -fsyntax-only -Wmissing-format-attribute -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
3
4 #include <stdarg.h>
5
6 @interface PrintCallee
7 -(void)printf:(const char *)fmt, ... __attribute__((format(printf, 1, 2)));
8 -(void)vprintf:(const char *)fmt list:(va_list)ap __attribute__((format(printf, 1, 0)));
9 @end
10
11 // CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:1-[[@LINE+1]]:1}:"__attribute__((format(printf, 2, 3))) "
12 void f1(PrintCallee *p, const char *fmt, int x) // #f1
13 {
14 [p printf:fmt, x]; // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 2, 3)' attribute to the declaration of 'f1'}}
15 // expected-note@#f1 {{'f1' declared here}}
16 }
17
18 // CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:1-[[@LINE+1]]:1}:"__attribute__((format(printf, 2, 3))) "
19 void f2(PrintCallee *p, const char *fmt, ...) // #f2
20 {
21 va_list ap;
22 [p vprintf:fmt list:ap]; // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 2, 3)' attribute to the declaration of 'f2'}}
23 // expected-note@#f2 {{'f2' declared here}}
24 }
25
26 // CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:1-[[@LINE+1]]:1}:"__attribute__((format(printf, 2, 0))) "
27 void f3(PrintCallee *p, const char *fmt, va_list ap) // #f3
28 {
29 [p vprintf:fmt list:ap]; // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 2, 0)' attribute to the declaration of 'f3'}}
30 // expected-note@#f3 {{'f3' declared here}}
31 }
32
33 __attribute__((format(printf, 1, 2)))
34 int printf(const char *, ...);
35 __attribute__((format(printf, 1, 0)))
36 int vprintf(const char *, va_list ap);
37
38 __attribute__((objc_root_class))
39 @interface PrintCaller
40 // CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:33-[[@LINE+1]]:33}:" __attribute__((format(printf, 1, 2)))"
41 -(void)f4:(const char *)fmt, ...; // #f4
42
43 // CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:45-[[@LINE+1]]:45}:" __attribute__((format(printf, 1, 0)))"
44 -(void)f5:(const char *)fmt list:(va_list)ap; // #f5
45
46 // CHECK: fix-it:"{{.*}}":{[[@LINE+1]]:37-[[@LINE+1]]:37}:" __attribute__((format(printf, 1, 2)))"
47 -(void)f6:(const char *)fmt x:(int)x; // #f6
48 @end
49
50 @implementation PrintCaller
51 -(void)f4:(const char *)fmt, ... {
52 va_list ap;
53 va_start(ap, fmt);
54 vprintf(fmt, ap); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 1, 2)' attribute to the declaration of 'f4:'}}
55 // expected-note@#f4 {{'f4:' declared here}}
56 va_end(ap);
57 }
58
59 -(void)f5:(const char *)fmt list:(va_list)ap {
60 vprintf(fmt, ap); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 1, 0)' attribute to the declaration of 'f5:list:'}}
61 // expected-note@#f5 {{'f5:list:' declared here}}
62 }
63
64 -(void)f6:(const char *)fmt x:(int)x {
65 printf(fmt, x); // expected-warning {{diagnostic behavior may be improved by adding the 'format(printf, 1, 2)' attribute to the declaration of 'f6:x:'}}
66 // expected-note@#f6 {{'f6:x:' declared here}}
67 }
68 @end