summaryrefslogtreecommitdiff
path: root/test/Sema
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2010-04-02 08:55:10 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2010-04-02 08:55:10 +0000
commit11d2b2d2bb706fca0656f2760839721bb7f6cb6f (patch)
treed374cdca417e76f1bf101f139dba2db1d10ee8f7 /test/Sema
parentc0c7bca4e5b8d12699dc93a0da49e9e4bb79671b (diff)
Notes
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/attr-format.c (renamed from test/Sema/format-attribute.c)46
-rw-r--r--test/Sema/attr-sentinel.c (renamed from test/Sema/function-sentinel-attr.c)24
-rw-r--r--test/Sema/attr-unused.c17
-rw-r--r--test/Sema/format-attr-pr4470.c12
-rw-r--r--test/Sema/format-attribute-printf0.c26
-rw-r--r--test/Sema/format-strings.c13
-rw-r--r--test/Sema/function-pointer-sentinel-attribute.c20
-rw-r--r--test/Sema/init.c3
-rw-r--r--test/Sema/nested-redef.c3
-rw-r--r--test/Sema/return.c17
-rw-r--r--test/Sema/struct-packed-align.c8
-rw-r--r--test/Sema/warn-gnu-designators.c2
-rw-r--r--test/Sema/warn-shadow.c5
-rw-r--r--test/Sema/x86-intrinsics-headers.c32
14 files changed, 131 insertions, 97 deletions
diff --git a/test/Sema/format-attribute.c b/test/Sema/attr-format.c
index 6e1bd0f1ab655..0fadf98f978f2 100644
--- a/test/Sema/format-attribute.c
+++ b/test/Sema/attr-format.c
@@ -32,3 +32,49 @@ int rdar6623513(void *, const char*, const char*, ...)
int rdar6623513_aux(int len, const char* s) {
rdar6623513(0, "hello", "%.*s", len, s);
}
+
+
+
+// same as format(printf(...))...
+void a2(const char *a, ...) __attribute__((format(printf0, 1,2))); // no-error
+void b2(const char *a, ...) __attribute__((format(printf0, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}
+void c2(const char *a, ...) __attribute__((format(printf0, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}}
+void d2(const char *a, int c) __attribute__((format(printf0, 1,2))); // expected-error {{format attribute requires variadic function}}
+void e2(char *str, int c, ...) __attribute__((format(printf0, 2,3))); // expected-error {{format argument not a string type}}
+
+// FreeBSD usage
+#define __printf0like(fmt,va) __attribute__((__format__(__printf0__,fmt,va)))
+void null(int i, const char *a, ...) __printf0like(2,0); // no-error
+void null(int i, const char *a, ...) {
+ if (a)
+ (void)0/* vprintf(...) would go here */;
+}
+
+void callnull(void){
+ null(0, 0); // no error
+ null(0, (char*)0); // no error
+ null(0, (void*)0); // no error
+ null(0, (int*)0); // expected-warning {{incompatible pointer types}}
+}
+
+
+
+// PR4470
+int xx_vprintf(const char *, va_list);
+
+const char *foo(const char *format) __attribute__((format_arg(1)));
+
+void __attribute__((format(printf, 1, 0)))
+foo2(const char *fmt, va_list va) {
+ xx_vprintf(foo(fmt), va);
+}
+
+// PR6542
+extern void gcc_format (const char *, ...)
+ __attribute__ ((__format__(__gcc_diag__, 1, 2)));
+extern void gcc_cformat (const char *, ...)
+ __attribute__ ((__format__(__gcc_cdiag__, 1, 2)));
+extern void gcc_cxxformat (const char *, ...)
+ __attribute__ ((__format__(__gcc_cxxdiag__, 1, 2)));
+extern void gcc_tformat (const char *, ...)
+ __attribute__ ((__format__(__gcc_tdiag__, 1, 2)));
diff --git a/test/Sema/function-sentinel-attr.c b/test/Sema/attr-sentinel.c
index 9bcbec4c0c368..db90d078b3f75 100644
--- a/test/Sema/function-sentinel-attr.c
+++ b/test/Sema/attr-sentinel.c
@@ -11,9 +11,7 @@ void foo7 (int x, ...) __attribute__ ((__sentinel__(0))); // expected-note {{fun
void foo10 (int x, ...) __attribute__ ((__sentinel__(1,1)));
void foo12 (int x, ... ) ATTR; // expected-note {{function has been explicitly marked sentinel here}}
-int main ()
-{
-
+void test1() {
foo1(1, NULL); // OK
foo1(1, 0) ; // expected-warning {{missing sentinel in function call}}
foo5(1, NULL, 2); // OK
@@ -28,3 +26,23 @@ int main ()
foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}}
}
+
+
+void (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
+
+void test2() {
+ void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}}
+ void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}
+
+
+ void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}
+
+ b(1, "%s", (void*)0); // OK
+ b(1, "%s", 0); // expected-warning {{missing sentinel in function call}}
+ z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}}
+ z(1, "%s", (void*)0, 1, 0); // OK
+
+ y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
+
+ y(1, "%s", (void*)0,3,4,5,6,7); // OK
+}
diff --git a/test/Sema/attr-unused.c b/test/Sema/attr-unused.c
index e45ec434f5338..28715141b995f 100644
--- a/test/Sema/attr-unused.c
+++ b/test/Sema/attr-unused.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fsyntax-only %s
+// RUN: %clang_cc1 -verify -Wunused-variable -fsyntax-only %s
static void (*fp0)(void) __attribute__((unused));
@@ -10,3 +10,18 @@ int f1() __attribute__((unused));
int g0 __attribute__((unused));
int f2() __attribute__((unused(1, 2))); // expected-error {{attribute requires 0 argument(s)}}
+
+struct Test0_unused {} __attribute__((unused));
+struct Test0_not_unused {};
+typedef int Int_unused __attribute__((unused));
+typedef int Int_not_unused;
+
+void test0() {
+ int x; // expected-warning {{unused variable}}
+
+ Int_not_unused i0; // expected-warning {{unused variable}}
+ Int_unused i1;
+
+ struct Test0_not_unused s0; // expected-warning {{unused variable}}
+ struct Test0_unused s1;
+}
diff --git a/test/Sema/format-attr-pr4470.c b/test/Sema/format-attr-pr4470.c
deleted file mode 100644
index 374d8b3af03f6..0000000000000
--- a/test/Sema/format-attr-pr4470.c
+++ /dev/null
@@ -1,12 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat=2 %s
-
-#include <stdarg.h>
-int vprintf(const char *, va_list);
-
-const char *foo(const char *format) __attribute__((format_arg(1)));
-
-void __attribute__((format(printf, 1, 0)))
-foo2(const char *fmt, va_list va)
-{
- vprintf(foo(fmt), va);
-}
diff --git a/test/Sema/format-attribute-printf0.c b/test/Sema/format-attribute-printf0.c
deleted file mode 100644
index 33e8d40076dc0..0000000000000
--- a/test/Sema/format-attribute-printf0.c
+++ /dev/null
@@ -1,26 +0,0 @@
-//RUN: %clang_cc1 -fsyntax-only -verify %s
-
-#include <stdarg.h>
-
-// same as format(printf(...))...
-void a2(const char *a, ...) __attribute__((format(printf0, 1,2))); // no-error
-void b2(const char *a, ...) __attribute__((format(printf0, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}
-void c2(const char *a, ...) __attribute__((format(printf0, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}}
-void d2(const char *a, int c) __attribute__((format(printf0, 1,2))); // expected-error {{format attribute requires variadic function}}
-void e2(char *str, int c, ...) __attribute__((format(printf0, 2,3))); // expected-error {{format argument not a string type}}
-
-// FreeBSD usage
-#define __printf0like(fmt,va) __attribute__((__format__(__printf0__,fmt,va)))
-void null(int i, const char *a, ...) __printf0like(2,0); // no-error
-void null(int i, const char *a, ...) {
- if (a)
- (void)0/* vprintf(...) would go here */;
-}
-
-void callnull(void){
- null(0, 0); // no error
- null(0, (char*)0); // no error
- null(0, (void*)0); // no error
- null(0, (int*)0); // expected-warning {{incompatible pointer types}}
-}
-
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index 4db775f96c946..dcc4c35d01eca 100644
--- a/test/Sema/format-strings.c
+++ b/test/Sema/format-strings.c
@@ -238,3 +238,16 @@ void test_positional_arguments() {
printf("%2$*8$d", (int) 2, (int) 3); // expected-warning{{specified field width is missing a matching 'int' argument}}
}
+// PR 6697 - Handle format strings where the data argument is not adjacent to the format string
+void myprintf_PR_6697(const char *format, int x, ...) __attribute__((__format__(printf,1, 3)));
+void test_pr_6697() {
+ myprintf_PR_6697("%s\n", 1, "foo"); // no-warning
+ myprintf_PR_6697("%s\n", 1, (int)0); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}}
+ // FIXME: Not everything should clearly support positional arguments,
+ // but we need a way to identify those cases.
+ myprintf_PR_6697("%1$s\n", 1, "foo"); // no-warning
+ myprintf_PR_6697("%2$s\n", 1, "foo"); // expected-warning{{data argument position '2' exceeds the number of data arguments (1)}}
+ myprintf_PR_6697("%18$s\n", 1, "foo"); // expected-warning{{data argument position '18' exceeds the number of data arguments (1)}}
+ myprintf_PR_6697("%1$s\n", 1, (int) 0); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}}
+}
+
diff --git a/test/Sema/function-pointer-sentinel-attribute.c b/test/Sema/function-pointer-sentinel-attribute.c
deleted file mode 100644
index 5f17a260b26f3..0000000000000
--- a/test/Sema/function-pointer-sentinel-attribute.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-void (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
-
-int main() {
- void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}}
- void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}
-
-
- void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}
-
- b(1, "%s", (void*)0); // OK
- b(1, "%s", 0); // expected-warning {{missing sentinel in function call}}
- z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}}
- z(1, "%s", (void*)0, 1, 0); // OK
-
- y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
-
- y(1, "%s", (void*)0,3,4,5,6,7); // OK
-}
diff --git a/test/Sema/init.c b/test/Sema/init.c
index c2712480c6164..b9867cf5027b5 100644
--- a/test/Sema/init.c
+++ b/test/Sema/init.c
@@ -75,7 +75,8 @@ int sym_fw1a_scr[] = {
};
// PR3001
-struct s1 s2 = {
+struct s1 s2 = { // expected-error {{variable has incomplete type 'struct s1'}} \
+ // expected-note {{forward declaration of 'struct s1'}}
.a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \
// expected-note{{forward declaration of 'struct s3'}}
.b = bogus // expected-error {{use of undeclared identifier 'bogus'}}
diff --git a/test/Sema/nested-redef.c b/test/Sema/nested-redef.c
index 6a19921f47fa5..bbc4859367704 100644
--- a/test/Sema/nested-redef.c
+++ b/test/Sema/nested-redef.c
@@ -1,7 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct X { // expected-note{{previous definition is here}}
- struct X { } x; // expected-error{{nested redefinition of 'X'}} \
- // expected-error{{field has incomplete type}}
+ struct X { } x; // expected-error{{nested redefinition of 'X'}}
};
struct Y { };
diff --git a/test/Sema/return.c b/test/Sema/return.c
index 3ab23f4f8f8e2..fab6a82aa7042 100644
--- a/test/Sema/return.c
+++ b/test/Sema/return.c
@@ -222,3 +222,20 @@ void test32() {
void test33() {
if (j) while (1) { }
}
+
+// Test that 'static inline' functions are only analyzed for CFG-based warnings
+// when they are used.
+static inline int si_has_missing_return() {} // no-warning
+static inline int si_has_missing_return_2() {}; // expected-warning{{control reaches end of non-void function}}
+static inline int si_forward();
+static inline int si_has_missing_return_3(int x) {
+ if (x)
+ return si_has_missing_return_3(x+1);
+} // expected-warning{{control may reach end of non-void function}}
+
+int test_static_inline(int x) {
+ si_forward();
+ return x ? si_has_missing_return_2() : si_has_missing_return_3(x);
+}
+static inline int si_forward() {} // expected-warning{{control reaches end of non-void function}}
+
diff --git a/test/Sema/struct-packed-align.c b/test/Sema/struct-packed-align.c
index 60a9febafbad1..2b9456703c727 100644
--- a/test/Sema/struct-packed-align.c
+++ b/test/Sema/struct-packed-align.c
@@ -37,6 +37,14 @@ struct __attribute__((packed)) packed_fas {
extern int d1[sizeof(struct packed_fas) == 1 ? 1 : -1];
extern int d2[__alignof(struct packed_fas) == 1 ? 1 : -1];
+struct packed_after_fas {
+ char a;
+ int b[];
+} __attribute__((packed));
+
+extern int d1_2[sizeof(struct packed_after_fas) == 1 ? 1 : -1];
+extern int d2_2[__alignof(struct packed_after_fas) == 1 ? 1 : -1];
+
// Alignment
struct __attribute__((aligned(8))) as1 {
diff --git a/test/Sema/warn-gnu-designators.c b/test/Sema/warn-gnu-designators.c
new file mode 100644
index 0000000000000..d5ac8cfe55394
--- /dev/null
+++ b/test/Sema/warn-gnu-designators.c
@@ -0,0 +1,2 @@
+// RUN: %clang_cc1 -Wno-gnu-designator -verify %s
+struct { int x, y, z[12] } value = { x:17, .z [3 ... 5] = 7 };
diff --git a/test/Sema/warn-shadow.c b/test/Sema/warn-shadow.c
index c9a783b437a01..a112210c96935 100644
--- a/test/Sema/warn-shadow.c
+++ b/test/Sema/warn-shadow.c
@@ -43,3 +43,8 @@ void test3(void) {
void test4(int i) { // expected-warning {{declaration shadows a variable in the global scope}}
}
+
+// Don't warn about shadowing for function declarations.
+void test5(int i);
+void test6(void (*f)(int i)) {}
+void test7(void *context, void (*callback)(void *context)) {}
diff --git a/test/Sema/x86-intrinsics-headers.c b/test/Sema/x86-intrinsics-headers.c
deleted file mode 100644
index 24c2d925e00de..0000000000000
--- a/test/Sema/x86-intrinsics-headers.c
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: %clang -fsyntax-only %s
-// RUN: %clang -fsyntax-only -fno-lax-vector-conversions %s
-// RUN: %clang -fsyntax-only -x c++ %s
-
-#if defined(i386) || defined(__x86_64__)
-
-# if defined(__MMX__)
-#include <emmintrin.h>
-#include <mm_malloc.h>
-# endif
-
-# if defined(__SSE__)
-#include <xmmintrin.h>
-# endif
-
-# if defined(__SSE3__)
-#include <pmmintrin.h>
-# endif
-
-# if defined(__SSSE3__)
-#include <tmmintrin.h>
-# endif
-
-# if defined(__SSE4_1__)
-#include <smmintrin.h>
-# endif
-
-# if defined(__SSE4_2__)
-#include <nmmintrin.h>
-# endif
-
-#endif