diff options
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/attr-sentinel.c | 8 | ||||
-rw-r--r-- | test/Sema/c89.c | 2 | ||||
-rw-r--r-- | test/Sema/compare.c | 20 | ||||
-rw-r--r-- | test/Sema/conditional-expr.c | 9 | ||||
-rw-r--r-- | test/Sema/conversion.c | 10 | ||||
-rw-r--r-- | test/Sema/format-strings.c | 3 | ||||
-rw-r--r-- | test/Sema/init.c | 14 | ||||
-rw-r--r-- | test/Sema/pragma-align-mac68k-unsupported.c | 4 | ||||
-rw-r--r-- | test/Sema/pragma-align-mac68k.c | 98 | ||||
-rw-r--r-- | test/Sema/pragma-pack-and-options-align.c | 34 | ||||
-rw-r--r-- | test/Sema/scope-check.c | 20 | ||||
-rw-r--r-- | test/Sema/switch.c | 30 | ||||
-rw-r--r-- | test/Sema/unused-expr.c | 8 |
13 files changed, 233 insertions, 27 deletions
diff --git a/test/Sema/attr-sentinel.c b/test/Sema/attr-sentinel.c index db90d07..5ca6a8d 100644 --- a/test/Sema/attr-sentinel.c +++ b/test/Sema/attr-sentinel.c @@ -4,7 +4,7 @@ #define ATTR __attribute__ ((__sentinel__)) -void foo1 (int x, ...) ATTR; // expected-note {{function has been explicitly marked sentinel here}} +void foo1 (int x, ...) ATTR; // expected-note 2 {{function has been explicitly marked sentinel here}} void foo5 (int x, ...) __attribute__ ((__sentinel__(1))); // expected-note {{function has been explicitly marked sentinel here}} void foo6 (int x, ...) __attribute__ ((__sentinel__(5))); // expected-note {{function has been explicitly marked sentinel here}} void foo7 (int x, ...) __attribute__ ((__sentinel__(0))); // expected-note {{function has been explicitly marked sentinel here}} @@ -24,6 +24,12 @@ void test1() { foo7(1, NULL); // OK foo12(1); // expected-warning {{not enough variable arguments in 'foo12' declaration to fit a sentinel}} + + // PR 5685 + struct A {}; + struct A a, b, c; + foo1(3, &a, &b, &c); // expected-warning {{missing sentinel in function call}} + foo1(3, &a, &b, &c, (struct A*) 0); } diff --git a/test/Sema/c89.c b/test/Sema/c89.c index 8a9e622..038f7e5 100644 --- a/test/Sema/c89.c +++ b/test/Sema/c89.c @@ -61,7 +61,7 @@ void foo(T); /* typedef for void is allowed */ void foo(void) {} /* PR2759 */ -void test10 (int x[*]); /* expected-warning {{use of C99-specific array features}} */ +void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature, accepted as an extension}} */ void test11 (int x[static 4]); /* expected-warning {{use of C99-specific array features}} */ void test12 (int x[const 4]) { /* expected-warning {{use of C99-specific array features}} */ diff --git a/test/Sema/compare.c b/test/Sema/compare.c index 631b694..f997dc1 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -23,8 +23,8 @@ int ints(long a, unsigned long b) { ((signed char) a == b) + // expected-warning {{comparison of integers of different signs}} ((long) a == (unsigned long) b) + // expected-warning {{comparison of integers of different signs}} ((int) a == (unsigned int) b) + // expected-warning {{comparison of integers of different signs}} - ((short) a == (unsigned short) b) + // expected-warning {{comparison of integers of different signs}} - ((signed char) a == (unsigned char) b) + // expected-warning {{comparison of integers of different signs}} + ((short) a == (unsigned short) b) + + ((signed char) a == (unsigned char) b) + (a < (unsigned long) b) + // expected-warning {{comparison of integers of different signs}} (a < (unsigned int) b) + (a < (unsigned short) b) + @@ -35,8 +35,8 @@ int ints(long a, unsigned long b) { ((signed char) a < b) + // expected-warning {{comparison of integers of different signs}} ((long) a < (unsigned long) b) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) b) + // expected-warning {{comparison of integers of different signs}} - ((short) a < (unsigned short) b) + // expected-warning {{comparison of integers of different signs}} - ((signed char) a < (unsigned char) b) + // expected-warning {{comparison of integers of different signs}} + ((short) a < (unsigned short) b) + + ((signed char) a < (unsigned char) b) + // (A,b) (A == (unsigned long) b) + @@ -87,8 +87,8 @@ int ints(long a, unsigned long b) { ((signed char) a < B) + ((long) a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) B) + // expected-warning {{comparison of integers of different signs}} - ((short) a < (unsigned short) B) + // expected-warning {{comparison of integers of different signs}} - ((signed char) a < (unsigned char) B) + // expected-warning {{comparison of integers of different signs}} + ((short) a < (unsigned short) B) + + ((signed char) a < (unsigned char) B) + // (C,b) (C == (unsigned long) b) + @@ -139,8 +139,8 @@ int ints(long a, unsigned long b) { ((signed char) a < C) + ((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}} - ((short) a < (unsigned short) C) + // expected-warning {{comparison of integers of different signs}} - ((signed char) a < (unsigned char) C) + // expected-warning {{comparison of integers of different signs}} + ((short) a < (unsigned short) C) + + ((signed char) a < (unsigned char) C) + // (0x80000,b) (0x80000 == (unsigned long) b) + @@ -191,8 +191,8 @@ int ints(long a, unsigned long b) { ((signed char) a < 0x80000) + ((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}} - ((short) a < (unsigned short) 0x80000) + // expected-warning {{comparison of integers of different signs}} - ((signed char) a < (unsigned char) 0x80000) + // expected-warning {{comparison of integers of different signs}} + ((short) a < (unsigned short) 0x80000) + + ((signed char) a < (unsigned char) 0x80000) + // We should be able to avoid warning about this. (b != (a < 4 ? 1 : 2)) + diff --git a/test/Sema/conditional-expr.c b/test/Sema/conditional-expr.c index 5e2c1a4..6e248bc 100644 --- a/test/Sema/conditional-expr.c +++ b/test/Sema/conditional-expr.c @@ -52,7 +52,9 @@ void foo() { enum Enum { EVal }; test0 = test0 ? EVal : test0; test0 = test0 ? EVal : (int) test0; // okay: EVal is an int - test0 = test0 ? (unsigned) EVal : (int) test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? // expected-warning {{operands of ? are integers of different signs}} + (unsigned) EVal + : (int) test0; } int Postgresql() { @@ -68,3 +70,8 @@ int f0(int a) { // GCC considers this a warning. return a ? f1() : nil; // expected-warning {{pointer/integer type mismatch in conditional expression ('int' and 'void *')}} expected-warning {{incompatible pointer to integer conversion returning 'void *' from a function with result type 'int'}} } + +int f2(int x) { + // We can suppress this because the immediate context wants an int. + return (x != 0) ? 0U : x; +} diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index addedd9..5b09ec6 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -287,3 +287,13 @@ void test_7676608(void) { char c = 5; f7676608(c *= q); } + +// <rdar://problem/7904686> +void test_7904686(void) { + const int i = -1; + unsigned u1 = i; // expected-warning {{implicit cast changes signedness}} + u1 = i; // expected-warning {{implicit cast changes signedness}} + + unsigned u2 = -1; // expected-warning {{implicit cast changes signedness}} + u2 = -1; // expected-warning {{implicit cast changes signedness}} +} diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index bdc2bb0..d6d3796 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -251,3 +251,6 @@ void test_pr_6697() { myprintf_PR_6697("%1$s\n", 1, (int) 0); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} } +void rdar8026030(FILE *fp) { + fprintf(fp, "\%"); // expected-warning{{incomplete format specifier}} +} diff --git a/test/Sema/init.c b/test/Sema/init.c index b9867cf..c2c29ad 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -131,3 +131,17 @@ const wchar_t widestr[] = L"asdf"; // PR5447 const double pr5447 = (0.05 < -1.0) ? -1.0 : 0.0499878; +// PR4386 + +// None of these are constant initializers, but we implement GCC's old +// behaviour of accepting bar and zed but not foo. GCC's behaviour was +// changed in 2007 (rev 122551), so we should be able to change too one +// day. +int PR4386_bar(); +int PR4386_foo() __attribute((weak)); +int PR4386_zed(); + +int PR4386_a = ((void *) PR4386_bar) != 0; +int PR4386_b = ((void *) PR4386_foo) != 0; // expected-error{{initializer element is not a compile-time constant}} +int PR4386_c = ((void *) PR4386_zed) != 0; +int PR4386_zed() __attribute((weak)); diff --git a/test/Sema/pragma-align-mac68k-unsupported.c b/test/Sema/pragma-align-mac68k-unsupported.c new file mode 100644 index 0000000..6588aa1 --- /dev/null +++ b/test/Sema/pragma-align-mac68k-unsupported.c @@ -0,0 +1,4 @@ +// RUN: %clang-cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s +// RUN: %clang-cc1 -triple i386-pc-linux-gnu -fsyntax-only -verify %s + +/* expected-error {{mac68k alignment pragma is not supported}} */ #pragma options align=mac68k diff --git a/test/Sema/pragma-align-mac68k.c b/test/Sema/pragma-align-mac68k.c new file mode 100644 index 0000000..d13a0be --- /dev/null +++ b/test/Sema/pragma-align-mac68k.c @@ -0,0 +1,98 @@ +// RUN: %clang-cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s + +#include <stddef.h> + +#pragma options align=mac68k + +typedef float __attribute__((vector_size (8))) v2f_t; +typedef float __attribute__((vector_size (16))) v4f_t; + +extern int a0_0[__alignof(v2f_t) == 8 ? 1 : -1]; +extern int a0_1[__alignof(v4f_t) == 16 ? 1 : -1]; + +struct s1 { + char f0; + int f1; +}; +extern int a1_0[offsetof(struct s1, f0) == 0 ? 1 : -1]; +extern int a1_1[offsetof(struct s1, f1) == 2 ? 1 : -1]; +extern int a1_2[sizeof(struct s1) == 6 ? 1 : -1]; +extern int a1_3[__alignof(struct s1) == 2 ? 1 : -1]; + +struct s2 { + char f0; + double f1; +}; +extern int a2_0[offsetof(struct s2, f0) == 0 ? 1 : -1]; +extern int a2_1[offsetof(struct s2, f1) == 2 ? 1 : -1]; +extern int a2_2[sizeof(struct s2) == 10 ? 1 : -1]; +extern int a2_3[__alignof(struct s2) == 2 ? 1 : -1]; + +struct s3 { + char f0; + v4f_t f1; +}; +extern int a3_0[offsetof(struct s3, f0) == 0 ? 1 : -1]; +extern int a3_1[offsetof(struct s3, f1) == 2 ? 1 : -1]; +extern int a3_2[sizeof(struct s3) == 18 ? 1 : -1]; +extern int a3_3[__alignof(struct s3) == 2 ? 1 : -1]; + +struct s4 { + char f0; + char f1; +}; +extern int a4_0[offsetof(struct s4, f0) == 0 ? 1 : -1]; +extern int a4_1[offsetof(struct s4, f1) == 1 ? 1 : -1]; +extern int a4_2[sizeof(struct s4) == 2 ? 1 : -1]; +extern int a4_3[__alignof(struct s4) == 2 ? 1 : -1]; + +struct s5 { + unsigned f0 : 9; + unsigned f1 : 9; +}; +extern int a5_0[sizeof(struct s5) == 4 ? 1 : -1]; +extern int a5_1[__alignof(struct s5) == 2 ? 1 : -1]; + +struct s6 { + unsigned : 0; + unsigned : 0; +}; +extern int a6_0[sizeof(struct s6) == 0 ? 1 : -1]; +extern int a6_1[__alignof(struct s6) == 2 ? 1 : -1]; + +struct s7 { + char : 1; + unsigned : 1; +}; +extern int a7_0[sizeof(struct s7) == 2 ? 1 : -1]; +extern int a7_1[__alignof(struct s7) == 2 ? 1 : -1]; + +struct s8 { + char f0; + unsigned : 1; +}; +extern int a8_0[sizeof(struct s8) == 2 ? 1 : -1]; +extern int a8_1[__alignof(struct s8) == 2 ? 1 : -1]; + +struct s9 { + char f0[3]; + unsigned : 0; + char f1; +}; +extern int a9_0[sizeof(struct s9) == 6 ? 1 : -1]; +extern int a9_1[__alignof(struct s9) == 2 ? 1 : -1]; + +struct s10 { + char f0; +}; +extern int a10_0[sizeof(struct s10) == 2 ? 1 : -1]; +extern int a10_1[__alignof(struct s10) == 2 ? 1 : -1]; + +struct s11 { + char f0; + v2f_t f1; +}; +extern int a11_0[offsetof(struct s11, f0) == 0 ? 1 : -1]; +extern int a11_1[offsetof(struct s11, f1) == 2 ? 1 : -1]; +extern int a11_2[sizeof(struct s11) == 10 ? 1 : -1]; +extern int a11_3[__alignof(struct s11) == 2 ? 1 : -1]; diff --git a/test/Sema/pragma-pack-and-options-align.c b/test/Sema/pragma-pack-and-options-align.c new file mode 100644 index 0000000..c880ed6 --- /dev/null +++ b/test/Sema/pragma-pack-and-options-align.c @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -triple i686-apple-darwin9 %s -fsyntax-only -verify + +// Check that #pragma pack and #pragma options share the same stack. + +#pragma pack(push, 1) +struct s0 { + char c; + int x; +}; +extern int a[sizeof(struct s0) == 5 ? 1 : -1]; + +#pragma options align=natural +struct s1 { + char c; + int x; +}; +extern int a[sizeof(struct s1) == 8 ? 1 : -1]; + +#pragma pack(pop) +struct s2 { + char c; + int x; +}; +extern int a[sizeof(struct s2) == 5 ? 1 : -1]; +#pragma pack(pop) + +struct s3 { + char c; + int x; +}; +extern int a[sizeof(struct s3) == 8 ? 1 : -1]; + +/* expected-warning {{#pragma options align=reset failed: stack empty}} */ #pragma options align=reset +/* expected-warning {{#pragma pack(pop, ...) failed: stack empty}} */ #pragma pack(pop) diff --git a/test/Sema/scope-check.c b/test/Sema/scope-check.c index 6f86402..f3881ed 100644 --- a/test/Sema/scope-check.c +++ b/test/Sema/scope-check.c @@ -19,7 +19,7 @@ void test3clean(int*); int test3() { goto L; // expected-error{{illegal goto into protected scope}} -int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of declaration with __attribute__((cleanup))}} +int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of variable with __attribute__((cleanup))}} L: return a; } @@ -133,20 +133,20 @@ int test8(int x) { void test9(int n, void *P) { int Y; int Z = 4; - goto *P; // ok. + goto *P; // expected-warning {{indirect goto might cross protected scopes}} L2: ; - int a[n]; // expected-note 2 {{jump bypasses initialization of variable length array}} + int a[n]; // expected-note {{jump bypasses initialization of variable length array}} -L3: +L3: // expected-note {{possible target of indirect goto}} L4: - goto *P; // expected-warning {{illegal indirect goto in protected scope, unknown effect on scopes}} + goto *P; goto L3; // ok goto L4; // ok void *Ptrs[] = { - &&L2, // Ok. - &&L3 // expected-warning {{address taken of label in protected scope, jump to it would have unknown effect on scope}} + &&L2, + &&L3 }; } @@ -193,3 +193,9 @@ void test12(int n) { }; } +void test13(int n, void *p) { + int vla[n]; + goto *p; + a0: ; + static void *ps[] = { &&a0 }; +} diff --git a/test/Sema/switch.c b/test/Sema/switch.c index e63a194..27ad066 100644 --- a/test/Sema/switch.c +++ b/test/Sema/switch.c @@ -24,36 +24,37 @@ void foo(int X) { void test3(void) { // empty switch; - switch (0); + switch (0); // expected-warning {{no case matching constant switch condition '0'}} } extern int g(); void test4() { - switch (1) { + int cond; + switch (cond) { case 0 && g(): case 1 || g(): break; } - switch(1) { + switch(cond) { case g(): // expected-error {{expression is not an integer constant expression}} case 0 ... g(): // expected-error {{expression is not an integer constant expression}} break; } - switch (1) { + switch (cond) { case 0 && g() ... 1 || g(): break; } - switch (1) { + switch (cond) { case g() && 0: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} break; } - switch (1) { + switch (cond) { case 0 ... g() || 1: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} break; } @@ -68,7 +69,7 @@ void test5(int z) { } void test6() { - const char ch = 'a'; + char ch = 'a'; switch(ch) { case 1234: // expected-warning {{overflow converting case value}} break; @@ -261,3 +262,18 @@ void f1(unsigned x) { default: break; } } + +void test15() { + int i = 0; + switch (1) { // expected-warning {{no case matching constant switch condition '1'}} + case 0: i = 0; break; + case 2: i++; break; + } +} + +void test16() { + const char c = '5'; + switch (c) { // expected-warning {{no case matching constant switch condition '53'}} + case '6': return; + } +} diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c index 4ae0d4b..15608ec 100644 --- a/test/Sema/unused-expr.c +++ b/test/Sema/unused-expr.c @@ -110,3 +110,11 @@ void *some_function(void); void t10() { (void*) some_function(); //expected-warning {{expression result unused; should this cast be to 'void'?}} } + +void f(int i, ...) { + __builtin_va_list ap; + + __builtin_va_start(ap, i); + __builtin_va_arg(ap, int); + __builtin_va_end(ap); +} |