diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Sema/format-strings-gnu.c | 55 | ||||
-rw-r--r-- | test/Sema/format-strings-non-iso.c | 2 | ||||
-rw-r--r-- | test/Sema/format-strings-scanf.c | 12 | ||||
-rw-r--r-- | test/Sema/format-strings.c | 11 |
4 files changed, 57 insertions, 23 deletions
diff --git a/test/Sema/format-strings-gnu.c b/test/Sema/format-strings-gnu.c new file mode 100644 index 0000000000..f4910856b0 --- /dev/null +++ b/test/Sema/format-strings-gnu.c @@ -0,0 +1,55 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 %s + +// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -DALLOWED %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -DALLOWED %s + +int printf(const char *restrict, ...); +int scanf(const char * restrict, ...) ; + +void test() { + long notLongEnough = 1; + long long quiteLong = 2; + + printf("%Ld", notLongEnough); // expected-warning {{format specifies type 'long long' but the argument has type 'long'}} + printf("%Ld", quiteLong); + +#ifndef ALLOWED + // expected-warning@-4 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}} + // expected-note@-5 {{did you mean to use 'll'?}} + + // expected-warning@-6 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}} + // expected-note@-7 {{did you mean to use 'll'?}} +#endif +} + +void testAlwaysInvalid() { + // We should not suggest 'll' here! + printf("%Lc", 'a'); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 'c' conversion specifier}} + printf("%Ls", "a"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} +} + +#ifdef ALLOWED +// PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx +void printf_longlong(long long x, unsigned long long y) { + printf("%Ld", y); // no-warning + printf("%Lu", y); // no-warning + printf("%Lx", y); // no-warning + printf("%Ld", x); // no-warning + printf("%Lu", x); // no-warning + printf("%Lx", x); // no-warning + printf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} +} + +void scanf_longlong(long long *x, unsigned long long *y) { + scanf("%Ld", y); // no-warning + scanf("%Lu", y); // no-warning + scanf("%Lx", y); // no-warning + scanf("%Ld", x); // no-warning + scanf("%Lu", x); // no-warning + scanf("%Lx", x); // no-warning + scanf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} +} +#endif diff --git a/test/Sema/format-strings-non-iso.c b/test/Sema/format-strings-non-iso.c index ed8095f10a..e5ff8798f6 100644 --- a/test/Sema/format-strings-non-iso.c +++ b/test/Sema/format-strings-non-iso.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -pedantic %s +// RUN: %clang_cc1 -triple i686-linux-gnu -fsyntax-only -verify -std=c99 -pedantic %s int printf(const char *restrict, ...); int scanf(const char * restrict, ...); diff --git a/test/Sema/format-strings-scanf.c b/test/Sema/format-strings-scanf.c index 235ac11faa..be2adddc52 100644 --- a/test/Sema/format-strings-scanf.c +++ b/test/Sema/format-strings-scanf.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -Wformat-nonliteral %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s // Test that -Wformat=0 works: // RUN: %clang_cc1 -fsyntax-only -Werror -Wformat=0 %s @@ -113,16 +113,6 @@ void test_alloc_extension(char **sp, wchar_t **lsp, float *fp) { scanf("%m[abc]", fp); // expected-warning{{format specifies type 'char **' but the argument has type 'float *'}} } -void test_longlong(long long *x, unsigned long long *y) { - scanf("%Ld", y); // no-warning - scanf("%Lu", y); // no-warning - scanf("%Lx", y); // no-warning - scanf("%Ld", x); // no-warning - scanf("%Lu", x); // no-warning - scanf("%Lx", x); // no-warning - scanf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} -} - void test_quad(int *x, long long *llx) { scanf("%qd", x); // expected-warning{{format specifies type 'long long *' but the argument has type 'int *'}} scanf("%qd", llx); // no-warning diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 86b9296108..2e980a59a2 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -531,17 +531,6 @@ void pr9751() { 0.0); // expected-warning{{format specifies}} } -// PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx -void printf_longlong(long long x, unsigned long long y) { - printf("%Ld", y); // no-warning - printf("%Lu", y); // no-warning - printf("%Lx", y); // no-warning - printf("%Ld", x); // no-warning - printf("%Lu", x); // no-warning - printf("%Lx", x); // no-warning - printf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} -} - void __attribute__((format(strfmon,1,2))) monformat(const char *fmt, ...); void __attribute__((format(strftime,1,0))) dateformat(const char *fmt); |