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