diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
commit | bca07a4524feb4edec581062d631a13116320a24 (patch) | |
tree | a9243275843fbeaa590afc07ee888e006b8d54ea /test/Sema | |
parent | 998bc5802ecdd65ce3b270f6c69a8ae8557f0a10 (diff) | |
download | src-bca07a4524feb4edec581062d631a13116320a24.tar.gz src-bca07a4524feb4edec581062d631a13116320a24.zip |
Vendor import of clang trunk r126079:vendor/clang/clang-r126079
Notes
Notes:
svn path=/vendor/clang/dist/; revision=218887
svn path=/vendor/clang/clang-r126079/; revision=218888; tag=vendor/clang/clang-r126079
Diffstat (limited to 'test/Sema')
86 files changed, 1367 insertions, 187 deletions
diff --git a/test/Sema/Inputs/conversion.h b/test/Sema/Inputs/conversion.h index 9f6ed2e70fb2..768190f8d260 100644 --- a/test/Sema/Inputs/conversion.h +++ b/test/Sema/Inputs/conversion.h @@ -1,3 +1,4 @@ /* Fake system header for Sema/conversion.c */ #define LONG_MAX __LONG_MAX__ +#define SETBIT(set,bit) do { int i = bit; set[i/(8*sizeof(set[0]))] |= (1 << (i%(8*sizeof(set)))); } while(0) diff --git a/test/Sema/MicrosoftExtensions.c b/test/Sema/MicrosoftExtensions.c new file mode 100644 index 000000000000..0ef72855684d --- /dev/null +++ b/test/Sema/MicrosoftExtensions.c @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions + + +struct A +{ + int a[]; /* expected-warning {{flexible array member 'a' in otherwise empty struct is a Microsoft extension}} */ +}; + +struct C { + int l; + union { + int c1[]; /* expected-warning {{flexible array member 'c1' in a union is a Microsoft extension}} */ + char c2[]; /* expected-warning {{flexible array member 'c2' in a union is a Microsoft extension}} */ + }; +}; + + +struct D { + int l; + int D[]; +}; + + +enum ENUM1; // expected-warning {{forward references to 'enum' types are a Microsoft extension}} +enum ENUM1 var1 = 3; +enum ENUM1* var2 = 0; + + +enum ENUM2 { + ENUM2_a = (enum ENUM2) 4, + ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}} + ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}} +}; + + + + +typedef struct notnested { + long bad1; + long bad2; +} NOTNESTED; + + +typedef struct nested1 { + long a; + struct notnested var1; + NOTNESTED var2; +} NESTED1; + +struct nested2 { + long b; + NESTED1; // expected-warning {{anonymous structs are a Microsoft extension}} +}; + +struct test { + int c; + struct nested2; // expected-warning {{anonymous structs are a Microsoft extension}} +}; + +void foo() +{ + struct test var; + var.a; + var.b; + var.c; + var.bad1; // expected-error {{no member named 'bad1' in 'struct test'}} + var.bad2; // expected-error {{no member named 'bad2' in 'struct test'}} +} + diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index 23c1405011a3..a53bb4da0003 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -36,7 +36,11 @@ struct _st { // rdar://6774906 __attribute__((address_space(256))) void * * const base = 0; void * get_0(void) { - return base[0]; // expected-error {{illegal implicit conversion between two pointers with different address spaces}} \ - expected-warning {{returning 'void __attribute__((address_space(256))) *' from a function with result type 'void *' discards qualifiers}} + return base[0]; // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}} } +__attribute__((address_space(1))) char test3_array[10]; +void test3(void) { + extern void test3_helper(char *p); // expected-note {{passing argument to parameter 'p' here}} + test3_helper(test3_array); // expected-error {{changes address space of pointer}} +} diff --git a/test/Sema/altivec-init.c b/test/Sema/altivec-init.c index b5758bc71837..ef6fe4bd9d2f 100644 --- a/test/Sema/altivec-init.c +++ b/test/Sema/altivec-init.c @@ -30,6 +30,6 @@ void test() f(vAltiVec); vGCC = vAltiVec; - vGCC = vGCC > vAltiVec; + int res = vGCC > vAltiVec; vAltiVec = 0 ? vGCC : vGCC; } diff --git a/test/Sema/arm-neon-types.c b/test/Sema/arm-neon-types.c new file mode 100644 index 000000000000..152d4c9b9a78 --- /dev/null +++ b/test/Sema/arm-neon-types.c @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -triple thumbv7-apple-darwin10 -target-cpu cortex-a8 -fsyntax-only -Wvector-conversions -ffreestanding -verify %s + +#include <arm_neon.h> + +// Radar 8228022: Should not report incompatible vector types. +int32x2_t test(int32x2_t x) { + return vshr_n_s32(x, 31); +} + +// ...but should warn when the types really do not match. +float32x2_t test2(uint32x2_t x) { + return vcvt_n_f32_s32(x, 0); // expected-warning {{incompatible vector types}} +} diff --git a/test/Sema/array-constraint.c b/test/Sema/array-constraint.c index 9fcac25abe96..bee33c09efbd 100644 --- a/test/Sema/array-constraint.c +++ b/test/Sema/array-constraint.c @@ -36,7 +36,7 @@ pfunc xx(int f[](void)) { // expected-error {{'f' declared as array of functions void check_size() { float f; int size_not_int[f]; // expected-error {{size of array has non-integer type 'float'}} - int negative_size[1-2]; // expected-error{{array size is negative}} + int negative_size[1-2]; // expected-error{{array with a negative size}} int zero_size[0]; // expected-warning{{zero size arrays are an extension}} } @@ -46,7 +46,7 @@ typedef int TA[I]; // expected-error {{variable length array declaration not all void strFunc(char *); // expected-note{{passing argument to parameter here}} const char staticAry[] = "test"; void checkStaticAry() { - strFunc(staticAry); // expected-warning{{passing 'char const [5]' to parameter of type 'char *' discards qualifiers}} + strFunc(staticAry); // expected-warning{{passing 'const char [5]' to parameter of type 'char *' discards qualifiers}} } diff --git a/test/Sema/asm.c b/test/Sema/asm.c index 6f2272da9e77..7f0f396b9d82 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -36,7 +36,7 @@ void test3() { // <rdar://problem/6156893> void test4(const volatile void *addr) { - asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'void const volatile' in asm input for constraint 'r'}} + asm ("nop" : : "r"(*addr)); // expected-error {{invalid type 'const volatile void' in asm input for constraint 'r'}} asm ("nop" : : "m"(*addr)); asm ("nop" : : "r"(test4(addr))); // expected-error {{invalid type 'void' in asm input for constraint 'r'}} @@ -79,3 +79,29 @@ int test7(unsigned long long b) { // <rdar://problem/7574870> asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}} + +// PR3904 +void test8(int i) { + // A number in an input constraint can't point to a read-write constraint. + asm("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}} +} + +// PR3905 +void test9(int i) { + asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}} + asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}} +} + +register int g asm("dx"); // expected-error{{global register variables are not supported}} + +void test10(void){ + static int g asm ("g_asm") = 0; + extern int gg asm ("gg_asm"); + __private_extern__ int ggg asm ("ggg_asm"); + + int a asm ("a_asm"); // expected-warning{{ignored asm label 'a_asm' on automatic variable}} + auto int aa asm ("aa_asm"); // expected-warning{{ignored asm label 'aa_asm' on automatic variable}} + + register int r asm ("cx"); + register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}} +} diff --git a/test/Sema/attr-alias.c b/test/Sema/attr-alias.c new file mode 100644 index 000000000000..151052f89e51 --- /dev/null +++ b/test/Sema/attr-alias.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -verify %s + +void g() {} + +// It is important that the following string be in the error message. The gcc +// testsuite looks for it to decide if a target supports aliases. + +void f() __attribute__((alias("g"))); //expected-error {{only weak aliases are supported}} diff --git a/test/Sema/attr-aligned.c b/test/Sema/attr-aligned.c index bcb12ee40de7..c094ff172dd5 100644 --- a/test/Sema/attr-aligned.c +++ b/test/Sema/attr-aligned.c @@ -13,9 +13,26 @@ struct struct_with_ueber_char { ueber_aligned_char c; }; -char c = 0; +char a = 0; char a0[__alignof__(ueber_aligned_char) == 8? 1 : -1] = { 0 }; char a1[__alignof__(struct struct_with_ueber_char) == 8? 1 : -1] = { 0 }; -char a2[__alignof__(c) == 1? : -1] = { 0 }; -char a3[sizeof(c) == 1? : -1] = { 0 }; +char a2[__alignof__(a) == 1? : -1] = { 0 }; +char a3[sizeof(a) == 1? : -1] = { 0 }; + +// rdar://problem/8335865 +int b __attribute__((aligned(2))); +char b1[__alignof__(b) == 2 ?: -1] = {0}; + +struct C { int member __attribute__((aligned(2))); } c; +char c1[__alignof__(c) == 4 ?: -1] = {0}; +char c2[__alignof__(c.member) == 4 ?: -1] = {0}; + +struct D { int member __attribute__((aligned(2))) __attribute__((packed)); } d; +char d1[__alignof__(d) == 2 ?: -1] = {0}; +char d2[__alignof__(d.member) == 2 ?: -1] = {0}; + +struct E { int member __attribute__((aligned(2))); } __attribute__((packed)); +struct E e; +char e1[__alignof__(e) == 2 ?: -1] = {0}; +char e2[__alignof__(e.member) == 2 ?: -1] = {0}; diff --git a/test/Sema/attr-deprecated-message.c b/test/Sema/attr-deprecated-message.c new file mode 100644 index 000000000000..5de31d0d13f8 --- /dev/null +++ b/test/Sema/attr-deprecated-message.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only +// rdar: // 6734520 + +typedef int INT1 __attribute__((deprecated("Please avoid INT1"))); + +typedef INT1 INT2 __attribute__ ((__deprecated__("Please avoid INT2"))); + +typedef INT1 INT1a; // expected-warning {{'INT1' is deprecated: Please avoid INT1}} + +typedef INT1 INT1b __attribute__ ((deprecated("Please avoid INT1b"))); + +INT1 should_be_unavailable; // expected-warning {{'INT1' is deprecated: Please avoid INT1}} +INT1a should_not_be_deprecated; + +INT1 f1(void) __attribute__ ((deprecated("Please avoid f1"))); +INT1 f2(void); // expected-warning {{'INT1' is deprecated: Please avoid INT1}} + +typedef enum {red, green, blue} Color __attribute__((deprecated("Please avoid Color"))); + + +Color c1; // expected-warning {{'Color' is deprecated: Please avoid Color}} + +int g1; +int g2 __attribute__ ((deprecated("Please avoid g2"))); + +int func1() +{ + int (*pf)() = f1; // expected-warning {{'f1' is deprecated: Please avoid f1}} + int i = f2(); + return g1 + g2; // expected-warning {{'g2' is deprecated: Please avoid g2}} +} diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index e7c997f3ee23..b26171b86b0a 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -98,3 +98,16 @@ unsigned long test16 __attribute__((deprecated)) foo_dep test17, // expected-warning {{'foo_dep' is deprecated}} test18 __attribute__((deprecated)), test19; + +// rdar://problem/8518751 +enum __attribute__((deprecated)) Test20 { + test20_a __attribute__((deprecated)), + test20_b +}; +void test20() { + enum Test20 f; // expected-warning {{'Test20' is deprecated}} + f = test20_a; // expected-warning {{'test20_a' is deprecated}} + f = test20_b; +} + +char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1]; diff --git a/test/Sema/attr-malloc.c b/test/Sema/attr-malloc.c index 9970b9de4f95..2cec84de4969 100644 --- a/test/Sema/attr-malloc.c +++ b/test/Sema/attr-malloc.c @@ -1,7 +1,10 @@ // RUN: %clang -Xclang -verify -fsyntax-only %s // RUN: %clang -emit-llvm -S -o %t %s -#include <stdlib.h> +#include <stddef.h> + +// Declare malloc here explicitly so we don't depend on system headers. +void * malloc(size_t) __attribute((malloc)); int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}} diff --git a/test/Sema/attr-naked.c b/test/Sema/attr-naked.c new file mode 100644 index 000000000000..65d1726da133 --- /dev/null +++ b/test/Sema/attr-naked.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only + +int a __attribute__((naked)); // expected-warning {{'naked' attribute only applies to functions}} + +void t1() __attribute__((naked)); + +void t2() __attribute__((naked(2))); // expected-error {{attribute requires 0 argument(s)}} + diff --git a/test/Sema/attr-nodebug.c b/test/Sema/attr-nodebug.c index 203c2a7300ab..6865de060266 100644 --- a/test/Sema/attr-nodebug.c +++ b/test/Sema/attr-nodebug.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -int a __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to function types}} +int a __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to functions}} void t1() __attribute__((nodebug)); diff --git a/test/Sema/attr-noinline.c b/test/Sema/attr-noinline.c index 92dc9007eb19..8c91b65b4f48 100644 --- a/test/Sema/attr-noinline.c +++ b/test/Sema/attr-noinline.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to function types}} +int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to functions}} void t1() __attribute__((noinline)); diff --git a/test/Sema/attr-unavailable-message.c b/test/Sema/attr-unavailable-message.c new file mode 100644 index 000000000000..a1e047c8176b --- /dev/null +++ b/test/Sema/attr-unavailable-message.c @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// rdar: //6734520 + +int foo(int) __attribute__((__unavailable__("USE IFOO INSTEAD"))); // expected-note {{function has been explicitly marked unavailable here}} +double dfoo(double) __attribute__((__unavailable__("NO LONGER"))); // expected-note 2 {{function has been explicitly marked unavailable here}} + +void bar() __attribute__((__unavailable__)); // expected-note {{explicitly marked unavailable}} + +void test_foo() { + int ir = foo(1); // expected-error {{'foo' is unavailable: USE IFOO INSTEAD}} + double dr = dfoo(1.0); // expected-error {{'dfoo' is unavailable: NO LONGER}} + + void (*fp)() = &bar; // expected-error {{'bar' is unavailable}} + + double (*fp4)(double) = dfoo; // expected-error {{'dfoo' is unavailable: NO LONGER}} +} + +char test2[__has_feature(attribute_unavailable_with_message) ? 1 : -1]; diff --git a/test/Sema/attr-unused.c b/test/Sema/attr-unused.c index 28715141b995..6a7ea951a360 100644 --- a/test/Sema/attr-unused.c +++ b/test/Sema/attr-unused.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -Wunused-variable -fsyntax-only %s +// RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s static void (*fp0)(void) __attribute__((unused)); @@ -20,8 +20,24 @@ void test0() { int x; // expected-warning {{unused variable}} Int_not_unused i0; // expected-warning {{unused variable}} - Int_unused i1; + Int_unused i1; // expected-warning {{'Int_unused' was marked unused but was used}} struct Test0_not_unused s0; // expected-warning {{unused variable}} - struct Test0_unused s1; + struct Test0_unused s1; // expected-warning {{'Test0_unused' was marked unused but was used}} +} + +int f3(int x) { // expected-warning{{unused parameter 'x'}} + return 0; +} + +int f4(int x) { + return x; +} + +int f5(int x __attribute__((__unused__))) { + return 0; +} + +int f6(int x __attribute__((__unused__))) { + return x; // expected-warning{{'x' was marked unused but was used}} } diff --git a/test/Sema/attr-used.c b/test/Sema/attr-used.c index d50f4c09ac85..08388169247e 100644 --- a/test/Sema/attr-used.c +++ b/test/Sema/attr-used.c @@ -3,7 +3,7 @@ extern int l0 __attribute__((used)); // expected-warning {{used attribute ignored}} __private_extern__ int l1 __attribute__((used)); // expected-warning {{used attribute ignored}} -struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to variable and function types}} +struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to variables and functions}} int x; }; diff --git a/test/Sema/attr-weak.c b/test/Sema/attr-weak.c index 8e3e626c5d34..41c9fd7165ab 100644 --- a/test/Sema/attr-weak.c +++ b/test/Sema/attr-weak.c @@ -8,8 +8,7 @@ int __attribute__((weak_import)) g4(void); void __attribute__((weak_import)) g5(void) { } -struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute only applies to variable and function types}} -struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variable and function types}} - -static int x __attribute__((weak)); // expected-error {{weak declaration of 'x' must be public}} +struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute only applies to variables and functions}} +struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variables and functions}} +static int x __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} diff --git a/test/Sema/bitfield-promote-int-16bit.c b/test/Sema/bitfield-promote-int-16bit.c deleted file mode 100644 index cd9adcffc071..000000000000 --- a/test/Sema/bitfield-promote-int-16bit.c +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -triple pic16-unknown-unknown - -// Check that int-sized unsigned bit-fields promote to unsigned int -// on targets where sizeof(unsigned short) == sizeof(unsigned int) - -enum E { ec1, ec2, ec3 }; -struct S { - enum E e : 16; - unsigned short us : 16; - unsigned long ul1 : 8; - unsigned long ul2 : 16; -} s; - -__typeof(s.e + s.e) x_e; -unsigned x_e; - -__typeof(s.us + s.us) x_us; -unsigned x_us; - -__typeof(s.ul1 + s.ul1) x_ul1; -signed x_ul1; - -__typeof(s.ul2 + s.ul2) x_ul2; -unsigned x_ul2; - diff --git a/test/Sema/bitfield.c b/test/Sema/bitfield.c index 5bb194b1f3a9..49c1c7d44361 100644 --- a/test/Sema/bitfield.c +++ b/test/Sema/bitfield.c @@ -34,3 +34,7 @@ struct {unsigned x : 2;} x2; __typeof__((x.x+=1)+1) y; __typeof__(x.x<<1) y; int y; + +struct PR8025 { + double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}} +}; diff --git a/test/Sema/block-args.c b/test/Sema/block-args.c index 970c60d51ddb..e2e2d8e44622 100644 --- a/test/Sema/block-args.c +++ b/test/Sema/block-args.c @@ -34,3 +34,9 @@ void f0() { ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \ // expected-error {{parameter name omitted}} } + +// rdar://problem/8962770 +void test4() { + int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}} +} + diff --git a/test/Sema/block-call.c b/test/Sema/block-call.c index 27e4cfc6d46b..2aa1422dd915 100644 --- a/test/Sema/block-call.c +++ b/test/Sema/block-call.c @@ -13,7 +13,7 @@ int main() { int (^IFP) () = PFR; // OK - const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}} + const int (^CIC) () = IFP; // OK - initializing 'const int (^)()' with an expression of type 'int (^)()'}} const int (^CICC) () = CIC; diff --git a/test/Sema/block-labels.c b/test/Sema/block-labels.c index 353a5702eafa..d1b60cc7d31f 100644 --- a/test/Sema/block-labels.c +++ b/test/Sema/block-labels.c @@ -3,8 +3,12 @@ void xx(); int a() { - A:if (1) xx(); - return ^{A:return 1;}(); + A: + + if (1) xx(); + return ^{ + A: return 1; + }(); } int b() { A: return ^{int a; A:return 1;}(); @@ -15,5 +19,9 @@ int d() { } int c() { - goto A; return ^{ A:return 1;}(); // expected-error {{use of undeclared label 'A'}} + goto A; // expected-error {{use of undeclared label 'A'}} + return ^{ + A: + return 1; + }(); } diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index 5a4ec010d3a2..c6e1e9dc5422 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -78,10 +78,10 @@ static int funk(char *s) { } void next(); void foo4() { - int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(char const *)' with an expression of type 'int (^)(char *)'}} - int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (*)(char const *)' with an expression of type 'int (char *)'}} + int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(const char *)' with an expression of type 'int (^)(char *)'}} + int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (*)(const char *)' with an expression of type 'int (char *)'}} - int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \ + int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring C library function 'printf' with type 'int (const char *, ...)'}} \ // expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}} } @@ -97,7 +97,8 @@ bptr foo5(int j) { } int (*funcptr3[5])(long); -int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block declared as returning an array}} +int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block cannot return array type}} expected-warning {{incompatible pointer to integer conversion}} +int sz9 = sizeof(^int(*())()[3]{ }); // expected-error {{function cannot return array type}} void foo6() { int (^b)(int) __attribute__((noreturn)); @@ -109,7 +110,7 @@ void foo6() { void foo7() { - const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' with an expression of type 'int (^)(void)'}} + const int (^BB) (void) = ^{ const int i = 1; return i; }; // OK - initializing 'const int (^)(void)' with an expression of type 'int (^)(void)' const int (^CC) (void) = ^const int{ const int i = 1; return i; }; diff --git a/test/Sema/builtin_objc_msgSend.c b/test/Sema/builtin_objc_msgSend.c new file mode 100644 index 000000000000..357a5bc26eb5 --- /dev/null +++ b/test/Sema/builtin_objc_msgSend.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify +// rdar://8632525 + +typedef struct objc_class *Class; +typedef struct objc_object { + Class isa; +} *id; + + +typedef struct objc_selector *SEL; +extern id objc_msgSend(id self, SEL op, ...); + diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index 787630c1a8c4..4072faa94b9f 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -26,7 +26,7 @@ int test6(float a, long double b) { #define CFSTR __builtin___CFStringMakeConstantString void test7() { const void *X; - X = CFSTR("\242"); + X = CFSTR("\242"); // expected-warning {{input conversion stopped}} X = CFSTR("\0"); // expected-warning {{ CFString literal contains NUL character }} X = CFSTR(242); // expected-error {{ CFString literal is not a string constant }} expected-warning {{incompatible integer to pointer conversion}} X = CFSTR("foo", "bar"); // expected-error {{too many arguments to function call}} @@ -37,7 +37,7 @@ void test7() { void test9(short v) { unsigned i, old; - + old = __sync_fetch_and_add(); // expected-error {{too few arguments to function call}} old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}} old = __sync_fetch_and_add((unsigned*)0, 42i); // expected-warning {{imaginary constants are an extension}} @@ -56,14 +56,14 @@ void test9(short v) { void test10(void) __attribute__((noreturn)); void test10(void) { - __asm__("int3"); + __asm__("int3"); __builtin_unreachable(); - + // No warning about falling off the end of a noreturn function. } void test11(int X) { - switch (X) { + switch (X) { case __builtin_eh_return_data_regno(0): // constant foldable. break; } @@ -95,3 +95,10 @@ void test14() { void test15(const char *s) { __builtin_printf("string is %s\n", s); } + +// PR7885 +int test16() { + return __builtin_constant_p() + // expected-error{{too few arguments}} + __builtin_constant_p(1, 2); // expected-error {{too many arguments}} +} + diff --git a/test/Sema/cast-to-union.c b/test/Sema/cast-to-union.c index 6f275e8b505f..c32964dfc0d5 100644 --- a/test/Sema/cast-to-union.c +++ b/test/Sema/cast-to-union.c @@ -1,11 +1,12 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -union u { int i; }; +union u { int i; unsigned : 3; }; void f(union u); void test(int x) { f((union u)x); // expected-warning {{C99 forbids casts to union type}} f((union u)&x); // expected-error {{cast to union type from type 'int *' not present in union}} + f((union u)2U); // expected-error {{cast to union type from type 'unsigned int' not present in union}} } union u w = (union u)2; // expected-warning {{C99 forbids casts to union type}} diff --git a/test/Sema/cast.c b/test/Sema/cast.c index e52dcaebbddb..71c44b4b816b 100644 --- a/test/Sema/cast.c +++ b/test/Sema/cast.c @@ -16,3 +16,144 @@ long bar1(long *next) { return (long)(*next)++; } +typedef _Bool Bool; +typedef int Int; +typedef long Long; +typedef float Float; +typedef double Double; +typedef _Complex int CInt; +typedef _Complex long CLong; +typedef _Complex float CFloat; +typedef _Complex double CDouble; +typedef void *VoidPtr; +typedef char *CharPtr; + +void testBool(Bool v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; + (void) (VoidPtr) v; + (void) (CharPtr) v; +} + +void testInt(Int v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; + (void) (VoidPtr) v; + (void) (CharPtr) v; +} + +void testLong(Long v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; + (void) (VoidPtr) v; + (void) (CharPtr) v; +} + +void testFloat(Float v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; +} + +void testDouble(Double v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; +} + +void testCI(CInt v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; +} + +void testCLong(CLong v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; +} + +void testCFloat(CFloat v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; +} + +void testCDouble(CDouble v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (Float) v; + (void) (Double) v; + (void) (CInt) v; + (void) (CLong) v; + (void) (CFloat) v; + (void) (CDouble) v; +} + +void testVoidPtr(VoidPtr v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (VoidPtr) v; + (void) (CharPtr) v; +} + +void testCharPtr(CharPtr v) { + (void) (Bool) v; + (void) (Int) v; + (void) (Long) v; + (void) (VoidPtr) v; + (void) (CharPtr) v; +} diff --git a/test/Sema/compare.c b/test/Sema/compare.c index b2c35633953d..5221b172a602 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -288,3 +288,27 @@ int test6(unsigned i, unsigned power) { unsigned x = (i < (1 << power) ? i : 0); return x != 3 ? 1 << power : i; } + +// <rdar://problem/8414119> enum >= (enum)0 comparison should not generate any warnings +enum rdar8414119_Vals { X, Y, Z }; +#define ZERO 0 +#define CHECK(x) (x >= X) +void rdar8414119_foo(enum rdar8414119_Vals v) { + if (CHECK(v)) // no-warning + return; + if (v >= X) // no-warning + return; +} +int rdar8414119_bar(unsigned x) { + return x >= ZERO; // no-warning +} +#undef ZERO +#undef CHECK + +int rdar8511238() { + enum A { A_foo, A_bar }; + enum A a; + if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}} + return 0; + return 20; +} diff --git a/test/Sema/complex-int.c b/test/Sema/complex-int.c index cb76a342c2d0..32249b35e1c5 100644 --- a/test/Sema/complex-int.c +++ b/test/Sema/complex-int.c @@ -53,3 +53,15 @@ void test4(_Complex float *x) { void test5(_Complex int *x) { (*x)++; } + +int i1[(2+3i)*(5+7i) == 29i-11 ? 1 : -1]; +int i2[(29i-11)/(5+7i) == 2+3i ? 1 : -1]; +int i3[-(2+3i) == +(-3i-2) ? 1 : -1]; +int i4[~(2+3i) == 2-3i ? 1 : -1]; +int i5[(3i == -(-3i) ? ((void)3, 1i - 1) : 0) == 1i - 1 ? 1 : -1]; + +int f1[(2.0+3.0i)*(5.0+7.0i) == 29.0i-11.0 ? 1 : -1]; +int f2[(29.0i-11.0)/(5.0+7.0i) == 2.0+3.0i ? 1 : -1]; +int f3[-(2.0+3.0i) == +(-3.0i-2.0) ? 1 : -1]; +int f4[~(2.0+3.0i) == 2.0-3.0i ? 1 : -1]; +int f5[(3.0i == -(-3.0i) ? ((void)3.0, __extension__ (1.0i - 1.0)) : 0) == 1.0i - 1.0 ? 1 : -1]; diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index aade4641ace0..41307625999e 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -3,9 +3,10 @@ struct foo { int a, b; }; static struct foo t = (struct foo){0,0}; -static struct foo t2 = {0,0}; +static struct foo t1 = __builtin_choose_expr(0, (struct foo){0,0}, (struct foo){0,0}); +static struct foo t2 = {0,0}; static struct foo t3 = t2; // -expected-error {{initializer element is not a compile-time constant}} -static int *p = (int []){2,4}; +static int *p = (int []){2,4}; static int x = (int){1}; static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}} diff --git a/test/Sema/conditional-expr.c b/test/Sema/conditional-expr.c index 6e248bc3cfec..7a8c9e9f3612 100644 --- a/test/Sema/conditional-expr.c +++ b/test/Sema/conditional-expr.c @@ -75,3 +75,16 @@ int f2(int x) { // We can suppress this because the immediate context wants an int. return (x != 0) ? 0U : x; } + +#define NULL (void*)0 + +void PR9236() { + struct A {int i;} A1; + (void)(1 ? A1 : NULL); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} + (void)(1 ? NULL : A1); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} + (void)(1 ? 0 : A1); // expected-error{{incompatible operand types}} + (void)(1 ? (void*)0 : A1); // expected-error{{incompatible operand types}} + (void)(1 ? A1: (void*)0); // expected-error{{incompatible operand types}} + (void)(1 ? A1 : (NULL)); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} +} + diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index 42097e75f317..aa0cee5da5b3 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -41,7 +41,7 @@ struct s { EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1)); -EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1)); +EVAL_EXPR(20, __builtin_constant_p(*((int*) 10))); EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1); @@ -80,3 +80,9 @@ EVAL_EXPR(38, __builtin_expect(1,1) == 1 ? 1 : -1) // PR7884 EVAL_EXPR(39, __real__(1.f) == 1 ? 1 : -1) EVAL_EXPR(40, __imag__(1.f) == 0 ? 1 : -1) + +// rdar://8875946 +void rdar8875946() { + double _Complex P; + float _Complex P2 = 3.3f + P; +} diff --git a/test/Sema/const-ptr-int-ptr-cast.c b/test/Sema/const-ptr-int-ptr-cast.c index c6e70b8b2455..8beaf9d4947c 100644 --- a/test/Sema/const-ptr-int-ptr-cast.c +++ b/test/Sema/const-ptr-int-ptr-cast.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s #include <stdint.h> diff --git a/test/Sema/constant-builtins-2.c b/test/Sema/constant-builtins-2.c index 23aa314e0c32..68b46bf19ad9 100644 --- a/test/Sema/constant-builtins-2.c +++ b/test/Sema/constant-builtins-2.c @@ -50,3 +50,7 @@ int h0 = __builtin_types_compatible_p(int, float); //int h2 = __builtin_expect(0, 0); extern long int bi0; extern __typeof__(__builtin_expect(0, 0)) bi0; + +// Strings +int array1[__builtin_strlen("ab\0cd")]; +int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1]; diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c new file mode 100644 index 000000000000..7c6b9b81bd0f --- /dev/null +++ b/test/Sema/constant-conversion.c @@ -0,0 +1,57 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin %s + +// This file tests -Wconstant-conversion, a subcategory of -Wconversion +// which is on by default. + +// rdar://problem/6792488 +void test_6792488(void) { + int x = 0x3ff0000000000000U; // expected-warning {{implicit conversion from 'unsigned long' to 'int' changes value from 4607182418800017408 to 0}} +} + +void test_7809123(void) { + struct { int i5 : 5; } a; + + a.i5 = 36; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 36 to 4}} +} + +void test() { + struct { int bit : 1; } a; + a.bit = 1; // shouldn't warn +} + +enum Test2 { K_zero, K_one }; +enum Test2 test2(enum Test2 *t) { + *t = 20; + return 10; // shouldn't warn +} + +void test3() { + struct A { + unsigned int foo : 2; + int bar : 2; + }; + + struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} + struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} + struct A c[] = {{10, 0}}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} + struct A d = (struct A) { 10, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} + struct A e = { .foo = 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} +} + +void test4() { + struct A { + char c : 2; + } a; + + a.c = 0x101; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 257 to 1}} +} + +void test5() { + struct A { + _Bool b : 1; + } a; + + // Don't warn about this implicit conversion to bool, or at least + // don't warn about it just because it's a bitfield. + a.b = 100; +} diff --git a/test/Sema/constructor-attribute.c b/test/Sema/constructor-attribute.c index 3dfbbcbe281c..2decebbd284a 100644 --- a/test/Sema/constructor-attribute.c +++ b/test/Sema/constructor-attribute.c @@ -1,12 +1,12 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -int x __attribute__((constructor)); // expected-warning {{'constructor' attribute only applies to function types}} +int x __attribute__((constructor)); // expected-warning {{'constructor' attribute only applies to functions}} int f() __attribute__((constructor)); int f() __attribute__((constructor(1))); int f() __attribute__((constructor(1,2))); // expected-error {{attribute requires 0 or 1 argument(s)}} int f() __attribute__((constructor(1.0))); // expected-error {{'constructor' attribute requires parameter 1 to be an integer constant}} -int x __attribute__((destructor)); // expected-warning {{'destructor' attribute only applies to function types}} +int x __attribute__((destructor)); // expected-warning {{'destructor' attribute only applies to functions}} int f() __attribute__((destructor)); int f() __attribute__((destructor(1))); int f() __attribute__((destructor(1,2))); // expected-error {{attribute requires 0 or 1 argument(s)}} diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 5fbd64de5bb4..e78902332eb1 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -40,17 +40,17 @@ void test0(char c, short s, int i, long l, long long ll) { l = (long) 0; c = (char) BIG; - c = (short) BIG; // expected-warning {{implicit conversion loses integer precision}} - c = (int) BIG; // expected-warning {{implicit conversion loses integer precision}} - c = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + c = (short) BIG; // expected-warning {{implicit conversion from 'short' to 'char' changes value}} + c = (int) BIG; // expected-warning {{implicit conversion from 'int' to 'char' changes value}} + c = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'char' changes value}} s = (char) BIG; s = (short) BIG; - s = (int) BIG; // expected-warning {{implicit conversion loses integer precision}} - s = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + s = (int) BIG; // expected-warning {{implicit conversion from 'int' to 'short' changes value}} + s = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'short' changes value}} i = (char) BIG; i = (short) BIG; i = (int) BIG; - i = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + i = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'int' changes value}} l = (char) BIG; l = (short) BIG; l = (int) BIG; @@ -63,10 +63,10 @@ char test1(long long ll) { return (int) ll; // expected-warning {{implicit conversion loses integer precision}} return (short) ll; // expected-warning {{implicit conversion loses integer precision}} return (char) ll; - return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (int) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (short) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'char' changes value}} + return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'char' changes value}} + return (int) BIG; // expected-warning {{implicit conversion from 'int' to 'char' changes value}} + return (short) BIG; // expected-warning {{implicit conversion from 'short' to 'char' changes value}} return (char) BIG; } @@ -76,9 +76,9 @@ short test2(long long ll) { return (int) ll; // expected-warning {{implicit conversion loses integer precision}} return (short) ll; return (char) ll; - return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (int) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'short' changes value}} + return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'short' changes value}} + return (int) BIG; // expected-warning {{implicit conversion from 'int' to 'short' changes value}} return (short) BIG; return (char) BIG; } @@ -89,8 +89,8 @@ int test3(long long ll) { return (int) ll; return (short) ll; return (char) ll; - return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'int' changes value}} + return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'int' changes value}} return (int) BIG; return (short) BIG; return (char) BIG; @@ -277,7 +277,7 @@ unsigned char test19(unsigned long u64) { // <rdar://problem/7631400> void test_7631400(void) { // This should show up despite the caret being inside a macro substitution - char s = LONG_MAX; // expected-warning {{implicit conversion loses integer precision: 'long' to 'char'}} + char s = LONG_MAX; // expected-warning {{implicit conversion from 'long' to 'char' changes value}} } // <rdar://problem/7676608>: assertion for compound operators with non-integral RHS @@ -297,3 +297,16 @@ void test_7904686(void) { unsigned u2 = -1; // expected-warning {{implicit conversion changes signedness}} u2 = -1; // expected-warning {{implicit conversion changes signedness}} } + +// <rdar://problem/8232669>: don't warn about conversions required by +// contexts in system headers +void test_8232669(void) { + unsigned bitset[20]; + SETBIT(bitset, 0); + + unsigned y = 50; + SETBIT(bitset, y); + +#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}} +} diff --git a/test/Sema/designated-initializers.c b/test/Sema/designated-initializers.c index 7e4ed6892aee..c9a8482e85db 100644 --- a/test/Sema/designated-initializers.c +++ b/test/Sema/designated-initializers.c @@ -249,3 +249,31 @@ struct expr expr0 = { } } }; + +// PR6955 + +struct ds { + struct { + struct { + unsigned int a; + }; + unsigned int b; + struct { + unsigned int c; + }; + }; +}; + +// C1X lookup-based anonymous member init cases +struct ds ds0 = { + { { + .a = 1 // expected-note{{previous initialization is here}} + } }, + .a = 2, // expected-warning{{initializer overrides prior initialization of this subobject}} + .b = 3 +}; +struct ds ds1 = { .c = 0 }; +struct ds ds2 = { { { + .a = 0, + .b = 1 // expected-error{{field designator 'b' does not refer to any field}} +} } }; diff --git a/test/Sema/dllimport-dllexport.c b/test/Sema/dllimport-dllexport.c index eea2f6fe9637..f09e3cf69ab5 100644 --- a/test/Sema/dllimport-dllexport.c +++ b/test/Sema/dllimport-dllexport.c @@ -10,9 +10,9 @@ void __attribute__((dllimport, dllexport)) foo4(); // expected-warning{{dllimpor void __attribute__((dllexport)) foo5(); void __attribute__((dllimport)) foo5(); // expected-warning{{dllimport attribute ignored}} -typedef int __attribute__((dllexport)) type6; // expected-warning{{'dllexport' attribute only applies to variable and function types}} +typedef int __attribute__((dllexport)) type6; // expected-warning{{'dllexport' attribute only applies to variables and functions}} -typedef int __attribute__((dllimport)) type7; // expected-warning{{'dllimport' attribute only applies to variable and function}} +typedef int __attribute__((dllimport)) type7; // expected-warning{{'dllimport' attribute only applies to variables and functions}} void __attribute__((dllimport)) foo6(); void foo6(){} // expected-warning {{'foo6' redeclared without dllimport attribute: previous dllimport ignored}} @@ -28,9 +28,9 @@ void __declspec(dllimport) __declspec(dllexport) foo10(); // expected-warning{{d void __declspec(dllexport) foo11(); void __declspec(dllimport) foo11(); // expected-warning{{dllimport attribute ignored}} -typedef int __declspec(dllexport) type1; // expected-warning{{'dllexport' attribute only applies to variable and function types}} +typedef int __declspec(dllexport) type1; // expected-warning{{'dllexport' attribute only applies to variables and functions}} -typedef int __declspec(dllimport) type2; // expected-warning{{'dllimport' attribute only applies to variable and function}} +typedef int __declspec(dllimport) type2; // expected-warning{{'dllimport' attribute only applies to variables and functions}} void __declspec(dllimport) foo12(); void foo12(){} // expected-warning {{'foo12' redeclared without dllimport attribute: previous dllimport ignored}} diff --git a/test/Sema/enum.c b/test/Sema/enum.c index 64aa31bc4b6f..a95efb035db1 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -102,3 +102,18 @@ extern enum PR7911T PR7911V; // expected-warning{{ISO C forbids forward referenc void PR7911F() { switch (PR7911V); // expected-error {{statement requires expression of integer type}} } + +char test5[__has_feature(enumerator_attributes) ? 1 : -1]; + +// PR8694 +// rdar://8707031 +void PR8694(int* e) // expected-note {{passing argument to parameter 'e' here}} +{ +} + +void crash(enum E* e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \ + // expected-warning {{ISO C forbids forward references to 'enum' types}} +{ + PR8694(e); // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}} +} + diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c index 56a52bed1bc3..e88f7fc08bce 100644 --- a/test/Sema/exprs.c +++ b/test/Sema/exprs.c @@ -150,3 +150,19 @@ int test20(int x) { // no warning, this is an idiom for "true" in old C style. return x && (signed char)1; } + +struct Test21; // expected-note 2 {{forward declaration}} +void test21(volatile struct Test21 *ptr) { + void test21_help(void); + (test21_help(), *ptr); // expected-error {{incomplete type 'struct Test21' where a complete type is required}} + (*ptr, test21_help()); // expected-error {{incomplete type 'struct Test21' where a complete type is required}} +} + +// Make sure we do function/array decay. +void test22() { + if ("help") + (void) 0; + + if (test22) + (void) 0; +} diff --git a/test/Sema/flexible-array-init.c b/test/Sema/flexible-array-init.c index e03881cdbcbe..12f5d4f5d605 100644 --- a/test/Sema/flexible-array-init.c +++ b/test/Sema/flexible-array-init.c @@ -1,13 +1,20 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s struct one { int a; - int values[]; // expected-note 3{{initialized flexible array member 'values' is here}} + int values[]; // expected-note 4{{initialized flexible array member 'values' is here}} } x = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}} void test() { - struct one x3 = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} + struct one x3 = {5, {1, 2, 3}}; // \ + // expected-warning{{flexible array initialization is a GNU extension}} \ + // expected-error {{non-static initialization of a variable with flexible array member}} + struct one x3a = { 5 }; + struct one x3b = { .a = 5 }; + struct one x3c = { 5, {} }; // expected-warning{{use of GNU empty initializer extension}} \ + // expected-warning{{flexible array initialization is a GNU extension}} \ + // expected-warning{{zero size arrays are an extension}} } struct foo { @@ -56,3 +63,18 @@ struct Y { int e; struct X xs[]; // expected-warning{{'struct X' may not be used as an array element due to flexible array member}} }; + + +// PR8217 +struct PR8217a { + int i; + char v[]; +}; + +void PR8217() { + struct PR8217a foo1 = { .i = 0, .v = "foo" }; // expected-error {{non-static initialization of a variable with flexible array member}} + struct PR8217a foo2 = { .i = 0 }; + struct PR8217a foo3 = { .i = 0, .v = { 'b', 'a', 'r', '\0' } }; // expected-error {{non-static initialization of a variable with flexible array member}} + struct PR8217a bar; +} + diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 2325454c0b75..be506d7c6b19 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -174,7 +174,16 @@ void test10(int x, float f, int i, long long lli) { printf("%.0Lf", (long double) 1.0); // no-warning printf("%c\n", "x"); // expected-warning{{conversion specifies type 'int' but the argument has type 'char *'}} printf("%c\n", 1.23); // expected-warning{{conversion specifies type 'int' but the argument has type 'double'}} -} + printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid conversion specifier '!'}} +} + +typedef unsigned char uint8_t; + +void should_understand_small_integers() { + printf("%hhu", (short) 10); // expected-warning{{conversion specifies type 'unsigned char' but the argument has type 'short'}} + printf("%hu\n", (unsigned char) 1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'unsigned char'}} + printf("%hu\n", (uint8_t)1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'uint8_t'}} +} void test11(void *p, char *s) { printf("%p", p); // no-warning @@ -301,3 +310,33 @@ void pr7981(wint_t c, wchar_t c2) { printf("%lc", c2); // no-warning } +// <rdar://problem/8269537> -Wformat-security says NULL is not a string literal +void rdar8269537() { + // This is likely to crash in most cases, but -Wformat-nonliteral technically + // doesn't warn in this case. + printf(0); // no-warning +} + +// Handle functions with multiple format attributes. +extern void rdar8332221_vprintf_scanf(const char *, va_list, const char *, ...) + __attribute__((__format__(__printf__, 1, 0))) + __attribute__((__format__(__scanf__, 3, 4))); + +void rdar8332221(va_list ap, int *x, long *y) { + rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}} +} + +// PR8641 +void pr8641() { + printf("%#x\n", 10); + printf("%#X\n", 10); +} + +void posix_extensions() { + // Test %'d, "thousands grouping". + // <rdar://problem/8816343> + printf("%'d\n", 123456789); // no-warning + printf("%'i\n", 123456789); // no-warning + printf("%'f\n", (float) 1.0); // no-warning + printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}} +} diff --git a/test/Sema/i-c-e.c b/test/Sema/i-c-e.c index eb77bbe3b990..4c2962d4b21a 100644 --- a/test/Sema/i-c-e.c +++ b/test/Sema/i-c-e.c @@ -1,4 +1,4 @@ -// RUN: %clang %s -fsyntax-only -Xclang -verify -pedantic -fpascal-strings +// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings #include <stdint.h> #include <limits.h> @@ -9,6 +9,7 @@ int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{inc int expr; char w[__builtin_constant_p(expr) ? expr : 1]; +char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1]; // __builtin_constant_p as the condition of ?: allows arbitrary foldable // constants to be transmogrified into i-c-e's. diff --git a/test/Sema/if-empty-body.c b/test/Sema/if-empty-body.c deleted file mode 100644 index af1e62f6b1b6..000000000000 --- a/test/Sema/if-empty-body.c +++ /dev/null @@ -1,16 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s - -void f1(int a) { - if (a); // expected-warning {{if statement has empty body}} -} - -void f2(int a) { - if (a) {} -} - -void f3() { - if (1) - xx; // expected-error {{use of undeclared identifier}} - return; // no empty body warning. -} - diff --git a/test/Sema/implicit-builtin-decl.c b/test/Sema/implicit-builtin-decl.c index 3d920389a228..d80414d5fea0 100644 --- a/test/Sema/implicit-builtin-decl.c +++ b/test/Sema/implicit-builtin-decl.c @@ -18,11 +18,11 @@ void g(int malloc) { // okay: these aren't functions void h() { int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}} int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \ - // expected-note{{'strcpy' is a builtin with type 'char *(char *, char const *)'}} + // expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}} } void f2() { - fprintf(0, "foo"); // expected-error{{implicit declaration of 'fprintf' requires inclusion of the header <stdio.h>}} \ + fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \ expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}} } @@ -52,3 +52,6 @@ main(int argc, char *argv[]) } void snprintf() { } + +// PR8316 +void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}} diff --git a/test/Sema/init.c b/test/Sema/init.c index ac274a4ce227..f8110079d0eb 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only +// RUN: %clang_cc1 %s -verify -fsyntax-only -ffreestanding #include <stddef.h> #include <stdint.h> @@ -143,3 +143,4 @@ 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/knr-def-call.c b/test/Sema/knr-def-call.c index 66f2ec07f287..d054a0476505 100644 --- a/test/Sema/knr-def-call.c +++ b/test/Sema/knr-def-call.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -Wconversion -Wliteral-conversion -fsyntax-only -verify %s // C DR #316, PR 3626. void f0(a, b, c, d) int a,b,c,d; {} @@ -23,7 +23,19 @@ void f4() { } char *rindex(s, c) - register char *s, c; // expected-warning{{promoted type 'char *' of K&R function parameter is not compatible with the parameter type 'char const *' declared in a previous prototype}} + register char *s, c; // expected-warning{{promoted type 'char *' of K&R function parameter is not compatible with the parameter type 'const char *' declared in a previous prototype}} { return 0; } + +// PR8314 +void proto(int); +void proto(x) + int x; +{ +} + +void use_proto() { + proto(42.0); // expected-warning{{implicit conversion turns literal floating-point number into integer}} + (&proto)(42.0); // expected-warning{{implicit conversion turns literal floating-point number into integer}} +} diff --git a/test/Sema/neon-vector-types.c b/test/Sema/neon-vector-types.c new file mode 100644 index 000000000000..1f501776cc8e --- /dev/null +++ b/test/Sema/neon-vector-types.c @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify + +typedef float float32_t; +typedef signed char poly8_t; +typedef short poly16_t; +typedef unsigned long long uint64_t; + +// Define some valid Neon types. +typedef __attribute__((neon_vector_type(2))) int int32x2_t; +typedef __attribute__((neon_vector_type(4))) int int32x4_t; +typedef __attribute__((neon_vector_type(1))) uint64_t uint64x1_t; +typedef __attribute__((neon_vector_type(2))) uint64_t uint64x2_t; +typedef __attribute__((neon_vector_type(2))) float32_t float32x2_t; +typedef __attribute__((neon_vector_type(4))) float32_t float32x4_t; +typedef __attribute__((neon_polyvector_type(16))) poly8_t poly8x16_t; +typedef __attribute__((neon_polyvector_type(8))) poly16_t poly16x8_t; + +// The attributes must have a single argument. +typedef __attribute__((neon_vector_type(2, 4))) int only_one_arg; // expected-error{{attribute requires 1 argument(s)}} + +// The number of elements must be an ICE. +typedef __attribute__((neon_vector_type(2.0))) int non_int_width; // expected-error{{attribute requires integer constant}} + +// Only certain element types are allowed. +typedef __attribute__((neon_vector_type(2))) double double_elt; // expected-error{{invalid vector element type}} +typedef __attribute__((neon_vector_type(4))) void* ptr_elt; // expected-error{{invalid vector element type}} +typedef __attribute__((neon_polyvector_type(4))) float32_t bad_poly_elt; // expected-error{{invalid vector element type}} +struct aggr { signed char c; }; +typedef __attribute__((neon_vector_type(8))) struct aggr aggregate_elt; // expected-error{{invalid vector element type}} + +// The total vector size must be 64 or 128 bits. +typedef __attribute__((neon_vector_type(1))) int int32x1_t; // expected-error{{Neon vector size must be 64 or 128 bits}} +typedef __attribute__((neon_vector_type(3))) int int32x3_t; // expected-error{{Neon vector size must be 64 or 128 bits}} diff --git a/test/Sema/opencl-init.c b/test/Sema/opencl-init.c deleted file mode 100644 index 3d116bd0dae6..000000000000 --- a/test/Sema/opencl-init.c +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clang_cc1 %s -x cl -verify -pedantic -fsyntax-only - -typedef float float8 __attribute((ext_vector_type(8))); - -typedef float float32_t; -typedef __attribute__(( __vector_size__(16) )) float32_t __neon_float32x4_t; -typedef struct __simd128_float32_t { - __neon_float32x4_t val; -} float32x4_t; - -float8 foo(float8 x) { - float32x4_t lo; - float32x4_t hi; - return (float8) (lo.val, hi.val); -} diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c index e53f0eb99bc1..6d6fa1d4bd42 100644 --- a/test/Sema/parentheses.c +++ b/test/Sema/parentheses.c @@ -25,4 +25,15 @@ void bitwise_rel(unsigned i) { // Eager logical op (void)(i == 1 | i == 2 | i == 3); (void)(i != 1 & i != 2 & i != 3); + + (void)(i || i && i); // expected-warning {{'&&' within '||'}} \ + // expected-note {{place parentheses around the '&&' expression to silence this warning}} + (void)(i || i && "w00t"); // no warning. + (void)("w00t" && i || i); // no warning. + (void)(i || i && "w00t" || i); // expected-warning {{'&&' within '||'}} \ + // expected-note {{place parentheses around the '&&' expression to silence this warning}} + (void)(i || "w00t" && i || i); // expected-warning {{'&&' within '||'}} \ + // expected-note {{place parentheses around the '&&' expression to silence this warning}} + (void)(i && i || 0); // no warning. + (void)(0 || i && i); // no warning. } diff --git a/test/Sema/pointer-addition.c b/test/Sema/pointer-addition.c index 34f8bbbfcd6d..aa425a7fd9d9 100644 --- a/test/Sema/pointer-addition.c +++ b/test/Sema/pointer-addition.c @@ -9,6 +9,7 @@ void a(S* b, void* c) { c += 1; // expected-warning {{use of GNU void* extension}} c--; // expected-warning {{use of GNU void* extension}} c -= 1; // expected-warning {{use of GNU void* extension}} + (void) c[1]; // expected-warning {{use of GNU void* extension}} b = 1+b; // expected-error {{arithmetic on pointer to incomplete type}} /* The next couple tests are only pedantic warnings in gcc */ void (*d)(S*,void*) = a; diff --git a/test/Sema/pragma-unused.c b/test/Sema/pragma-unused.c index 8a051a3ec9ef..aafac0de206d 100644 --- a/test/Sema/pragma-unused.c +++ b/test/Sema/pragma-unused.c @@ -1,16 +1,16 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -Wused-but-marked-unused -Wunused -verify %s void f1(void) { int x, y, z; #pragma unused(x) #pragma unused(y, z) - int w; // FIXME: We should emit a warning that 'w' is unused. + int w; // expected-warning {{unused}} #pragma unused w // expected-warning{{missing '(' after '#pragma unused' - ignoring}} } void f2(void) { - int x, y; + int x, y; // expected-warning {{unused}} expected-warning {{unused}} #pragma unused(x,) // expected-warning{{expected '#pragma unused' argument to be a variable name}} #pragma unused() // expected-warning{{expected '#pragma unused' argument to be a variable name}} } @@ -20,15 +20,10 @@ void f3(void) { } void f4(void) { - int w; // FIXME: We should emit a warning that 'w' is unused. + int w; // expected-warning {{unused}} #pragma unused((w)) // expected-warning{{expected '#pragma unused' argument to be a variable name}} } -int k; -void f5(void) { - #pragma unused(k) // expected-warning{{only local variables can be arguments to '#pragma unused'}} -} - void f6(void) { int z; // no-warning { @@ -41,3 +36,30 @@ void f7() { #pragma unused(undeclared, undefined, y) // expected-warning{{undeclared variable 'undeclared' used as an argument for '#pragma unused'}} expected-warning{{undeclared variable 'undefined' used as an argument for '#pragma unused'}} } +int f8(int x) { // expected-warning{{unused parameter 'x'}} + return 0; +} + +int f9(int x) { + return x; +} + +int f10(int x) { + #pragma unused(x) + return 0; +} + +int f11(int x) { + #pragma unused(x) + return x; // expected-warning{{'x' was marked unused but was used}} +} + +int f12(int x) { + int y = x; + #pragma unused(x) // expected-warning{{'x' was marked unused but was used}} + return y; +} + +// rdar://8793832 +static int glob_var = 0; +#pragma unused(glob_var) diff --git a/test/Sema/predef.c b/test/Sema/predef.c index 08a4a2bf83e9..95bcfb9d8d51 100644 --- a/test/Sema/predef.c +++ b/test/Sema/predef.c @@ -6,7 +6,7 @@ void abcdefghi12(void) { } char *X = __func__; // expected-warning {{predefined identifier is only valid}} \ - expected-warning {{initializing 'char *' with an expression of type 'char const [1]' discards qualifiers}} + expected-warning {{initializing 'char *' with an expression of type 'const char [1]' discards qualifiers}} void a() { __func__[0] = 'a'; // expected-error {{variable is not assignable}} diff --git a/test/Sema/private-extern.c b/test/Sema/private-extern.c index d3c12651098a..25591dc5b1f2 100644 --- a/test/Sema/private-extern.c +++ b/test/Sema/private-extern.c @@ -19,27 +19,23 @@ __private_extern__ int g5; // expected-note{{previous definition}} static int g5; // expected-error{{static declaration of 'g5' follows non-static declaration}} void f0() { - // FIXME: Diagnose this? - int g6; - extern int g6; + int g6; // expected-note {{previous}} + extern int g6; // expected-error {{extern declaration of 'g6' follows non-extern declaration}} } void f1() { - // FIXME: Diagnose this? - int g7; - __private_extern__ int g7; + int g7; // expected-note {{previous}} + __private_extern__ int g7; // expected-error {{extern declaration of 'g7' follows non-extern declaration}} } void f2() { extern int g8; // expected-note{{previous definition}} - // FIXME: Improve this diagnostic. - int g8; // expected-error{{redefinition of 'g8'}} + int g8; // expected-error {{non-extern declaration of 'g8' follows extern declaration}} } void f3() { __private_extern__ int g9; // expected-note{{previous definition}} - // FIXME: Improve this diagnostic. - int g9; // expected-error{{redefinition of 'g9'}} + int g9; // expected-error {{non-extern declaration of 'g9' follows extern declaration}} } void f4() { diff --git a/test/Sema/promote-int-16bit.c b/test/Sema/promote-int-16bit.c deleted file mode 100644 index 6446720a815e..000000000000 --- a/test/Sema/promote-int-16bit.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -triple pic16-unknown-unknown - -// Check that unsigned short promotes to unsigned int on targets where -// sizeof(unsigned short) == sizeof(unsigned int) -__typeof(1+(unsigned short)1) x; -unsigned x; diff --git a/test/Sema/rdr6094103-unordered-compare-promote.c b/test/Sema/rdr6094103-unordered-compare-promote.c index 9991982a20b2..7bb363e797c8 100644 --- a/test/Sema/rdr6094103-unordered-compare-promote.c +++ b/test/Sema/rdr6094103-unordered-compare-promote.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -ast-dump %s 2>&1 | grep ImplicitCastExpr | count 2 +// RUN: %clang_cc1 -ast-dump %s 2>&1 | grep ImplicitCastExpr | count 4 int foo (double x, long double y) { // There needs to be an implicit cast on x here. diff --git a/test/Sema/redefinition.c b/test/Sema/redefinition.c index 1092b33ca35d..1ee35f7c36ee 100644 --- a/test/Sema/redefinition.c +++ b/test/Sema/redefinition.c @@ -8,3 +8,7 @@ int foo(x) { return 0; } int x = 1; + +// <rdar://problem/6880464> +extern inline int g(void) { return 0; } // expected-note{{previous definition}} +int g(void) { return 0; } // expected-error{{redefinition of a 'extern inline' function 'g' is not supported in C99 mode}} diff --git a/test/Sema/return.c b/test/Sema/return.c index 54c340634d39..0c2c72ee537f 100644 --- a/test/Sema/return.c +++ b/test/Sema/return.c @@ -203,7 +203,7 @@ int test30() { if (j) longjmp(test30_j, 1); else -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) longjmp(test30_j, 2); #else _longjmp(test30_j, 1); @@ -242,3 +242,16 @@ 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}} + +// Test that for switch(enum) that if the switch statement covers all the cases +// that we don't consider that for -Wreturn-type. +enum Cases { C1, C2, C3, C4 }; +int test_enum_cases(enum Cases C) { + switch (C) { + case C1: return 1; + case C2: return 2; + case C4: return 3; + case C3: return 4; + } +} // no-warning + diff --git a/test/Sema/scope-check.c b/test/Sema/scope-check.c index 4ccb64c9aa07..a9494d3e3fb4 100644 --- a/test/Sema/scope-check.c +++ b/test/Sema/scope-check.c @@ -133,7 +133,7 @@ int test8(int x) { void test9(int n, void *P) { int Y; int Z = 4; - goto *P; // expected-warning {{indirect goto might cross protected scopes}} + goto *P; // expected-error {{indirect goto might cross protected scopes}} L2: ; int a[n]; // expected-note {{jump bypasses initialization of variable length array}} @@ -199,3 +199,36 @@ void test13(int n, void *p) { a0: ; static void *ps[] = { &&a0 }; } + +int test14(int n) { + static void *ps[] = { &&a0, &&a1 }; + if (n < 0) + goto *&&a0; + + if (n > 0) { + int vla[n]; + a1: + vla[n-1] = 0; + } + a0: + return 0; +} + + +// PR8473: IR gen can't deal with indirect gotos past VLA +// initialization, so that really needs to be a hard error. +void test15(int n, void *pc) { + static const void *addrs[] = { &&L1, &&L2 }; + + goto *pc; // expected-error {{indirect goto might cross protected scope}} + + L1: + { + char vla[n]; // expected-note {{jump bypasses initialization}} + L2: // expected-note {{possible target}} + vla[0] = 'a'; + } +} + +// rdar://9024687 +int test16(int [sizeof &&z]); // expected-error {{use of address-of-label extension outside of a function body}} diff --git a/test/Sema/self-comparison.c b/test/Sema/self-comparison.c index c5c0611e7c94..edb3a6a4c8a5 100644 --- a/test/Sema/self-comparison.c +++ b/test/Sema/self-comparison.c @@ -75,3 +75,14 @@ int array_comparisons() { } +// Don't issue a warning when either the left or right side of the comparison +// results from a macro expansion. <rdar://problem/8435950> +#define R8435950_A i +#define R8435950_B i + +int R8435950(int i) { + if (R8435950_A == R8435950_B) // no-warning + return 0; + return 1; +} + diff --git a/test/Sema/sentinel-attribute.c b/test/Sema/sentinel-attribute.c index 4c0927396763..ed0ef89db70b 100644 --- a/test/Sema/sentinel-attribute.c +++ b/test/Sema/sentinel-attribute.c @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -int x __attribute__((sentinel)); //expected-warning{{'sentinel' attribute only applies to function, method or block types}} +int x __attribute__((sentinel)); //expected-warning{{'sentinel' attribute only applies to functions, methods and blocks}} void f1(int a, ...) __attribute__ ((sentinel)); void f2(int a, ...) __attribute__ ((sentinel(1))); diff --git a/test/Sema/shift.c b/test/Sema/shift.c index 558a7d20065a..4273cab98ee3 100644 --- a/test/Sema/shift.c +++ b/test/Sema/shift.c @@ -1,4 +1,4 @@ -// RUN: %clang -Wall -fsyntax-only -Xclang -verify %s +// RUN: %clang -Wall -ffreestanding -fsyntax-only -Xclang -verify %s #include <limits.h> diff --git a/test/Sema/short-enums.c b/test/Sema/short-enums.c new file mode 100644 index 000000000000..6605c4e8fc07 --- /dev/null +++ b/test/Sema/short-enums.c @@ -0,0 +1,5 @@ +// RUN: not %clang_cc1 -fsyntax-only %s -verify +// RUN: %clang_cc1 -fshort-enums -fsyntax-only %s -verify + +enum x { A }; +int t0[sizeof(enum x) == 1 ? 1 : -1]; diff --git a/test/Sema/statements.c b/test/Sema/statements.c index e3c41f3e1aaf..963b98fe56ad 100644 --- a/test/Sema/statements.c +++ b/test/Sema/statements.c @@ -50,4 +50,53 @@ int test12(enum Numbers num) { case kThree: break; } -}
\ No newline at end of file +} + + +enum x { a, b, c, d, e, f, g }; + +void foo(enum x X) { + switch (X) { // expected-warning {{enumeration value 'g' not handled in switch}} + case a: + case b: + case c: + case d: + case e: + case f: + break; + } + + switch (X) { // expected-warning {{enumeration values 'f' and 'g' not handled in switch}} + case a: + case b: + case c: + case d: + case e: + break; + } + + switch (X) { // expected-warning {{enumeration values 'e', 'f', and 'g' not handled in switch}} + case a: + case b: + case c: + case d: + break; + } + + switch (X) { // expected-warning {{5 enumeration values not handled in switch: 'c', 'd', 'e'...}} + case a: + case b: + break; + } +} + +// PR 8880 +// FIXME: Clang should reject this, since GCC does. Previously this +// was causing a crash in the CFG builder. +int test_pr8880() { + int first = 1; + for ( ; ({ if (first) { first = 0; continue; } 0; }); ) + return 0; + return 1; +} + diff --git a/test/Sema/stdcall-fastcall.c b/test/Sema/stdcall-fastcall.c index a06952647984..4531eb2a81c8 100644 --- a/test/Sema/stdcall-fastcall.c +++ b/test/Sema/stdcall-fastcall.c @@ -5,6 +5,16 @@ int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies t int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' only applies to function types; type here is 'int'}} // Different CC qualifiers are not compatible -void __attribute__((stdcall, fastcall)) foo3(void); // expected-error{{stdcall and fastcall attributes are not compatible}} +void __attribute__((stdcall, fastcall)) foo3(void); // expected-error{{fastcall and stdcall attributes are not compatible}} void __attribute__((stdcall)) foo4(); // expected-note{{previous declaration is here}} void __attribute__((fastcall)) foo4(void); // expected-error{{function declared 'fastcall' here was previously declared 'stdcall'}} + +// rdar://8876096 +void rdar8876096foo1(int i, int j) __attribute__((fastcall, cdecl)); // expected-error {{not compatible}} +void rdar8876096foo2(int i, int j) __attribute__((fastcall, stdcall)); // expected-error {{not compatible}} +void rdar8876096foo3(int i, int j) __attribute__((fastcall, regparm(2))); // expected-error {{not compatible}} +void rdar8876096foo4(int i, int j) __attribute__((stdcall, cdecl)); // expected-error {{not compatible}} +void rdar8876096foo5(int i, int j) __attribute__((stdcall, fastcall)); // expected-error {{not compatible}} +void rdar8876096foo6(int i, int j) __attribute__((cdecl, fastcall)); // expected-error {{not compatible}} +void rdar8876096foo7(int i, int j) __attribute__((cdecl, stdcall)); // expected-error {{not compatible}} +void rdar8876096foo8(int i, int j) __attribute__((regparm(2), fastcall)); // expected-error {{not compatible}} diff --git a/test/Sema/struct-packed-align.c b/test/Sema/struct-packed-align.c index 2b9456703c72..6ca6a6096c4e 100644 --- a/test/Sema/struct-packed-align.c +++ b/test/Sema/struct-packed-align.c @@ -117,3 +117,18 @@ struct packed_fas2 { extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1]; extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1]; + +// Attribute aligned can round down typedefs. PR9253 +typedef long long __attribute__((aligned(1))) nt; + +struct nS { + char buf_nr; + nt start_lba; +}; + +extern int n1[sizeof(struct nS) == 9 ? 1 : -1]; +extern int n2[__alignof(struct nS) == 1 ? 1 : -1]; + + + + diff --git a/test/Sema/switch.c b/test/Sema/switch.c index bb4822916cc7..96a6eb6e9632 100644 --- a/test/Sema/switch.c +++ b/test/Sema/switch.c @@ -77,7 +77,7 @@ void test6() { } // PR5606 -int f0(int var) { // expected-note{{'var' declared here}} +int f0(int var) { switch (va) { // expected-error{{use of undeclared identifier 'va'}} case 1: break; diff --git a/test/Sema/transparent-union.c b/test/Sema/transparent-union.c index 27d5c2403b43..ab1ba1867f47 100644 --- a/test/Sema/transparent-union.c +++ b/test/Sema/transparent-union.c @@ -2,6 +2,8 @@ typedef union { int *ip; float *fp; + long *__restrict rlp; + void *vpa[1]; } TU __attribute__((transparent_union)); void f(TU); // expected-note{{passing argument to parameter here}} @@ -17,6 +19,30 @@ void g(int *ip, float *fp, char *cp) { tu.ip = ip; } +/* Test ability to redeclare a function taking a transparent_union arg + with various compatible and incompatible argument types. */ + +void fip(TU); +void fip(int *i) {} + +void ffp(TU); +void ffp(float *f) {} + +void flp(TU); +void flp(long *l) {} + +void fvp(TU); // expected-note{{previous declaration is here}} +void fvp(void *p) {} // expected-error{{conflicting types}} + +void fsp(TU); // expected-note{{previous declaration is here}} +void fsp(short *s) {} // expected-error{{conflicting types}} + +void fi(TU); // expected-note{{previous declaration is here}} +void fi(int i) {} // expected-error{{conflicting types}} + +void fvpp(TU); // expected-note{{previous declaration is here}} +void fvpp(void **v) {} // expected-error{{conflicting types}} + /* FIXME: we'd like to just use an "int" here and align it differently from the normal "int", but if we do so we lose the alignment information from the typedef within the compiler. */ diff --git a/test/Sema/typedef-retain.c b/test/Sema/typedef-retain.c index 5b963c48b2cc..a7173b787791 100644 --- a/test/Sema/typedef-retain.c +++ b/test/Sema/typedef-retain.c @@ -24,15 +24,3 @@ int test4(const a y) { y[0] = 10; // expected-error {{read-only variable is not assignable}} } -// PR2189 -int test5() { - const int s[5]; int t[5]; - return &s == &t; // expected-warning {{comparison of distinct pointer types}} -} - -int test6() { - const a s; - a t; - return &s == &t; // expected-warning {{comparison of distinct pointer types}} -} - diff --git a/test/Sema/typeof-use-deprecated.c b/test/Sema/typeof-use-deprecated.c new file mode 100644 index 000000000000..238e5019f121 --- /dev/null +++ b/test/Sema/typeof-use-deprecated.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only + +struct s { int a; } __attribute__((deprecated)) x; // expected-warning {{'s' is deprecated}} + +typeof(x) y; // expected-warning {{'s' is deprecated}} + +union un{ int a; } __attribute__((deprecated)) u; // expected-warning {{'un' is deprecated}} + +typeof( u) z; // expected-warning {{'un' is deprecated}} + +enum E{ one} __attribute__((deprecated)) e; // expected-warning {{'E' is deprecated}} + +typeof( e) w; // expected-warning {{'E' is deprecated}} + +struct foo { int x; } __attribute__((deprecated)); +typedef struct foo bar __attribute__((deprecated)); +bar x1; // expected-warning {{'bar' is deprecated}} + +int main() { typeof(x1) y; } // expected-warning {{'foo' is deprecated}} + +struct gorf { int x; }; +typedef struct gorf T __attribute__((deprecated)); +T t; // expected-warning {{'T' is deprecated}} +void wee() { typeof(t) y; } + + diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c new file mode 100644 index 000000000000..973e504f634d --- /dev/null +++ b/test/Sema/uninit-variables.c @@ -0,0 +1,262 @@ +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only -fblocks %s -verify + +int test1() { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +int test2() { + int x = 0; + return x; // no-warning +} + +int test3() { + int x; + x = 0; + return x; // no-warning +} + +int test4() { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + ++x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} + return x; +} + +int test5() { + int x, y; // expected-note{{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + x = y; // expected-warning{{variable 'y' is possibly uninitialized when used here}} + return x; +} + +int test6() { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + x += 2; // expected-warning{{variable 'x' is possibly uninitialized when used here}} + return x; +} + +int test7(int y) { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + if (y) + x = 1; + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +int test8(int y) { + int x; + if (y) + x = 1; + else + x = 0; + return x; +} + +int test9(int n) { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + for (unsigned i = 0 ; i < n; ++i) { + if (i == n - 1) + break; + x = 1; + } + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +int test10(unsigned n) { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + for (unsigned i = 0 ; i < n; ++i) { + x = 1; + } + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +int test11(unsigned n) { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + for (unsigned i = 0 ; i <= n; ++i) { + x = 1; + } + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +void test12(unsigned n) { + for (unsigned i ; n ; ++i) ; // expected-warning{{variable 'i' is possibly uninitialized when used here}} expected-note{{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}} +} + +int test13() { + static int i; + return i; // no-warning +} + +// Simply don't crash on this test case. +void test14() { + const char *p = 0; + for (;;) {} +} + +void test15() { + int x = x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} +} + +// Don't warn in the following example; shows dataflow confluence. +char *test16_aux(); +void test16() { + char *p = test16_aux(); + for (unsigned i = 0 ; i < 100 ; i++) + p[i] = 'a'; // no-warning +} + +void test17() { + // Don't warn multiple times about the same uninitialized variable + // along the same path. + int *x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + *x = 1; // expected-warning{{variable 'x' is possibly uninitialized when used here}} + *x = 1; // no-warning +} + +int test18(int x, int y) { + int z; + if (x && y && (z = 1)) { + return z; // no-warning + } + return 0; +} + +int test19_aux1(); +int test19_aux2(); +int test19_aux3(int *x); +int test19() { + int z; + if (test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z)) + return z; // no-warning + return 0; +} + +int test20() { + int z; // expected-note{{variable 'z' is declared here}} expected-note{{add initialization to silence this warning}} + if ((test19_aux1() + test19_aux2() && test19_aux1()) || test19_aux3(&z)) + return z; // expected-warning{{variable 'z' is possibly uninitialized when used here}} + return 0; +} + +int test21(int x, int y) { + int z; // expected-note{{variable 'z' is declared here}} expected-note{{add initialization to silence this warning}} + if ((x && y) || test19_aux3(&z) || test19_aux2()) + return z; // expected-warning{{variable 'z' is possibly uninitialized when used here}} + return 0; +} + +int test22() { + int z; + while (test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z)) + return z; // no-warning + return 0; +} + +int test23() { + int z; + for ( ; test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z) ; ) + return z; // no-warning + return 0; +} + +// The basic uninitialized value analysis doesn't have enough path-sensitivity +// to catch initializations relying on control-dependencies spanning multiple +// conditionals. This possibly can be handled by making the CFG itself +// represent such control-dependencies, but it is a niche case. +int test24(int flag) { + unsigned val; // expected-note{{variable 'val' is declared here}} expected-note{{add initialization to silence this warning}} + if (flag) + val = 1; + if (!flag) + val = 1; + return val; // expected-warning{{variable 'val' is possibly uninitialized when used here}} +} + +float test25() { + float x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +typedef int MyInt; +MyInt test26() { + MyInt x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +// Test handling of sizeof(). +int test27() { + struct test_27 { int x; } *y; + return sizeof(y->x); // no-warning +} + +int test28() { + int len; // expected-note{{variable 'len' is declared here}} expected-note{{add initialization to silence this warning}} + return sizeof(int[len]); // expected-warning{{variable 'len' is possibly uninitialized when used here}} +} + +void test29() { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + (void) ^{ (void) x; }; // expected-warning{{variable 'x' is possibly uninitialized when captured by block}} +} + +void test30() { + static int x; // no-warning + (void) ^{ (void) x; }; +} + +void test31() { + __block int x; // no-warning + (void) ^{ (void) x; }; +} + +int test32_x; +void test32() { + (void) ^{ (void) test32_x; }; // no-warning +} + +void test_33() { + int x; // no-warning + (void) x; +} + +int test_34() { + int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + (void) x; + return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} +} + +// Test that this case doesn't crash. +void test35(int x) { + __block int y = 0; + ^{ y = (x == 0); }(); +} + +// Test handling of indirect goto. +void test36() +{ + void **pc; // expected-note{{variable 'pc' is declared here}} expected-note{{add initialization to silence this warning}} + void *dummy[] = { &&L1, &&L2 }; + L1: + goto *pc; // expected-warning{{variable 'pc' is possibly uninitialized when used here}} + L2: + goto *pc; +} + +// Test && nested in ||. +int test37_a(); +int test37_b(); +int test37() +{ + int identifier; + if ((test37_a() && (identifier = 1)) || + (test37_b() && (identifier = 2))) { + return identifier; // no-warning + } + return 0; +} + +// Test merging of path-specific dataflow values (without asserting). +int test38(int r, int x, int y) +{ + int z; + return ((r < 0) || ((r == 0) && (x < y))); +} + diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c index 15608ec8a4be..9949887b23e7 100644 --- a/test/Sema/unused-expr.c +++ b/test/Sema/unused-expr.c @@ -95,7 +95,7 @@ int t6() { return 0; } -int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to function types}} +int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to functions}} // PR4010 int (*fn4)(void) __attribute__ ((warn_unused_result)); @@ -118,3 +118,6 @@ void f(int i, ...) { __builtin_va_arg(ap, int); __builtin_va_end(ap); } + +// PR8371 +int fn5() __attribute__ ((__const)); diff --git a/test/Sema/varargs-x86-64.c b/test/Sema/varargs-x86-64.c index 2cfedc1b37e7..2fe9b10cf78d 100644 --- a/test/Sema/varargs-x86-64.c +++ b/test/Sema/varargs-x86-64.c @@ -3,6 +3,6 @@ // rdar://6726818 void f1() { const __builtin_va_list args2; - (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type '__builtin_va_list const' and not 'va_list'}} + (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type 'const __builtin_va_list' and not 'va_list'}} } diff --git a/test/Sema/vector-assign.c b/test/Sema/vector-assign.c index 05fc3b13db0c..8b0dc9288ee0 100644 --- a/test/Sema/vector-assign.c +++ b/test/Sema/vector-assign.c @@ -49,5 +49,5 @@ longlongvec; void test3a(longlongvec *); // expected-note{{passing argument to parameter here}} void test3(const unsigned *src) { - test3a(src); // expected-warning {{incompatible pointer types passing 'unsigned int const *' to parameter of type 'longlongvec *'}} + test3a(src); // expected-warning {{incompatible pointer types passing 'const unsigned int *' to parameter of type 'longlongvec *'}} } diff --git a/test/Sema/vector-init.c b/test/Sema/vector-init.c index 8f81adc05ba3..5be040ae6c11 100644 --- a/test/Sema/vector-init.c +++ b/test/Sema/vector-init.c @@ -33,3 +33,12 @@ __attribute__((vector_size(16))) float f2( typedef float __attribute__((ext_vector_type (3))) float3; int test2[sizeof(float3) == sizeof(float4) ? 1 : -1]; +// rdar://problem/8345836 +typedef long long __attribute__((vector_size(16))) longlong2; +typedef short __attribute__((vector_size(16))) short8; +typedef short __attribute__((vector_size(8))) short4; +void test3() { + extern short8 test3_helper(void); + longlong2 arr1[2] = { test3_helper(), test3_helper() }; + short4 arr2[2] = { test3_helper(), test3_helper() }; // expected-error 2 {{initializing 'short4' with an expression of incompatible type 'short8'}} +} diff --git a/test/Sema/warn-shadow.c b/test/Sema/warn-shadow.c index a112210c9693..32aca8d612b2 100644 --- a/test/Sema/warn-shadow.c +++ b/test/Sema/warn-shadow.c @@ -48,3 +48,14 @@ void test4(int i) { // expected-warning {{declaration shadows a variable in the void test5(int i); void test6(void (*f)(int i)) {} void test7(void *context, void (*callback)(void *context)) {} + +extern int bob; // expected-note {{previous declaration is here}} + +// rdar://8883302 +void rdar8883302() { + extern int bob; // don't warn for shadowing. +} + +void test8() { + int bob; // expected-warning {{declaration shadows a variable in the global scope}} +} diff --git a/test/Sema/warn-unreachable.c b/test/Sema/warn-unreachable.c index 10ed6961a556..20e0c3172401 100644 --- a/test/Sema/warn-unreachable.c +++ b/test/Sema/warn-unreachable.c @@ -35,8 +35,8 @@ void test2() { dead(); // expected-warning {{will never be executed}} case 3: - live() // expected-warning {{will never be executed}} - + + live() + + // expected-warning {{will never be executed}} halt(); dead(); @@ -75,8 +75,8 @@ void test2() { goto c6; case 7: halt() - + // expected-warning {{will never be executed}} - dead(); + + + dead(); // expected-warning {{will never be executed}} - // expected-warning {{will never be executed}} halt(); case 8: @@ -98,3 +98,19 @@ void test2() { } } } + +enum Cases { C1, C2, C3 }; +int test_enum_cases(enum Cases C) { + switch (C) { + case C1: + case C2: + case C3: + return 1; + default: { + int i = 0; // expected-warning{{will never be executed}} + ++i; + return i; + } + } +} + diff --git a/test/Sema/warn-unused-function.c b/test/Sema/warn-unused-function.c index 24d4fade9b31..5bbcf18a623d 100644 --- a/test/Sema/warn-unused-function.c +++ b/test/Sema/warn-unused-function.c @@ -47,3 +47,10 @@ static void f12(void); // PR7923 static void unused(void) { unused(); } // expected-warning{{unused}} + +// rdar://8728293 +static void cleanupMalloc(char * const * const allocation) { } +void f13(void) { + char * const __attribute__((cleanup(cleanupMalloc))) a; + (void)a; +} diff --git a/test/Sema/warn-unused-label.c b/test/Sema/warn-unused-label.c new file mode 100644 index 000000000000..48370a5fd641 --- /dev/null +++ b/test/Sema/warn-unused-label.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunused-label -verify %s + +void f() { + a: + goto a; + b: // expected-warning{{unused}} + c: __attribute__((unused)); + d: __attribute__((noreturn)); // expected-warning {{'noreturn' attribute only applies to functions}} + goto d; + return; +} diff --git a/test/Sema/warn-unused-value.c b/test/Sema/warn-unused-value.c index 1a7e745785b3..876eb9e4823e 100644 --- a/test/Sema/warn-unused-value.c +++ b/test/Sema/warn-unused-value.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -Wunused-label %s // RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s // RUN: %clang_cc1 -fsyntax-only -verify -Wall %s @@ -52,6 +52,9 @@ void pr4806() { volatile int* pj = &j; *pi; // expected-warning {{expression result unused}} *pj; + + foo_label: // expected-warning {{unused label}} + i; // expected-warning {{expression result unused}} } // Don't warn about unused '||', '&&' expressions that contain assignments. diff --git a/test/Sema/warn-write-strings.c b/test/Sema/warn-write-strings.c index c936a1267bf5..dd0bb8a6d83a 100644 --- a/test/Sema/warn-write-strings.c +++ b/test/Sema/warn-write-strings.c @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s // PR4804 -char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'char const [4]' discards qualifiers}} +char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'const char [4]' discards qualifiers}} // PR7192 #include <stddef.h> diff --git a/test/Sema/x86-attr-force-align-arg-pointer.c b/test/Sema/x86-attr-force-align-arg-pointer.c index b406a77e044c..5d36e9af195b 100644 --- a/test/Sema/x86-attr-force-align-arg-pointer.c +++ b/test/Sema/x86-attr-force-align-arg-pointer.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple i386-apple-darwin10 -fsyntax-only -verify %s -int a __attribute__((force_align_arg_pointer)); // expected-warning{{attribute only applies to function types}} +int a __attribute__((force_align_arg_pointer)); // expected-warning{{attribute only applies to functions}} // It doesn't matter where the attribute is located. void b(void) __attribute__((force_align_arg_pointer)); diff --git a/test/Sema/x86-builtin-palignr.c b/test/Sema/x86-builtin-palignr.c index eedf99bdfb6f..23443065a43e 100644 --- a/test/Sema/x86-builtin-palignr.c +++ b/test/Sema/x86-builtin-palignr.c @@ -1,10 +1,14 @@ -// RUN: %clang_cc1 -fsyntax-only -target-feature +ssse3 -verify %s -// Temporarily xfail this on windows. -// XFAIL: win32 +// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify %s #include <tmmintrin.h> -__m64 foo(__m64 a, __m64 b, int c) -{ +__m64 test1(__m64 a, __m64 b, int c) { return _mm_alignr_pi8(a, b, c); // expected-error {{argument to '__builtin_ia32_palignr' must be a constant integer}} } + +int test2(int N) { + __m128i white2; + white2 = __builtin_ia32_pslldqi128(white2, N); // expected-error {{argument to '__builtin_ia32_pslldqi128' must be a constant integer}} + return 0; +} + |