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