]> granicus.if.org Git - clang/commitdiff
Make fscanf, vscanf, etc. be recognized as scanf-like functions.
authorHans Wennborg <hans@hanshq.net>
Mon, 12 Dec 2011 10:34:18 +0000 (10:34 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 12 Dec 2011 10:34:18 +0000 (10:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146367 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Builtins.def
test/Sema/format-strings-scanf.c

index ef253e818fd69e87f4aeeaeb3cfb86c348913b21..e7c300d7c8fec838a0ead3902d4c41e9a3ad02c5 100644 (file)
@@ -656,7 +656,12 @@ LIBBUILTIN(vprintf, "icC*a",      "fP:0:", "stdio.h", ALL_LANGUAGES)
 LIBBUILTIN(vfprintf, "i.",        "fP:1:", "stdio.h", ALL_LANGUAGES)
 LIBBUILTIN(vsnprintf, "ic*zcC*a", "fP:2:", "stdio.h", ALL_LANGUAGES)
 LIBBUILTIN(vsprintf, "ic*cC*a",   "fP:1:", "stdio.h", ALL_LANGUAGES)
-LIBBUILTIN(scanf, "icC*.",       "fs:0:", "stdio.h", ALL_LANGUAGES)
+LIBBUILTIN(scanf, "icC*.",        "fs:0:", "stdio.h", ALL_LANGUAGES)
+LIBBUILTIN(fscanf, "iP*cC*.",     "fs:1:", "stdio.h", ALL_LANGUAGES)
+LIBBUILTIN(sscanf, "ic*cC*.",     "fs:1:", "stdio.h", ALL_LANGUAGES)
+LIBBUILTIN(vscanf, "icC*a",       "fS:0:", "stdio.h", ALL_LANGUAGES)
+LIBBUILTIN(vfscanf, "iP*cC*a",    "fS:1:", "stdio.h", ALL_LANGUAGES)
+LIBBUILTIN(vsscanf, "ic*cC*a",    "fS:1:", "stdio.h", ALL_LANGUAGES)
 // C99
 LIBBUILTIN(longjmp, "vJi",        "fr",    "setjmp.h", ALL_LANGUAGES)
 
index 467586215b2f68aa93a24c1b26fccce5b3e162b2..c0f6b0becb256cf019063b096e851b3265c222e8 100644 (file)
@@ -1,12 +1,18 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
 
+#include <stdarg.h>
 typedef __typeof(sizeof(int)) size_t;
 typedef struct _FILE FILE;
 typedef __WCHAR_TYPE__ wchar_t;
 
 int fscanf(FILE * restrict, const char * restrict, ...) ;
 int scanf(const char * restrict, ...) ;
-int sscanf(const char * restrict, const char * restrict, ...) ;
+int sscanf(char * restrict, const char * restrict, ...) ;
+int my_scanf(const char * restrict, ...) __attribute__((__format__(__scanf__, 1, 2)));
+
+int vscanf(const char * restrict, va_list);
+int vfscanf(FILE * restrict, const char * restrict, va_list);
+int vsscanf(char * restrict, const char * restrict, va_list);
 
 void test(const char *s, int *i) {
   scanf(s, i); // expected-warning{{ormat string is not a string literal}}
@@ -45,3 +51,19 @@ void pr9751() {
   scanf(kFormat2, str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
   scanf("%[", str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
 }
+
+void test_variants(int *i, const char *s, ...) {
+  FILE *f = 0;
+  char buf[100];
+
+  fscanf(f, "%ld", i); // expected-warning{{conversion specifies type 'long *' but the argument has type 'int *'}}
+  sscanf(buf, "%ld", i); // expected-warning{{conversion specifies type 'long *' but the argument has type 'int *'}}
+  my_scanf("%ld", i); // expected-warning{{conversion specifies type 'long *' but the argument has type 'int *'}}
+
+  va_list ap;
+  va_start(ap, s);
+
+  vscanf("%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+  vfscanf(f, "%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+  vsscanf(buf, "%[abc", ap); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+}