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