diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-04 15:04:32 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-04 15:04:32 +0000 |
commit | 51fb8b013e7734b795139f49d3b1f77c539be20a (patch) | |
tree | 59e0e47a9831dcf0e21e547927c8ebb7e113bfd1 /test/Sema | |
parent | 73490b890977362d28dd6326843a1ecae413921d (diff) |
Notes
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/attr-deprecated.c | 57 | ||||
-rw-r--r-- | test/Sema/callingconv.c | 9 | ||||
-rw-r--r-- | test/Sema/constant-builtins-2.c | 2 | ||||
-rw-r--r-- | test/Sema/decl-invalid.c | 3 | ||||
-rw-r--r-- | test/Sema/format-strings.c | 6 | ||||
-rw-r--r-- | test/Sema/init.c | 2 | ||||
-rw-r--r-- | test/Sema/offsetof.c | 6 | ||||
-rw-r--r-- | test/Sema/parentheses.c | 20 | ||||
-rw-r--r-- | test/Sema/return-noreturn.c | 8 | ||||
-rw-r--r-- | test/Sema/return.c | 4 | ||||
-rw-r--r-- | test/Sema/statements.c | 6 | ||||
-rw-r--r-- | test/Sema/stdcall-fastcall.c | 4 | ||||
-rw-r--r-- | test/Sema/vector-init.c | 4 |
13 files changed, 123 insertions, 8 deletions
diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index e15381e4c6d1..4b889fc8aa4f 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -43,3 +43,60 @@ void test1(struct foo *F) { typedef struct foo foo_dep __attribute__((deprecated)); foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}} + +struct bar_dep __attribute__((deprecated, + invalid_attribute)); // expected-warning {{'invalid_attribute' attribute ignored}} + +struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}} + + +// These should not warn because the actually declaration itself is deprecated. +// rdar://6756623 +foo_dep *test4 __attribute__((deprecated)); +struct bar_dep *test5 __attribute__((deprecated)); + +typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \ + // expected-warning {{'bar_dep' is deprecated}} +typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated)); + +int test8(char *p) { + p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} + + foo_dep *ptr; // expected-warning {{'foo_dep' is deprecated}} + ptr = (foo_dep*) p; // expected-warning {{'foo_dep' is deprecated}} + + int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} + return func(ptr); +} + +foo_dep *test9(void) __attribute__((deprecated)); +foo_dep *test9(void) { + void* myalloc(unsigned long); + + foo_dep *ptr + = (foo_dep*) + myalloc(sizeof(foo_dep)); + return ptr; +} + +void test10(void) __attribute__((deprecated)); +void test10(void) { + if (sizeof(foo_dep) == sizeof(void*)) { + } + foo_dep *localfunc(void); + foo_dep localvar; +} + +char test11[sizeof(foo_dep)] __attribute__((deprecated)); +char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}} + +int test13(foo_dep *foo) __attribute__((deprecated)); +int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} + +unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} +unsigned long test16 __attribute__((deprecated)) + = sizeof(foo_dep); + +foo_dep test17, // expected-warning {{'foo_dep' is deprecated}} + test18 __attribute__((deprecated)), + test19; diff --git a/test/Sema/callingconv.c b/test/Sema/callingconv.c index cb69c59c403a..102115b3bf2b 100644 --- a/test/Sema/callingconv.c +++ b/test/Sema/callingconv.c @@ -8,3 +8,12 @@ void __attribute__((stdcall)) bar(float *a) { void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{attribute requires 0 argument(s)}} } + +void __attribute__((fastcall)) test0() { // expected-error {{function with no prototype cannot use 'fastcall' calling convention}} +} + +void __attribute__((fastcall)) test1(void) { +} + +void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic function cannot use 'fastcall' calling convention}} +} diff --git a/test/Sema/constant-builtins-2.c b/test/Sema/constant-builtins-2.c index 146d9e9bb92b..18dbb1e7c54a 100644 --- a/test/Sema/constant-builtins-2.c +++ b/test/Sema/constant-builtins-2.c @@ -48,3 +48,5 @@ extern int f(); int h0 = __builtin_types_compatible_p(int, float); //int h1 = __builtin_choose_expr(1, 10, f()); //int h2 = __builtin_expect(0, 0); +extern long int bi0; +extern __typeof__(__builtin_expect(0, 0)) bi0; diff --git a/test/Sema/decl-invalid.c b/test/Sema/decl-invalid.c index 051f0f7ffbcc..823551f02e6f 100644 --- a/test/Sema/decl-invalid.c +++ b/test/Sema/decl-invalid.c @@ -10,8 +10,7 @@ int a() { int r[x()]; // expected-error {{size of array has non-integer type 'void'}} static y ?; // expected-error{{unknown type name 'y'}} \ - expected-error{{expected identifier or '('}} \ - expected-error{{expected ';' at end of declaration}} + expected-error{{expected identifier or '('}} } int; // expected-error {{declaration does not declare anything}} diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 1826c7457e30..797e53c1bd22 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -8,6 +8,10 @@ char * global_fmt; +#if defined(_WIN32) || defined(_WIN64) +extern int snprintf(char*, size_t, const char*, ...); +#endif + void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { char * b; @@ -83,7 +87,7 @@ void check_wide_string(char* b, ...) va_start(ap,b); printf(L"foo %d",2); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}} - vasprintf(&b,L"bar %d",ap); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}} + vsprintf(b,L"bar %d",ap); // expected-warning {{incompatible pointer types}}, expected-warning {{should not be a wide string}} } void check_asterisk_precision_width(int x) { diff --git a/test/Sema/init.c b/test/Sema/init.c index 1cbcbb7e36f8..840b24fd30b0 100644 --- a/test/Sema/init.c +++ b/test/Sema/init.c @@ -21,7 +21,7 @@ int *h = &x; int test() { int a[10]; int b[10] = a; // expected-error {{initialization with '{...}' expected}} -int +; // expected-error {{expected identifier or '('}} expected-error {{expected ';' at end of declaration}} +int +; // expected-error {{expected identifier or '('}} } diff --git a/test/Sema/offsetof.c b/test/Sema/offsetof.c index f8b9fed03c3c..dfae99216f8a 100644 --- a/test/Sema/offsetof.c +++ b/test/Sema/offsetof.c @@ -48,3 +48,9 @@ int a[__builtin_offsetof(struct sockaddr_un, sun_path[len+1])]; // PR4079 union x {struct {int x;};}; int x[__builtin_offsetof(union x, x)]; + +// rdar://problem/7222956 +struct incomplete; // expected-note 2 {{forward declaration of 'struct incomplete'}} +int test1[__builtin_offsetof(struct incomplete, foo)]; // expected-error {{offsetof of incomplete type 'struct incomplete'}} + +int test1[__builtin_offsetof(struct incomplete[10], [4].foo)]; // expected-error {{array has incomplete element type 'struct incomplete'}} diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c new file mode 100644 index 000000000000..a8ad260bf8b5 --- /dev/null +++ b/test/Sema/parentheses.c @@ -0,0 +1,20 @@ +// RUN: clang-cc -Wparentheses -fsyntax-only -verify %s && +// RUN: clang-cc -Wparentheses -fixit %s -o - | clang-cc -Wparentheses -Werror - + +// Test the various warnings under -Wparentheses +void if_assign(void) { + int i; + if (i = 4) {} // expected-warning {{assignment as a condition}} + if ((i = 4)) {} +} + +void bitwise_rel(unsigned i) { + (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} + (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}} + (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}} + (void)((i & 0x2) == 0); + (void)(i & (0x2 == 0)); + // Eager logical op + (void)(i == 1 | i == 2 | i == 3); + (void)(i != 1 & i != 2 & i != 3); +} diff --git a/test/Sema/return-noreturn.c b/test/Sema/return-noreturn.c index e2452f407f4f..8868c9ee0aeb 100644 --- a/test/Sema/return-noreturn.c +++ b/test/Sema/return-noreturn.c @@ -27,3 +27,11 @@ __attribute__((__noreturn__)) void* test3(int arg) { __attribute__((__noreturn__)) void* test3_positive(int arg) { while (0) foo_test_3(); } // expected-warning{{function declared 'noreturn' should not return}} + + +// PR5298 - -Wmissing-noreturn shouldn't warn if the function is already +// declared noreturn. +void __attribute__((noreturn)) +test4() { + test2_positive(); +} diff --git a/test/Sema/return.c b/test/Sema/return.c index 64def306ebc8..cdd31059b3e7 100644 --- a/test/Sema/return.c +++ b/test/Sema/return.c @@ -203,7 +203,11 @@ int test30() { if (j) longjmp(test30_j, 1); else +#if defined(_WIN32) || defined(_WIN64) + longjmp(test30_j, 2); +#else _longjmp(test30_j, 1); +#endif } typedef void test31_t(int status); diff --git a/test/Sema/statements.c b/test/Sema/statements.c index 9a71a403700d..8eac052a25c7 100644 --- a/test/Sema/statements.c +++ b/test/Sema/statements.c @@ -27,3 +27,9 @@ int test8[({10;})]; // expected-error {{statement expression not allowed at file void test9(const void *P) { __builtin_prefetch(P); } + + +void *test10() { +bar: + return &&bar; // expected-warning {{returning address of label, which is local}} +} diff --git a/test/Sema/stdcall-fastcall.c b/test/Sema/stdcall-fastcall.c index 353bbfc25297..e0db63822fb3 100644 --- a/test/Sema/stdcall-fastcall.c +++ b/test/Sema/stdcall-fastcall.c @@ -5,6 +5,6 @@ int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' attribute only int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' attribute only applies to function types}} // Different CC qualifiers are not compatible -void __attribute__((stdcall, fastcall)) foo3(); // expected-error{{stdcall and fastcall attributes are not compatible}} +void __attribute__((stdcall, fastcall)) foo3(void); // expected-error{{stdcall and fastcall attributes are not compatible}} void __attribute__((stdcall)) foo4(); -void __attribute__((fastcall)) foo4(); // expected-error{{fastcall and stdcall attributes are not compatible}} +void __attribute__((fastcall)) foo4(void); // expected-error{{fastcall and stdcall attributes are not compatible}} diff --git a/test/Sema/vector-init.c b/test/Sema/vector-init.c index 18104d871d6c..9dac6c7114da 100644 --- a/test/Sema/vector-init.c +++ b/test/Sema/vector-init.c @@ -8,7 +8,7 @@ float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 }; float4 foo2 = (float4){ 1.0, 2.0, 3.0, 4.0 , 5.0 }; // expected-warning{{excess elements in vector initializer}} float4 array[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; -int array_sizecheck[(sizeof(array) / sizeof(float4)) == 3? 1 : -1]; +int array_sizecheck[(sizeof(array) / sizeof(float4)) == 3 ? 1 : -1]; float4 array2[2] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; // expected-warning {{excess elements in array initializer}} @@ -26,5 +26,5 @@ float f1(void) { // PR5265 typedef float __attribute__((ext_vector_type (3))) float3; -int test2[(sizeof(float3) == sizeof(float4))*2-1]; +int test2[sizeof(float3) == sizeof(float4) ? 1 : -1]; |