annotate clang/test/Sema/format-strings-gnu.c @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 -DMS %s
anatofuz
parents:
diff changeset
4 // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 -DMS %s
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -DALLOWED %s
anatofuz
parents:
diff changeset
7 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -DALLOWED %s
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 int printf(const char *restrict, ...);
anatofuz
parents:
diff changeset
10 int scanf(const char * restrict, ...) ;
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 void test() {
anatofuz
parents:
diff changeset
13 long notLongEnough = 1;
anatofuz
parents:
diff changeset
14 long long quiteLong = 2;
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 printf("%Ld", notLongEnough); // expected-warning {{format specifies type 'long long' but the argument has type 'long'}}
anatofuz
parents:
diff changeset
17 printf("%Ld", quiteLong);
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 #ifndef ALLOWED
anatofuz
parents:
diff changeset
20 // expected-warning@-4 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}}
anatofuz
parents:
diff changeset
21 // expected-note@-5 {{did you mean to use 'll'?}}
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 // expected-warning@-6 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}}
anatofuz
parents:
diff changeset
24 // expected-note@-7 {{did you mean to use 'll'?}}
anatofuz
parents:
diff changeset
25 #endif
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 #ifndef MS
anatofuz
parents:
diff changeset
28 printf("%Z\n", quiteLong); // expected-warning{{invalid conversion specifier 'Z'}}
anatofuz
parents:
diff changeset
29 #endif
anatofuz
parents:
diff changeset
30 }
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 void testAlwaysInvalid() {
anatofuz
parents:
diff changeset
33 // We should not suggest 'll' here!
anatofuz
parents:
diff changeset
34 printf("%Lc", 'a'); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 'c' conversion specifier}}
anatofuz
parents:
diff changeset
35 printf("%Ls", "a"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 #ifdef ALLOWED
anatofuz
parents:
diff changeset
39 // PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx
anatofuz
parents:
diff changeset
40 void printf_longlong(long long x, unsigned long long y) {
anatofuz
parents:
diff changeset
41 printf("%Ld", y); // no-warning
anatofuz
parents:
diff changeset
42 printf("%Lu", y); // no-warning
anatofuz
parents:
diff changeset
43 printf("%Lx", y); // no-warning
anatofuz
parents:
diff changeset
44 printf("%Ld", x); // no-warning
anatofuz
parents:
diff changeset
45 printf("%Lu", x); // no-warning
anatofuz
parents:
diff changeset
46 printf("%Lx", x); // no-warning
anatofuz
parents:
diff changeset
47 printf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}
anatofuz
parents:
diff changeset
48 }
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 void scanf_longlong(long long *x, unsigned long long *y) {
anatofuz
parents:
diff changeset
51 scanf("%Ld", y); // no-warning
anatofuz
parents:
diff changeset
52 scanf("%Lu", y); // no-warning
anatofuz
parents:
diff changeset
53 scanf("%Lx", y); // no-warning
anatofuz
parents:
diff changeset
54 scanf("%Ld", x); // no-warning
anatofuz
parents:
diff changeset
55 scanf("%Lu", x); // no-warning
anatofuz
parents:
diff changeset
56 scanf("%Lx", x); // no-warning
anatofuz
parents:
diff changeset
57 scanf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59 #endif