diff options
Diffstat (limited to 'test/Sema')
50 files changed, 669 insertions, 57 deletions
diff --git a/test/Sema/__try.c b/test/Sema/__try.c new file mode 100644 index 0000000000000..5490aea539edf --- /dev/null +++ b/test/Sema/__try.c @@ -0,0 +1,171 @@ +// RUN: %clang_cc1 -fborland-extensions -fsyntax-only -verify %s + +#define JOIN2(x,y) x ## y +#define JOIN(x,y) JOIN2(x,y) +#define TEST2(name) JOIN(name,__LINE__) +#define TEST TEST2(test) +typedef int DWORD; + +#pragma sysheader begin + +struct EXCEPTION_INFO{}; + +int __exception_code(); +struct EXCEPTION_INFO* __exception_info(); +void __abnormal_termination(); + +#define GetExceptionCode __exception_code +#define GetExceptionInformation __exception_info +#define AbnormalTermination __abnormal_termination + +#pragma sysheader end + +DWORD FilterExpression(int); +DWORD FilterExceptionInformation(struct EXCEPTION_INFO*); + +const char * NotFilterExpression(); + +void TEST() { + __try { + __try { + __try { + } + __finally{ + } + } + __finally{ + } + } + __finally{ + } +} + +void TEST() { + __try { + + } +} // expected-error{{expected '__except' or '__finally' block}} + +void TEST() { + __except ( FilterExpression() ) { // expected-error{{}} + + } +} + +void TEST() { + __finally { } // expected-error{{}} +} + +void TEST() { + __try{ + int try_scope = 0; + } // TODO: expected expression is an extra error + __except( try_scope ? 1 : -1 ) // expected-error{{undeclared identifier 'try_scope'}} expected-error{{expected expression}} + {} +} + +void TEST() { + __try { + + } + // TODO: Why are there two errors? + __except( ) { // expected-error{{expected expression}} expected-error{{expected expression}} + } +} + +void TEST() { + __try { + + } + __except ( FilterExpression(GetExceptionCode()) ) { + + } + + __try { + + } + __except( FilterExpression(__exception_code()) ) { + + } + + __try { + + } + __except( FilterExceptionInformation(__exception_info()) ) { + + } + + __try { + + } + __except(FilterExceptionInformation( GetExceptionInformation() ) ) { + + } +} + +void TEST() { + __try { + + } + __except ( NotFilterExpression() ) { // expected-error{{filter expression type should be an integral value not 'const char *'}} + + } +} + +void TEST() { + int function_scope = 0; + __try { + int try_scope = 0; + } + __except ( FilterExpression(GetExceptionCode()) ) { + (void)function_scope; + (void)try_scope; // expected-error{{undeclared identifier}} + } +} + +void TEST() { + int function_scope = 0; + __try { + int try_scope = 0; + } + __finally { + (void)function_scope; + (void)try_scope; // expected-error{{undeclared identifier}} + } +} + +void TEST() { + int function_scope = 0; + __try { + + } + __except( function_scope ? 1 : -1 ) {} +} + +void TEST() { + __try { + (void)AbnormalTermination; // expected-error{{only allowed in __finally block}} + (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} + } + __except( 1 ) { + (void)AbnormalTermination; // expected-error{{only allowed in __finally block}} + (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} + } + + __try { + } + __finally { + AbnormalTermination(); + __abnormal_termination(); + } +} + +void TEST() { + (void)__exception_code; // expected-error{{only allowed in __except block}} + (void)__exception_info; // expected-error{{only allowed in __except filter expression}} + (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} + + (void)GetExceptionCode(); // expected-error{{only allowed in __except block}} + (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}} + (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}} +} diff --git a/test/Sema/align-x86-64.c b/test/Sema/align-x86-64.c index 6dcf5714b0053..edea5d8b74223 100644 --- a/test/Sema/align-x86-64.c +++ b/test/Sema/align-x86-64.c @@ -9,3 +9,17 @@ void foo(void) { char y[__alignof__(x) == 16 ? 1 : -1]; frob(y); } + +// PR5637 + +typedef __attribute__((aligned(16))) struct { + unsigned long long w[3]; +} UINT192; + +UINT192 ten2mk192M[] = { + {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}}, + {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}}, + {{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}} +}; + +short chk1[sizeof(ten2mk192M) == 80 ? 1 : -1]; diff --git a/test/Sema/align-x86.c b/test/Sema/align-x86.c index c9a63989ecbc2..61bd1d33c9d6e 100644 --- a/test/Sema/align-x86.c +++ b/test/Sema/align-x86.c @@ -14,7 +14,31 @@ short chk1[__alignof__(g3) == 8 ? 1 : -1]; short chk2[__alignof__(_Complex double) == 8 ? 1 : -1]; // PR6362 -struct __attribute__((packed)) {unsigned int a} g4; +struct __attribute__((packed)) {unsigned int a;} g4; short chk1[__alignof__(g4) == 1 ? 1 : -1]; short chk2[__alignof__(g4.a) == 1 ? 1 : -1]; + +// PR5637 + +#define ALIGNED(x) __attribute__((aligned(x))) + +typedef ALIGNED(2) struct { + char a[3]; +} T; + +short chk1[sizeof(T) == 3 ? 1 : -1]; +short chk2[sizeof(T[1]) == 4 ? 1 : -1]; +short chk3[sizeof(T[2]) == 6 ? 1 : -1]; +short chk4[sizeof(T[2][1]) == 8 ? 1 : -1]; +short chk5[sizeof(T[1][2]) == 6 ? 1 : -1]; + +typedef struct ALIGNED(2) { + char a[3]; +} T2; + +short chk1[sizeof(T2) == 4 ? 1 : -1]; +short chk2[sizeof(T2[1]) == 4 ? 1 : -1]; +short chk3[sizeof(T2[2]) == 8 ? 1 : -1]; +short chk4[sizeof(T2[2][1]) == 8 ? 1 : -1]; +short chk5[sizeof(T2[1][2]) == 8 ? 1 : -1]; diff --git a/test/Sema/altivec-init.c b/test/Sema/altivec-init.c index ef6fe4bd9d2f2..973aab15d4660 100644 --- a/test/Sema/altivec-init.c +++ b/test/Sema/altivec-init.c @@ -9,6 +9,18 @@ v8 foo(void) { a = (v8){4, 2}; b = (v4)(5, 6, 7, 8, 9); // expected-warning {{excess elements in vector initializer}} b = (v4)(5, 6, 8, 8.0f); + + vector int vi; + vi = (vector int)(1); + vi = (vector int)(1, 2); // expected-error {{number of elements must be either one or match the size of the vector}} + vi = (vector int)(1, 2, 3, 4); + vi = (vector int)(1, 2, 3, 4, 5); // expected-warning {{excess elements in vector initializer}} + vi = (vector int){1}; + vi = (vector int){1, 2}; + vi = (vector int){1, 2, 3, 4, 5}; // expected-warning {{excess elements in vector initializer}} + vector float vf; + vf = (vector float)(1.0); + return (v8){0, 1, 2, 3, 1, 2, 3, 4}; // FIXME: test that (type)(fn)(args) still works with -faltivec diff --git a/test/Sema/annotate.c b/test/Sema/annotate.c index 4d550759a25fb..6f81491f1ffa4 100644 --- a/test/Sema/annotate.c +++ b/test/Sema/annotate.c @@ -3,5 +3,5 @@ void __attribute__((annotate("foo"))) foo(float *a) { __attribute__((annotate("bar"))) int x; __attribute__((annotate(1))) int y; // expected-error {{argument to annotate attribute was not a string literal}} - __attribute__((annotate("bar", 1))) int z; // expected-error {{attribute requires 1 argument(s)}} + __attribute__((annotate("bar", 1))) int z; // expected-error {{attribute takes one argument}} } diff --git a/test/Sema/anonymous-struct-union.c b/test/Sema/anonymous-struct-union.c index d9e08397f2d38..d88abc3c3b9e9 100644 --- a/test/Sema/anonymous-struct-union.c +++ b/test/Sema/anonymous-struct-union.c @@ -94,7 +94,7 @@ struct {}; // expected-warning{{declaration does not declare anything}} struct s2 { union { int a; - } + } // expected-warning{{expected ';' at end of declaration list}} }; // expected-error{{expected member name or ';' after declaration specifiers}} // Make sure we don't a.k.a. anonymous structs. diff --git a/test/Sema/arm-layout.c b/test/Sema/arm-layout.c index 424868510428c..d017fdb8aa07d 100644 --- a/test/Sema/arm-layout.c +++ b/test/Sema/arm-layout.c @@ -42,7 +42,7 @@ check(s3_offset_0, __builtin_offsetof(struct s3, field0) == 0); check(s3_offset_1, __builtin_offsetof(struct s3, field2) == 7); struct s4 { - int field0 : 4 + int field0 : 4; }; #ifdef __ARM_EABI__ check(s4_size, sizeof(struct s4) == 4); diff --git a/test/Sema/attr-args.c b/test/Sema/attr-args.c new file mode 100644 index 0000000000000..61358016fbe1e --- /dev/null +++ b/test/Sema/attr-args.c @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -DATTR=noreturn -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=always_inline -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=cdecl -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=const -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=fastcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=malloc -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=nothrow -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=stdcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=used -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=unused -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=weak -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s + +#define ATTR_DECL(a) __attribute__((ATTR(a))) + +int a; + +inline ATTR_DECL(a) void* foo(); // expected-error{{attribute takes no arguments}} + + + +// RUN: %clang_cc1 -DATTR=noreturn -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=always_inline -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=cdecl -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=const -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=fastcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=malloc -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=nothrow -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=stdcall -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=used -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=unused -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s +// RUN: %clang_cc1 -DATTR=weak -verify -Wunused -Wused-but-marked-unused -Wunused-parameter -Wunused -fsyntax-only %s + +#define ATTR_DECL(a) __attribute__((ATTR(a))) + +int a; + +inline ATTR_DECL(a) void* foo(); // expected-error{{attribute takes no arguments}} + + + diff --git a/test/Sema/attr-availability-ios.c b/test/Sema/attr-availability-ios.c new file mode 100644 index 0000000000000..435e312481d63 --- /dev/null +++ b/test/Sema/attr-availability-ios.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 "-triple" "x86_64-apple-darwin3.0.0-iphoneos" -fsyntax-only -verify %s + +void f0(int) __attribute__((availability(ios,introduced=2.0,deprecated=2.1))); +void f1(int) __attribute__((availability(ios,introduced=2.1))); +void f2(int) __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); +void f3(int) __attribute__((availability(ios,introduced=3.0))); +void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(ios,introduced=2.0,deprecated=2.1,obsoleted=3.0))); // expected-note{{explicitly marked unavailable}} + +void f5(int) __attribute__((availability(ios,introduced=2.0))) __attribute__((availability(ios,deprecated=3.0))); +void f6(int) __attribute__((availability(ios,deprecated=3.0))); +void f6(int) __attribute__((availability(ios,introduced=2.0))); + +void test() { + f0(0); // expected-warning{{'f0' is deprecated: first deprecated in iOS 2.1}} + f1(0); + f2(0); // expected-warning{{'f2' is deprecated: first deprecated in iOS 3.0}} + f3(0); + f4(0); // expected-error{{f4' is unavailable: obsoleted in iOS 3.0}} + f5(0); // expected-warning{{'f5' is deprecated: first deprecated in iOS 3.0}} + f6(0); // expected-warning{{'f6' is deprecated: first deprecated in iOS 3.0}} +} diff --git a/test/Sema/attr-availability-macosx.c b/test/Sema/attr-availability-macosx.c new file mode 100644 index 0000000000000..2b7c1e06ace78 --- /dev/null +++ b/test/Sema/attr-availability-macosx.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 "-triple" "x86_64-apple-darwin9.0.0" -fsyntax-only -verify %s + +void f0(int) __attribute__((availability(macosx,introduced=10.4,deprecated=10.6))); +void f1(int) __attribute__((availability(macosx,introduced=10.5))); +void f2(int) __attribute__((availability(macosx,introduced=10.4,deprecated=10.5))); +void f3(int) __attribute__((availability(macosx,introduced=10.6))); +void f4(int) __attribute__((availability(macosx,introduced=10.1,deprecated=10.3,obsoleted=10.5), availability(ios,introduced=2.0,deprecated=3.0))); // expected-note{{explicitly marked unavailable}} +void f5(int) __attribute__((availability(ios,introduced=3.2), availability(macosx,unavailable))); // expected-note{{function has been explicitly marked unavailable here}} + +void test() { + f0(0); + f1(0); + f2(0); // expected-warning{{'f2' is deprecated: first deprecated in Mac OS X 10.5}} + f3(0); + f4(0); // expected-error{{f4' is unavailable: obsoleted in Mac OS X 10.5}} + f5(0); // expected-error{{'f5' is unavailable: not available on Mac OS X}} +} diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c new file mode 100644 index 0000000000000..1314cf5a5b032 --- /dev/null +++ b/test/Sema/attr-availability.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in Mac OS X version 10.2 before it was introduced in version 10.4; attribute ignored}} +void f1() __attribute__((availability(ios,obsoleted=2.1,deprecated=3.0))); // expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was deprecated in version 3.0; attribute ignored}} + +void f2() __attribute__((availability(otheros,introduced=2.2))); // expected-warning{{unknown platform 'otheros' in availability macro}} diff --git a/test/Sema/attr-cleanup.c b/test/Sema/attr-cleanup.c index 9057c27a56fe5..59ebbfc4599fe 100644 --- a/test/Sema/attr-cleanup.c +++ b/test/Sema/attr-cleanup.c @@ -8,8 +8,8 @@ static int g3 __attribute((cleanup(c1))); // expected-warning {{cleanup attribut void t1() { - int v1 __attribute((cleanup)); // expected-error {{attribute requires 1 argument(s)}} - int v2 __attribute((cleanup(1, 2))); // expected-error {{attribute requires 1 argument(s)}} + int v1 __attribute((cleanup)); // expected-error {{attribute takes one argument}} + int v2 __attribute((cleanup(1, 2))); // expected-error {{attribute takes one argument}} static int v3 __attribute((cleanup(c1))); // expected-warning {{cleanup attribute ignored}} diff --git a/test/Sema/attr-naked.c b/test/Sema/attr-naked.c index 65d1726da1337..1ebd78438e2f8 100644 --- a/test/Sema/attr-naked.c +++ b/test/Sema/attr-naked.c @@ -4,5 +4,5 @@ int a __attribute__((naked)); // expected-warning {{'naked' attribute only appli void t1() __attribute__((naked)); -void t2() __attribute__((naked(2))); // expected-error {{attribute requires 0 argument(s)}} +void t2() __attribute__((naked(2))); // expected-error {{attribute takes no arguments}} diff --git a/test/Sema/attr-nodebug.c b/test/Sema/attr-nodebug.c index 6865de060266c..a66e96168dd60 100644 --- a/test/Sema/attr-nodebug.c +++ b/test/Sema/attr-nodebug.c @@ -4,5 +4,5 @@ int a __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only a void t1() __attribute__((nodebug)); -void t2() __attribute__((nodebug(2))); // expected-error {{attribute requires 0 argument(s)}} +void t2() __attribute__((nodebug(2))); // expected-error {{attribute takes no arguments}} diff --git a/test/Sema/attr-noinline.c b/test/Sema/attr-noinline.c index 8c91b65b4f486..dfc88a8d8fcb5 100644 --- a/test/Sema/attr-noinline.c +++ b/test/Sema/attr-noinline.c @@ -4,5 +4,5 @@ int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only void t1() __attribute__((noinline)); -void t2() __attribute__((noinline(2))); // expected-error {{attribute requires 0 argument(s)}} +void t2() __attribute__((noinline(2))); // expected-error {{attribute takes no arguments}} diff --git a/test/Sema/attr-noreturn.c b/test/Sema/attr-noreturn.c index 5333a2c13fc28..5c643fff718df 100644 --- a/test/Sema/attr-noreturn.c +++ b/test/Sema/attr-noreturn.c @@ -13,7 +13,7 @@ int f1() __attribute__((noreturn)); int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' only applies to function types; type here is 'int'}} -int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute requires 0 argument(s)}} +int f2() __attribute__((noreturn(1, 2))); // expected-error {{attribute takes no arguments}} void f3() __attribute__((noreturn)); void f3() { @@ -41,4 +41,4 @@ __attribute__((noreturn)) void f(__attribute__((noreturn)) void (*x)(void)) { x(); } -typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{attribute requires 0 argument(s)}} +typedef void (*Fun)(void) __attribute__ ((noreturn(2))); // expected-error {{attribute takes no arguments}} diff --git a/test/Sema/attr-regparm.c b/test/Sema/attr-regparm.c index 4049e0e8a13fd..642c07e7bc112 100644 --- a/test/Sema/attr-regparm.c +++ b/test/Sema/attr-regparm.c @@ -4,7 +4,7 @@ __attribute((regparm(2))) int x0(void); __attribute((regparm(1.0))) int x1(void); // expected-error{{'regparm' attribute requires integer constant}} __attribute((regparm(-1))) int x2(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}} __attribute((regparm(5))) int x3(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}} -__attribute((regparm(5,3))) int x4(void); // expected-error{{attribute requires 1 argument(s)}} +__attribute((regparm(5,3))) int x4(void); // expected-error{{attribute takes one argument}} void __attribute__((regparm(3))) x5(int); void x5(int); // expected-note{{previous declaration is here}} diff --git a/test/Sema/attr-unused.c b/test/Sema/attr-unused.c index 6a7ea951a3609..07c65cbd9aede 100644 --- a/test/Sema/attr-unused.c +++ b/test/Sema/attr-unused.c @@ -9,7 +9,7 @@ int f1() __attribute__((unused)); int g0 __attribute__((unused)); -int f2() __attribute__((unused(1, 2))); // expected-error {{attribute requires 0 argument(s)}} +int f2() __attribute__((unused(1, 2))); // expected-error {{attribute takes no arguments}} struct Test0_unused {} __attribute__((unused)); struct Test0_not_unused {}; diff --git a/test/Sema/block-args.c b/test/Sema/block-args.c index e2e2d8e44622e..5ee383eebb024 100644 --- a/test/Sema/block-args.c +++ b/test/Sema/block-args.c @@ -40,3 +40,8 @@ void test4() { int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}} } +// rdar://problem/9170609 +void test5_helper(void (^)(int, int[*])); +void test5(void) { + test5_helper(^(int n, int array[n]) {}); +} diff --git a/test/Sema/builtins-decl.c b/test/Sema/builtins-decl.c new file mode 100644 index 0000000000000..19bdb840ccfb2 --- /dev/null +++ b/test/Sema/builtins-decl.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=i686-mingw32 +// RUN: %clang_cc1 %s -fsyntax-only -verify -triple=x86_64-mingw32 + +// mingw-w64's intrin.h has decls below. +// we should accept them. +extern unsigned int __builtin_ia32_crc32qi (unsigned int, unsigned char); +extern unsigned int __builtin_ia32_crc32hi (unsigned int, unsigned short); +extern unsigned int __builtin_ia32_crc32si (unsigned int, unsigned int); diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index 4072faa94b9f8..64efefc7fdadd 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -27,7 +27,7 @@ int test6(float a, long double b) { void test7() { const void *X; X = CFSTR("\242"); // expected-warning {{input conversion stopped}} - X = CFSTR("\0"); // expected-warning {{ CFString literal contains NUL character }} + X = CFSTR("\0"); // no-warning 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}} } diff --git a/test/Sema/c89.c b/test/Sema/c89.c index 038f7e537d76a..670dd15539f03 100644 --- a/test/Sema/c89.c +++ b/test/Sema/c89.c @@ -80,3 +80,5 @@ void test13b() { /* Make sure we allow *test14 as a "function designator" */ int test14() { return (&*test14)(); } + +int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */ diff --git a/test/Sema/callingconv.c b/test/Sema/callingconv.c index 92a20572a2c17..25669f08ae29c 100644 --- a/test/Sema/callingconv.c +++ b/test/Sema/callingconv.c @@ -6,7 +6,7 @@ void __attribute__((fastcall)) foo(float *a) { void __attribute__((stdcall)) bar(float *a) { } -void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{attribute requires 0 argument(s)}} +void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{attribute takes no arguments}} } void __attribute__((fastcall)) test0() { // expected-error {{function with no prototype cannot use fastcall calling convention}} @@ -20,7 +20,7 @@ void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic void __attribute__((cdecl)) ctest0() {} -void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{attribute requires 0 argument(s)}} +void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{attribute takes no arguments}} void (__attribute__((fastcall)) *pfoo)(float*) = foo; diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index aa0cee5da5b34..56c429c58c2ab 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -58,7 +58,7 @@ EVAL_EXPR(29, (_Complex int)1 ? 1 : -1) // PR4027 + rdar://6808859 -struct a { int x, y }; +struct a { int x, y; }; static struct a V2 = (struct a)(struct a){ 1, 2}; static const struct a V1 = (struct a){ 1, 2}; diff --git a/test/Sema/constructor-attribute.c b/test/Sema/constructor-attribute.c index 2decebbd284ac..382591654d91b 100644 --- a/test/Sema/constructor-attribute.c +++ b/test/Sema/constructor-attribute.c @@ -3,13 +3,13 @@ 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,2))); // expected-error {{attribute takes no more than 1 argument}} 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 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)}} +int f() __attribute__((destructor(1,2))); // expected-error {{attribute takes no more than 1 argument}} int f() __attribute__((destructor(1.0))); // expected-error {{'destructor' attribute requires parameter 1 to be an integer constant}} diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 619d6993251f3..1eaf7082d67e7 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -323,6 +323,10 @@ void test_8559831(enum E8559831b value_a, E8559831c value_c) { 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(E8559831b_val); // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}} + enum E8559831a a1a = E8559831b_val; // expected-warning{{implicit conversion from enumeration type 'enum E8559831b' to different enumeration type 'enum E8559831a'}} + a1 = E8559831b_val; // 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'}} diff --git a/test/Sema/expr-address-of.c b/test/Sema/expr-address-of.c index 8f9f795d00ddf..2b8cfbfa68f59 100644 --- a/test/Sema/expr-address-of.c +++ b/test/Sema/expr-address-of.c @@ -107,3 +107,14 @@ char* f7() { void* t3 = &(*(void*)0); } + +void f8() { + void *dummy0 = &f8(); // expected-error {{address expression must be an lvalue or a function designator}} + + extern void v; + void *dummy1 = &(1 ? v : f8()); // expected-error {{address expression must be an lvalue or a function designator}} + + void *dummy2 = &(f8(), v); // expected-error {{address expression must be an lvalue or a function designator}} + + void *dummy3 = &({ ; }); // expected-error {{address expression must be an lvalue or a function designator}} +} diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c index 0d6c5488de5f2..e4eeaec05d97d 100644 --- a/test/Sema/exprs.c +++ b/test/Sema/exprs.c @@ -12,6 +12,14 @@ } while (0) +// Test that we don't report divide-by-zero errors in unreachable code. +// This test should be left as is, as it also tests CFG functionality. +void radar9171946() { + if (0) { + 0 / (0 ? 1 : 0); // expected-warning {{expression result unused}} + } +} + 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'}} @@ -155,7 +163,7 @@ void test17(int x) { } // PR6501 -void test18_a(int a); +void test18_a(int a); // expected-note {{'test18_a' declared here}} void test18(int b) { test18_a(b, b); // expected-error {{too many arguments to function call, expected 1, have 2}} test18_a(); // expected-error {{too few arguments to function call, expected 1, have 0}} @@ -166,6 +174,12 @@ void test19() { *(int*)0 = 0; // expected-warning {{indirection of non-volatile null pointer}} \ // expected-note {{consider using __builtin_trap}} *(volatile int*)0 = 0; // Ok. + + // rdar://9269271 + int x = *(int*)0; // expected-warning {{indirection of non-volatile null pointer}} \ + // expected-note {{consider using __builtin_trap}} + int x2 = *(volatile int*)0; // Ok. + int *p = &(*(int*)0); // Ok; } int test20(int x) { diff --git a/test/Sema/format-strings-fixit.c b/test/Sema/format-strings-fixit.c index 7cd76c7c37e78..c2fa2f7707450 100644 --- a/test/Sema/format-strings-fixit.c +++ b/test/Sema/format-strings-fixit.c @@ -1,6 +1,7 @@ // RUN: cp %s %t // RUN: %clang_cc1 -pedantic -Wall -fixit %t || true // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t +// RUN: %clang_cc1 -E -o - %t | FileCheck %s /* This is a test of the various code modification hints that are provided as part of warning or extension diagnostics. All of the @@ -41,4 +42,29 @@ void test() { // Bad length modifiers printf("%hhs", "foo"); printf("%1$zp", (void *)0); + + // Perserve the original formatting for unsigned integers. + unsigned long val = 42; + printf("%X", val); } + +// Validate the fixes... +// CHECK: printf("%d", (int) 123); +// CHECK: printf("abc%s", "testing testing 123"); +// CHECK: printf("%ld", (long) -12); +// CHECK: printf("%d", 123); +// CHECK: printf("%s\n", "x"); +// CHECK: printf("%f\n", 1.23); +// CHECK: printf("%.2llu", (unsigned long long) 123456); +// CHECK: printf("%1Lf", (long double) 1.23); +// CHECK: printf("%0u", (unsigned) 31337); +// CHECK: printf("%p", (void *) 0); +// CHECK: printf("%+f", 1.23); +// CHECK: printf("%-f", 1.23); +// CHECK: printf("%1$d:%2$.*3$d:%4$.*3$d\n", 1, 2, 3, 4); +// CHECK: printf("%10.5ld", 1l); +// CHECK: printf("%c", 'a'); +// CHECK: printf("%-f", 1.23); +// CHECK: printf("%s", "foo"); +// CHECK: printf("%1$p", (void *)0); +// CHECK: printf("%lX", val); diff --git a/test/Sema/function-redecl.c b/test/Sema/function-redecl.c index 27ec163ea9cb8..7076bdf3bd1ff 100644 --- a/test/Sema/function-redecl.c +++ b/test/Sema/function-redecl.c @@ -2,7 +2,7 @@ // PR3588 void g0(int, int); -void g0(); // expected-note{{previous declaration is here}} +void g0(); // expected-note{{previous declaration is here}} expected-note{{'g0' declared here}} void f0() { g0(1, 2, 3); // expected-error{{too many arguments to function call}} diff --git a/test/Sema/generic-selection.c b/test/Sema/generic-selection.c new file mode 100644 index 0000000000000..8cef975c709c8 --- /dev/null +++ b/test/Sema/generic-selection.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s + +void foo(int n) { + (void) _Generic(0, + struct A: 0, // expected-error {{type 'struct A' in generic association incomplete}} + void(): 0, // expected-error {{type 'void ()' in generic association not an object type}} + int[n]: 0); // expected-error {{type 'int [n]' in generic association is a variably modified type}} + + (void) _Generic(0, + void (*)(): 0, // expected-note {{compatible type 'void (*)()' specified here}} + void (*)(void): 0); // expected-error {{type 'void (*)(void)' in generic association compatible with previously specified type 'void (*)()'}} + + (void) _Generic((void (*)()) 0, // expected-error {{controlling expression type 'void (*)()' compatible with 2 generic association types}} + void (*)(int): 0, // expected-note {{compatible type 'void (*)(int)' specified here}} + void (*)(void): 0); // expected-note {{compatible type 'void (*)(void)' specified here}} + + (void) _Generic(0, // expected-error {{controlling expression type 'int' not compatible with any generic association type}} + char: 0, short: 0, long: 0); + + int a1[_Generic(0, int: 1, short: 2, float: 3, default: 4) == 1 ? 1 : -1]; + int a2[_Generic(0, default: 1, short: 2, float: 3, int: 4) == 4 ? 1 : -1]; + int a3[_Generic(0L, int: 1, short: 2, float: 3, default: 4) == 4 ? 1 : -1]; + int a4[_Generic(0L, default: 1, short: 2, float: 3, int: 4) == 1 ? 1 : -1]; + int a5[_Generic(0, int: 1, short: 2, float: 3) == 1 ? 1 : -1]; + int a6[_Generic(0, short: 1, float: 2, int: 3) == 3 ? 1 : -1]; +} diff --git a/test/Sema/incomplete-call.c b/test/Sema/incomplete-call.c index 3ef578d59f6f2..d34bda54986c8 100644 --- a/test/Sema/incomplete-call.c +++ b/test/Sema/incomplete-call.c @@ -6,8 +6,8 @@ struct foo a(); // expected-note {{'a' declared here}} void b(struct foo); void c(); -void func() { +void func(void *p) { a(); // expected-error{{calling 'a' with incomplete return type 'struct foo'}} - b(*(struct foo*)0); // expected-error{{argument type 'struct foo' is incomplete}} - c(*(struct foo*)0); // expected-error{{argument type 'struct foo' is incomplete}} + b(*(struct foo*)p); // expected-error{{argument type 'struct foo' is incomplete}} + c(*(struct foo*)p); // expected-error{{argument type 'struct foo' is incomplete}} } diff --git a/test/Sema/knr-def-call.c b/test/Sema/knr-def-call.c index d054a04765054..6243af6193989 100644 --- a/test/Sema/knr-def-call.c +++ b/test/Sema/knr-def-call.c @@ -36,6 +36,8 @@ void proto(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}} + proto(42.0); // expected-warning{{implicit conversion turns literal floating-point number into integer}} \ + // expected-note {{this can be rewritten as an integer literal with the exact same value}} + (&proto)(42.0); // expected-warning{{implicit conversion turns literal floating-point number into integer}} \ + // expected-note {{this can be rewritten as an integer literal with the exact same value}} } diff --git a/test/Sema/memset-invalid.c b/test/Sema/memset-invalid.c new file mode 100644 index 0000000000000..c763858e26ec6 --- /dev/null +++ b/test/Sema/memset-invalid.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify + +char memset(); // expected-warning {{incompatible redeclaration of library function 'memset'}} expected-note{{'memset' is a builtin with type}} +char test() { + return memset(); +} diff --git a/test/Sema/missing-field-initializers.c b/test/Sema/missing-field-initializers.c index 6aa48ba9e419d..90e0e2a345b08 100644 --- a/test/Sema/missing-field-initializers.c +++ b/test/Sema/missing-field-initializers.c @@ -46,7 +46,7 @@ struct Three data[] = { { { .two = { 1.0f, 2.0f } } } // expected-warning {{missing field 'e' initializer}} }; -struct { int:5; int a; int:5; int b; int:5 } noNamedImplicit[] = { +struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = { { 1, 2 }, { 1 } // expected-warning {{missing field 'b' initializer}} }; diff --git a/test/Sema/neon-vector-types.c b/test/Sema/neon-vector-types.c index 1f501776cc8e5..cbf013398a264 100644 --- a/test/Sema/neon-vector-types.c +++ b/test/Sema/neon-vector-types.c @@ -16,7 +16,7 @@ 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)}} +typedef __attribute__((neon_vector_type(2, 4))) int only_one_arg; // expected-error{{attribute takes one argument}} // 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}} diff --git a/test/Sema/overloaded-func-transparent-union.c b/test/Sema/overloaded-func-transparent-union.c new file mode 100644 index 0000000000000..fa0314e946f2a --- /dev/null +++ b/test/Sema/overloaded-func-transparent-union.c @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify +// rdar:// 9129552 +// PR9406 + +typedef struct { + char *str; + char *str2; +} Class; + +typedef union { + Class *object; +} Instance __attribute__((transparent_union)); + +__attribute__((overloadable)) void Class_Init(Instance this, char *str, void *str2) { + this.object->str = str; + this.object->str2 = str2; +} + +__attribute__((overloadable)) void Class_Init(Instance this, char *str) { + this.object->str = str; + this.object->str2 = str; +} + +int main(void) { + Class obj; + Class_Init(&obj, "Hello ", " World"); +} + diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c index b45d8512f6bf7..a25ded66a665b 100644 --- a/test/Sema/parentheses.c +++ b/test/Sema/parentheses.c @@ -26,7 +26,8 @@ void bitwise_rel(unsigned i) { (void)(i == 1 | i == 2 | i == 3); (void)(i != 1 & i != 2 & i != 3); - (void)(i || i && i); // expected-warning {{'&&' within '||'}} \ + (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. diff --git a/test/Sema/pragma-ms_struct.c b/test/Sema/pragma-ms_struct.c new file mode 100644 index 0000000000000..b2c2684c61945 --- /dev/null +++ b/test/Sema/pragma-ms_struct.c @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin9 %s + +#pragma ms_struct on + +#pragma ms_struct off + +#pragma ms_struct reset + +#pragma ms_struct // expected-warning {{incorrect use of '#pragma ms_struct on|off' - ignored}} + +#pragma ms_struct on top of spaghetti // expected-warning {{extra tokens at end of '#pragma ms_struct' - ignored}} + +struct foo +{ + int a; + int b; + char c; +}; + + +struct { + unsigned long bf_1 : 12; + unsigned long : 0; + unsigned long bf_2 : 12; +} __attribute__((__ms_struct__)) t1; + +struct S { + double __attribute__((ms_struct)) d; // expected-warning {{'ms_struct' attribute ignored}} + unsigned long bf_1 : 12; + unsigned long : 0; + unsigned long bf_2 : 12; +} __attribute__((ms_struct)) t2; + + diff --git a/test/Sema/sentinel-attribute.c b/test/Sema/sentinel-attribute.c index ed0ef89db70bf..e5cbf6ee04af5 100644 --- a/test/Sema/sentinel-attribute.c +++ b/test/Sema/sentinel-attribute.c @@ -5,7 +5,7 @@ void f1(int a, ...) __attribute__ ((sentinel)); void f2(int a, ...) __attribute__ ((sentinel(1))); void f3(int a, ...) __attribute__ ((sentinel("hello"))); //expected-error{{'sentinel' attribute requires parameter 1 to be an integer constant}} -void f4(int a, ...) __attribute__ ((sentinel(1, 2, 3))); //expected-error{{attribute requires 0, 1 or 2 argument(s)}} +void f4(int a, ...) __attribute__ ((sentinel(1, 2, 3))); //expected-error{{attribute takes no more than 2 arguments}} void f4(int a, ...) __attribute__ ((sentinel(-1))); //expected-error{{parameter 1 less than zero}} void f4(int a, ...) __attribute__ ((sentinel(0, 2))); // expected-error{{parameter 2 not 0 or 1}} diff --git a/test/Sema/shift.c b/test/Sema/shift.c index df6b1141bdfc7..28407be079f45 100644 --- a/test/Sema/shift.c +++ b/test/Sema/shift.c @@ -56,3 +56,13 @@ void test() { #define ashift 8 enum { b = (a << ashift) }; +// Don't warn for negative shifts in code that is unreachable. +void test_pr5544() { + (void) (((1) > 63 && (1) < 128 ? (((unsigned long long) 1)<<((1)-64)) : (unsigned long long) 0)); // no-warning +} + +void test_shift_too_much(char x) { + if (0) + (void) (x >> 80); // no-warning + (void) (x >> 80); // expected-warning {{shift count >= width of type}} +} diff --git a/test/Sema/static-assert.c b/test/Sema/static-assert.c new file mode 100644 index 0000000000000..13d70708582b9 --- /dev/null +++ b/test/Sema/static-assert.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s + +_Static_assert("foo", "string is nonzero"); // expected-error {{static_assert expression is not an integral constant expression}} + +_Static_assert(1, "1 is nonzero"); +_Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} + +void foo(void) { + _Static_assert(1, "1 is nonzero"); + _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} +} diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c index 3639d2479b97c..e1c7073e01b29 100644 --- a/test/Sema/struct-decl.c +++ b/test/Sema/struct-decl.c @@ -46,3 +46,14 @@ struct s0 f0(void) {} struct x0 { unsigned int x1; }; + +// rdar://problem/9150338 +static struct test1 { // expected-warning {{'static' ignored on this declaration}} + int x; +}; +const struct test2 { // expected-warning {{'const' ignored on this declaration}} + int x; +}; +inline struct test3 { // expected-warning {{'inline' ignored on this declaration}} + int x; +}; diff --git a/test/Sema/uninit-variables-vectors.c b/test/Sema/uninit-variables-vectors.c new file mode 100644 index 0000000000000..10a8ecc378f0f --- /dev/null +++ b/test/Sema/uninit-variables-vectors.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -Wuninitialized -fsyntax-only %s -verify + +typedef int __v4si __attribute__((__vector_size__(16))); +typedef float __m128 __attribute__((__vector_size__(16))); +__m128 _mm_xor_ps(__m128 a, __m128 b); +__m128 _mm_loadu_ps(const float *p); + +void test1(float *input) { + __m128 x, y, z, w, X; // expected-note {{variable 'x' is declared here}} expected-note {{variable 'y' is declared here}} expected-note {{variable 'w' is declared here}} expected-note {{variable 'z' is declared here}} + x = _mm_xor_ps(x,x); // expected-warning {{variable 'x' is uninitialized when used here}} + y = _mm_xor_ps(y,y); // expected-warning {{variable 'y' is uninitialized when used here}} + z = _mm_xor_ps(z,z); // expected-warning {{variable 'z' is uninitialized when used here}} + w = _mm_xor_ps(w,w); // expected-warning {{variable 'w' is uninitialized when used here}} + X = _mm_loadu_ps(&input[0]); + X = _mm_xor_ps(X,X); // no-warning +} + diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index 973e504f634dc..60cae802ae73a 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -1,8 +1,8 @@ -// RUN: %clang_cc1 -fsyntax-only -Wuninitialized-experimental -fsyntax-only -fblocks %s -verify +// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -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}} + return x; // expected-warning{{variable 'x' is uninitialized when used here}} } int test2() { @@ -18,19 +18,19 @@ int test3() { 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}} + ++x; // expected-warning{{variable 'x' is 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}} + x = y; // expected-warning{{variable 'y' is 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}} + x += 2; // expected-warning{{variable 'x' is uninitialized when used here}} return x; } @@ -38,7 +38,7 @@ 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}} + return x; // expected-warning{{variable 'x' may be uninitialized when used here}} } int test8(int y) { @@ -57,7 +57,7 @@ int test9(int n) { break; x = 1; } - return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} + return x; // expected-warning{{variable 'x' may be uninitialized when used here}} } int test10(unsigned n) { @@ -65,7 +65,7 @@ int test10(unsigned n) { for (unsigned i = 0 ; i < n; ++i) { x = 1; } - return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} + return x; // expected-warning{{variable 'x' may be uninitialized when used here}} } int test11(unsigned n) { @@ -73,11 +73,11 @@ int test11(unsigned n) { for (unsigned i = 0 ; i <= n; ++i) { x = 1; } - return x; // expected-warning{{variable 'x' is possibly uninitialized when used here}} + return x; // expected-warning{{variable 'x' may be 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}} + for (unsigned i ; n ; ++i) ; // expected-warning{{variable 'i' may be uninitialized when used here}} expected-note{{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}} } int test13() { @@ -91,8 +91,10 @@ void test14() { 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}} +int test15() { + int x = x; // no-warning: signals intended lack of initialization. \ + // expected-note{{variable 'x' is declared here}} + return x; // expected-warning{{variable 'x' is uninitialized when used here}} } // Don't warn in the following example; shows dataflow confluence. @@ -107,7 +109,7 @@ 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; // expected-warning{{variable 'x' is uninitialized when used here}} *x = 1; // no-warning } @@ -132,14 +134,14 @@ int test19() { 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 z; // expected-warning{{variable 'z' may be 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 z; // expected-warning{{variable 'z' may be uninitialized when used here}} return 0; } @@ -167,18 +169,18 @@ int test24(int flag) { val = 1; if (!flag) val = 1; - return val; // expected-warning{{variable 'val' is possibly uninitialized when used here}} + return val; // expected-warning{{variable 'val' may be 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}} + return x; // expected-warning{{variable 'x' is 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}} + return x; // expected-warning{{variable 'x' is uninitialized when used here}} } // Test handling of sizeof(). @@ -189,12 +191,12 @@ int test27() { 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}} + return sizeof(int[len]); // expected-warning{{variable 'len' is 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) ^{ (void) x; }; // expected-warning{{variable 'x' is uninitialized when captured by block}} } void test30() { @@ -220,7 +222,7 @@ void test_33() { 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}} + return x; // expected-warning{{variable 'x' is uninitialized when used here}} } // Test that this case doesn't crash. @@ -235,7 +237,7 @@ 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}} + goto *pc; // expected-warning{{variable 'pc' may be uninitialized when used here}} L2: goto *pc; } @@ -260,3 +262,80 @@ int test38(int r, int x, int y) return ((r < 0) || ((r == 0) && (x < y))); } +int test39(int x) { + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + int z = x + y; // expected-warning {{variable 'y' is uninitialized when used here}} + return z; +} + + +int test40(int x) { + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + return x ? 1 : y; // expected-warning {{variable 'y' is uninitialized when used here}} +} + +int test41(int x) { + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + if (x) y = 1; // no-warning + return y; // expected-warning {{variable 'y' may be uninitialized when used here}} +} + +void test42() { + int a; + a = 30; // no-warning +} + +void test43_aux(int x); +void test43(int i) { + int x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} + for (i = 0 ; i < 10; i++) + test43_aux(x++); // expected-warning {{variable 'x' may be uninitialized when used here}} +} + +void test44(int i) { + int x = i; + int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} + for (i = 0; i < 10; i++ ) { + test43_aux(x++); // no-warning + x += y; // expected-warning {{variable 'y' may be uninitialized when used here}} + } +} + +int test45(int j) { + int x = 1, y = x + 1; + if (y) // no-warning + return x; + return y; +} + +void test46() +{ + int i; // expected-note {{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}} + int j = i ? : 1; // expected-warning {{variable 'i' is uninitialized when used here}} +} + +void *test47(int *i) +{ + return i ? : 0; // no-warning +} + +void *test49(int *i) +{ + int a; + return &a ? : i; // no-warning +} + +void test50() +{ + char c[1 ? : 2]; // no-warning +} + +int test51(void) +{ + __block int a; + ^(void) { + a = 42; + }(); + return a; // no-warning +} + diff --git a/test/Sema/vector-ops.c b/test/Sema/vector-ops.c index 20575ec510c31..ca397375d7392 100644 --- a/test/Sema/vector-ops.c +++ b/test/Sema/vector-ops.c @@ -12,6 +12,9 @@ void test1(v2u v2ua, v2s v2sa, v2f v2fa) { (void)(~v2ua); (void)(~v2fa); // expected-error{{invalid argument type 'v2f' to unary}} + // Comparison operators + v2ua = (v2ua==v2sa); + // Arrays int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u'}} int array2[17]; diff --git a/test/Sema/warn-gnu-designators.c b/test/Sema/warn-gnu-designators.c index d5ac8cfe55394..bdb3374288df0 100644 --- a/test/Sema/warn-gnu-designators.c +++ b/test/Sema/warn-gnu-designators.c @@ -1,2 +1,2 @@ // RUN: %clang_cc1 -Wno-gnu-designator -verify %s -struct { int x, y, z[12] } value = { x:17, .z [3 ... 5] = 7 }; +struct { int x, y, z[12]; } value = { x:17, .z [3 ... 5] = 7 }; diff --git a/test/Sema/warn-unused-function.c b/test/Sema/warn-unused-function.c index 5bbcf18a623d9..8f4cdcba881e4 100644 --- a/test/Sema/warn-unused-function.c +++ b/test/Sema/warn-unused-function.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -Wunused-function -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wunused-function -Wunneeded-internal-declaration -verify %s // RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s // RUN: %clang_cc1 -fsyntax-only -verify -Wall %s @@ -6,7 +6,7 @@ void foo() {} static void f2() {} static void f1() {f2();} // expected-warning{{unused}} -static int f0() { return 17; } // expected-warning{{unused}} +static int f0() { return 17; } // expected-warning{{not needed and will not be emitted}} int x = sizeof(f0()); static void f3(); @@ -46,7 +46,7 @@ static void f12(void) { } // expected-warning{{unused}} static void f12(void); // PR7923 -static void unused(void) { unused(); } // expected-warning{{unused}} +static void unused(void) { unused(); } // expected-warning{{not needed and will not be emitted}} // rdar://8728293 static void cleanupMalloc(char * const * const allocation) { } diff --git a/test/Sema/warn-unused-value.c b/test/Sema/warn-unused-value.c index 876eb9e4823e5..95cd8fb704002 100644 --- a/test/Sema/warn-unused-value.c +++ b/test/Sema/warn-unused-value.c @@ -72,6 +72,15 @@ int test_logical_bar() { return x; } +// PR8282 +void conditional_for_control_flow(int cond, int x, int y) +{ + cond? y++ : x; // no-warning + cond? y : ++x; // no-warning + cond? (x |= y) : ++x; // no-warning + cond? y : x; // expected-warning {{expression result unused}} +} + struct s0 { int f0; }; void f0(int a); diff --git a/test/Sema/warn-write-strings.c b/test/Sema/warn-write-strings.c index dd0bb8a6d83a4..dee554cf6b575 100644 --- a/test/Sema/warn-write-strings.c +++ b/test/Sema/warn-write-strings.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s +// RUN: %clang_cc1 -verify -fsyntax-only -fconst-strings %s // PR4804 char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'const char [4]' discards qualifiers}} |