diff options
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/MicrosoftExtensions.c | 12 | ||||
-rw-r--r-- | test/Sema/array-init.c | 14 | ||||
-rw-r--r-- | test/Sema/block-as-object.m | 20 | ||||
-rw-r--r-- | test/Sema/conversion.c | 21 | ||||
-rw-r--r-- | test/Sema/expr-comma-c99.c (renamed from test/Sema/expr-comma-c89.c) | 0 | ||||
-rw-r--r-- | test/Sema/exprs.c | 26 | ||||
-rw-r--r-- | test/Sema/format-strings.c | 18 | ||||
-rw-r--r-- | test/Sema/i-c-e.c | 6 | ||||
-rw-r--r-- | test/Sema/parentheses.c | 4 | ||||
-rw-r--r-- | test/Sema/rdar6248119.m | 27 | ||||
-rw-r--r-- | test/Sema/return.c | 2 | ||||
-rw-r--r-- | test/Sema/shift.c | 20 |
12 files changed, 120 insertions, 50 deletions
diff --git a/test/Sema/MicrosoftExtensions.c b/test/Sema/MicrosoftExtensions.c index 0ef72855684d9..cb9fee9dc1d49 100644 --- a/test/Sema/MicrosoftExtensions.c +++ b/test/Sema/MicrosoftExtensions.c @@ -67,3 +67,15 @@ void foo() var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}} } +// Enumeration types with a fixed underlying type. +const int seventeen = 17; +typedef int Int; + +struct X0 { + enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} + enum E1 : seventeen; +}; + +enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} + SomeValue = 0x100000000 +}; diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c index 0ee22c0f19948..345ab6981b17d 100644 --- a/test/Sema/array-init.c +++ b/test/Sema/array-init.c @@ -264,3 +264,17 @@ void test_matrix() { } char badchararray[1] = { badchararray[0], "asdf" }; // expected-warning {{excess elements in array initializer}} expected-error {{initializer element is not a compile-time constant}} + +// Test the GNU extension for initializing an array from an array +// compound literal. PR9261. +typedef int int5[5]; +int a1[5] = (int[]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}} +int a2[5] = (int[5]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int [5]' from a compound literal of type 'int [5]' is a GNU extension}} +int a3[] = ((int[]){1, 2, 3, 4, 5}); // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int [5]' is a GNU extension}} +int a4[] = (int[5]){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int [5]' is a GNU extension}} +int a5[] = (int5){1, 2, 3, 4, 5}; // expected-warning{{initialization of an array of type 'int []' from a compound literal of type 'int5' (aka 'int [5]') is a GNU extension}} + +int a6[5] = (int[]){1, 2, 3}; // expected-error{{cannot initialize array of type 'int [5]' with array of type 'int [3]'}} + +int nonconst_value(); +int a7[5] = (int[5]){ 1, 2, 3, 4, nonconst_value() }; // expected-error{{initializer element is not a compile-time constant}} diff --git a/test/Sema/block-as-object.m b/test/Sema/block-as-object.m deleted file mode 100644 index a85b6067571ee..0000000000000 --- a/test/Sema/block-as-object.m +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks - -@interface Whatever -- copy; -@end - -typedef long (^MyBlock)(id obj1, id obj2); - -void foo(MyBlock b) { - id bar = [b copy]; -} - -void foo2(id b) { -} - -void foo3(void (^block)(void)) { - foo2(block); - id x; - foo(x); -} diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index e78902332eb1b..619d6993251f3 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -310,3 +310,24 @@ void test_8232669(void) { #define USER_SETBIT(set,bit) do { int i = bit; set[i/(8*sizeof(set[0]))] |= (1 << (i%(8*sizeof(set)))); } while(0) USER_SETBIT(bitset, 0); // expected-warning 2 {{implicit conversion changes signedness}} } + +// <rdar://problem/8559831> +enum E8559831a { E8559831a_val }; +enum E8559831b { E8559831b_val }; +typedef enum { E8559831c_val } E8559831c; +enum { E8559831d_val } value_d; + +void test_8559831_a(enum E8559831a value); +void test_8559831(enum E8559831b value_a, E8559831c value_c) { + test_8559831_a(value_a); // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}} + enum E8559831a a1 = value_a; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}} + a1 = value_a; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}} + + test_8559831_a(value_c); // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}} + enum E8559831a a2 = value_c; // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}} + a2 = value_c; // expected-warning{{implicit conversion from enumeration type 'E8559831c' to different enumeration type 'enum E8559831a'}} + + test_8559831_a(value_d); + enum E8559831a a3 = value_d; + a3 = value_d; +} diff --git a/test/Sema/expr-comma-c89.c b/test/Sema/expr-comma-c99.c index d0883ba202f9b..d0883ba202f9b 100644 --- a/test/Sema/expr-comma-c89.c +++ b/test/Sema/expr-comma-c99.c diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c index e88f7fc08bce2..0d6c5488de5f2 100644 --- a/test/Sema/exprs.c +++ b/test/Sema/exprs.c @@ -1,5 +1,31 @@ // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only +// PR 8876 - don't warn about trivially unreachable null derefs. Note that +// we put this here because the reachability analysis only kicks in for +// suppressing false positives when code has no errors. +#define PR8876(err_ptr) do {\ + if (err_ptr) *(int*)(err_ptr) = 1;\ + } while (0) + +#define PR8876_pos(err_ptr) do {\ + if (!err_ptr) *(int*)(err_ptr) = 1;\ + } while (0) + + +int test_pr8876() { + PR8876(0); // no-warning + PR8876_pos(0); // expected-warning{{indirection of non-volatile null pointer will be deleted, not trap}} expected-note{{consider using __builtin_trap() or qualifying pointer with 'volatile'}} + return 0; +} + +// PR 8183 - Handle null pointer constants on the left-side of the '&&', and reason about +// this when determining the reachability of the null pointer dereference on the right side. +void pr8183(unsigned long long test) +{ + (void)((((void*)0)) && (*((unsigned long long*)(((void*)0))) = ((unsigned long long)((test)) % (unsigned long long)((1000000000))))); // no-warning + (*((unsigned long long*)(((void*)0))) = ((unsigned long long)((test)) % (unsigned long long)((1000000000)))); // expected-warning {{indirection of non-volatile null pointer will be deleted, not trap}} expected-note {{consider using __builtin_trap() or qualifying pointer with 'volatile'}} +} + // PR1966 _Complex double test1() { return __extension__ 1.0if; diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index be506d7c6b191..c78095a04d7b5 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -340,3 +340,21 @@ void posix_extensions() { printf("%'f\n", (float) 1.0); // no-warning printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}} } + +// PR8486 +// +// Test what happens when -Wformat is on, but -Wformat-security is off. +#pragma GCC diagnostic warning "-Wformat" +#pragma GCC diagnostic ignored "-Wformat-security" + +void pr8486() { + printf("%s", 1); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} +} + +// PR9314 +// Don't warn about string literals that are PreDefinedExprs, e.g. __func__. +void pr9314() { + printf(__PRETTY_FUNCTION__); // no-warning + printf(__func__); // no-warning +} + diff --git a/test/Sema/i-c-e.c b/test/Sema/i-c-e.c index 4c2962d4b21a8..4d7007cd077c9 100644 --- a/test/Sema/i-c-e.c +++ b/test/Sema/i-c-e.c @@ -60,10 +60,14 @@ int comma3[(1,2)]; // expected-warning {{size of static array must be an integer // Pointer + __builtin_constant_p char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}} -int illegaldiv1[1 || 1/0]; // expected-warning {{division by zero is undefined}} +int illegaldiv1a[1 || 1/0]; // expected-warning {{division by zero is undefined}} +int illegaldiv1b[1 && 1/0]; // expected-warning {{division by zero is undefined}} expected-error{{variable length array declaration not allowed at file scope}} + int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}} \ // expected-warning {{division by zero is undefined}} int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}} +// PR9262 +int illegaldiv4[0 / (1 / 0)]; // expected-warning {{division by zero is undefined}} expected-error {{variable length array declaration not allowed at file scope}} int chooseexpr[__builtin_choose_expr(1, 1, expr)]; int realop[(__real__ 4) == 4 ? 1 : -1]; diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c index 6d6fa1d4bd42f..b45d8512f6bf7 100644 --- a/test/Sema/parentheses.c +++ b/test/Sema/parentheses.c @@ -37,3 +37,7 @@ void bitwise_rel(unsigned i) { (void)(i && i || 0); // no warning. (void)(0 || i && i); // no warning. } + +// RUN: %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s +// CHECK: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses] + diff --git a/test/Sema/rdar6248119.m b/test/Sema/rdar6248119.m deleted file mode 100644 index 6b120b2847561..0000000000000 --- a/test/Sema/rdar6248119.m +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only %s -verify -// Test case for: -// <rdar://problem/6248119> @finally doesn't introduce a new scope - -void f0() { - int i; - @try { - } @finally { - int i = 0; - } -} - -void f1() { - int i; - @try { - int i =0; - } @finally { - } -} - -void f2() { - int i; - @try { - } @catch(id e) { - int i = 0; - } -} diff --git a/test/Sema/return.c b/test/Sema/return.c index 0c2c72ee537fe..d9456b6e353bd 100644 --- a/test/Sema/return.c +++ b/test/Sema/return.c @@ -242,6 +242,7 @@ static inline int si_forward() {} // expected-warning{{control reaches end of no // Test warnings on ignored qualifiers on return types. const int ignored_c_quals(); // expected-warning{{'const' type qualifier on return type has no effect}} const volatile int ignored_cv_quals(); // expected-warning{{'const volatile' type qualifiers on return type have no effect}} +char* const volatile restrict ignored_cvr_quals(); // expected-warning{{'const volatile restrict' type qualifiers on return type have no effect}} // Test that for switch(enum) that if the switch statement covers all the cases // that we don't consider that for -Wreturn-type. @@ -254,4 +255,3 @@ int test_enum_cases(enum Cases C) { case C3: return 4; } } // no-warning - diff --git a/test/Sema/shift.c b/test/Sema/shift.c index 4273cab98ee39..df6b1141bdfc7 100644 --- a/test/Sema/shift.c +++ b/test/Sema/shift.c @@ -1,7 +1,9 @@ -// RUN: %clang -Wall -ffreestanding -fsyntax-only -Xclang -verify %s +// RUN: %clang -Wall -Wshift-sign-overflow -ffreestanding -fsyntax-only -Xclang -verify %s #include <limits.h> +#define WORD_BIT (sizeof(int) * CHAR_BIT) + enum { X = 1 << 0, Y = 1 << 1, @@ -32,6 +34,22 @@ void test() { c <<= CHAR_BIT+1; // expected-warning {{shift count >= width of type}} c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}} (void)((long)c << CHAR_BIT); + + int i; + i = 1 << (WORD_BIT - 2); + i = 2 << (WORD_BIT - 1); // expected-warning {{bits to represent, but 'int' only has}} + i = 1 << (WORD_BIT - 1); // expected-warning {{overrides the sign bit of the shift expression}} + i = -1 << (WORD_BIT - 1); + i = 0 << (WORD_BIT - 1); + i = (char)1 << (WORD_BIT - 2); + + unsigned u; + u = 1U << (WORD_BIT - 1); + u = 5U << (WORD_BIT - 1); + + long long int lli; + lli = INT_MIN << 2; // expected-warning {{bits to represent, but 'int' only has}} + lli = 1LL << (sizeof(long long) * CHAR_BIT - 2); } #define a 0 |