diff options
author | Hans Wennborg <hans@hanshq.net> | 2012-01-12 17:11:12 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2012-01-12 17:11:12 +0000 |
commit | 6073e31baa3af760adbf4ec1688d6fb51bf89e0c (patch) | |
tree | 0b721c8977980f19f6d73c4d14fef4c2f5e40115 /clang/test/Sema/format-strings-scanf.c | |
parent | bf3a826f2cf7975cf6d92de325e00e50ede04cba (diff) | |
download | bcm5719-llvm-6073e31baa3af760adbf4ec1688d6fb51bf89e0c.tar.gz bcm5719-llvm-6073e31baa3af760adbf4ec1688d6fb51bf89e0c.zip |
scanf: parse the 'm' length modifier, and check that the right arguments
are used with that and the 'a' length modifier.
llvm-svn: 148029
Diffstat (limited to 'clang/test/Sema/format-strings-scanf.c')
-rw-r--r-- | clang/test/Sema/format-strings-scanf.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/clang/test/Sema/format-strings-scanf.c b/clang/test/Sema/format-strings-scanf.c index 7a2f278aebd..4d9843cd790 100644 --- a/clang/test/Sema/format-strings-scanf.c +++ b/clang/test/Sema/format-strings-scanf.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -Wformat-nonliteral %s #include <stdarg.h> typedef __typeof(sizeof(int)) size_t; @@ -73,11 +73,27 @@ void test_scanlist(int *ip, char *sp) { scanf("%h[abc]", sp); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with '[' conversion specifier}} } -void test_alloc_extension(char **sp, wchar_t **lsp) { +void test_alloc_extension(char **sp, wchar_t **lsp, float *fp) { /* Make sure "%a" gets parsed as a conversion specifier for float, * even when followed by an 's', 'S' or '[', which would cause it to be * parsed as a length modifier in C90. */ scanf("%as", sp); // expected-warning{{conversion specifies type 'float *' but the argument has type 'char **'}} scanf("%aS", lsp); // expected-warning{{conversion specifies type 'float *' but the argument has type 'wchar_t **'}} scanf("%a[bcd]", sp); // expected-warning{{conversion specifies type 'float *' but the argument has type 'char **'}} + + // Test that the 'm' length modifier is only allowed with s, S, c, C or [. + // TODO: Warn that 'm' is an extension. + scanf("%ms", sp); // No warning. + scanf("%mS", lsp); // No warning. + scanf("%mc", sp); // No warning. + scanf("%mC", lsp); // No warning. + scanf("%m[abc]", sp); // No warning. + scanf("%md", sp); // expected-warning{{length modifier 'm' results in undefined behavior or no effect with 'd' conversion specifier}} + + // Test argument type check for the 'm' length modifier. + scanf("%ms", fp); // expected-warning{{conversion specifies type 'char **' but the argument has type 'float *'}} + scanf("%mS", fp); // expected-warning{{conversion specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}} + scanf("%mc", fp); // expected-warning{{conversion specifies type 'char **' but the argument has type 'float *'}} + scanf("%mC", fp); // expected-warning{{conversion specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'}} + scanf("%m[abc]", fp); // expected-warning{{conversion specifies type 'char **' but the argument has type 'float *'}} } |