diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-02-16 09:31:36 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-02-16 09:31:36 +0000 |
commit | fd035e6496665b1f1197868e21cb0a4594e8db6e (patch) | |
tree | 53010172e19c77ea447bcd89e117cda052ab52e0 /test/Sema | |
parent | 2fce988e86bc01829142e4362d4eff1af0925147 (diff) | |
download | FreeBSD-src-fd035e6496665b1f1197868e21cb0a4594e8db6e.zip FreeBSD-src-fd035e6496665b1f1197868e21cb0a4594e8db6e.tar.gz |
Update clang to r96341.
Diffstat (limited to 'test/Sema')
31 files changed, 404 insertions, 37 deletions
diff --git a/test/Sema/Inputs/conversion.h b/test/Sema/Inputs/conversion.h new file mode 100644 index 0000000..9f6ed2e --- /dev/null +++ b/test/Sema/Inputs/conversion.h @@ -0,0 +1,3 @@ +/* Fake system header for Sema/conversion.c */ + +#define LONG_MAX __LONG_MAX__ diff --git a/test/Sema/arm-layout.c b/test/Sema/arm-layout.c new file mode 100644 index 0000000..1e239d2 --- /dev/null +++ b/test/Sema/arm-layout.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi apcs-gnu %s -verify +// RUN: %clang_cc1 -triple armv7-unknown-unknown -target-abi aapcs %s -verify + +#ifdef __ARM_EABI__ + +struct s0 { char field0; double field1; }; +int g0[sizeof(struct s0) == 16 ? 1 : -1]; + +struct s1 { char field0; long double field1; }; +int g1[sizeof(struct s1) == 16 ? 1 : -1]; + +#else + +struct s0 { char field0; double field1; }; +int g0[sizeof(struct s0) == 12 ? 1 : -1]; + +struct s1 { char field0; long double field1; }; +int g1[sizeof(struct s1) == 12 ? 1 : -1]; + +#endif diff --git a/test/Sema/asm.c b/test/Sema/asm.c index 18d900c..6f2272d 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -76,3 +76,6 @@ int test7(unsigned long long b) { asm volatile("foo %0 %1" : "=a" (a) :"0" (b)); // expected-error {{input with type 'unsigned long long' matching output with type 'int'}} return a; } + +// <rdar://problem/7574870> +asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}} diff --git a/test/Sema/attr-mode.c b/test/Sema/attr-mode.c index 9acd2c6..0c53362 100644 --- a/test/Sema/attr-mode.c +++ b/test/Sema/attr-mode.c @@ -1,4 +1,7 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -DTEST_32BIT_X86 -fsyntax-only \ +// RUN: -verify %s +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -DTEST_64BIT_X86 -fsyntax-only \ +// RUN: -verify %s typedef int i16_1 __attribute((mode(HI))); int i16_1_test[sizeof(i16_1) == 2 ? 1 : -1]; @@ -20,3 +23,37 @@ typedef _Complex double c32 __attribute((mode(SC))); int c32_test[sizeof(c32) == 8 ? 1 : -1]; typedef _Complex float c64 __attribute((mode(DC))); typedef _Complex float c80 __attribute((mode(XC))); + +// PR6108: Correctly select 'long' built in type on 64-bit platforms for 64 bit +// modes. Also test other mode-based conversions. +typedef int i8_mode_t __attribute__ ((__mode__ (__QI__))); +typedef unsigned int ui8_mode_t __attribute__ ((__mode__ (__QI__))); +typedef int i16_mode_t __attribute__ ((__mode__ (__HI__))); +typedef unsigned int ui16_mode_t __attribute__ ((__mode__ (__HI__))); +typedef int i32_mode_t __attribute__ ((__mode__ (__SI__))); +typedef unsigned int ui32_mode_t __attribute__ ((__mode__ (__SI__))); +typedef int i64_mode_t __attribute__ ((__mode__ (__DI__))); +typedef unsigned int ui64_mode_t __attribute__ ((__mode__ (__DI__))); +void f_i8_arg(i8_mode_t* x) { (void)x; } +void f_ui8_arg(ui8_mode_t* x) { (void)x; } +void f_i16_arg(i16_mode_t* x) { (void)x; } +void f_ui16_arg(ui16_mode_t* x) { (void)x; } +void f_i32_arg(i32_mode_t* x) { (void)x; } +void f_ui32_arg(ui32_mode_t* x) { (void)x; } +void f_i64_arg(i64_mode_t* x) { (void)x; } +void f_ui64_arg(ui64_mode_t* x) { (void)x; } +void test_char_to_i8(signed char* y) { f_i8_arg(y); } +void test_char_to_ui8(unsigned char* y) { f_ui8_arg(y); } +void test_short_to_i16(short* y) { f_i16_arg(y); } +void test_short_to_ui16(unsigned short* y) { f_ui16_arg(y); } +void test_int_to_i32(int* y) { f_i32_arg(y); } +void test_int_to_ui32(unsigned int* y) { f_ui32_arg(y); } +#if TEST_32BIT_X86 +void test_long_to_i64(long long* y) { f_i64_arg(y); } +void test_long_to_ui64(unsigned long long* y) { f_ui64_arg(y); } +#elif TEST_64BIT_X86 +void test_long_to_i64(long* y) { f_i64_arg(y); } +void test_long_to_ui64(unsigned long* y) { f_ui64_arg(y); } +#else +#error Unknown test architecture. +#endif diff --git a/test/Sema/attr-noreturn.c b/test/Sema/attr-noreturn.c index 3f064a0..b17f9fd 100644 --- a/test/Sema/attr-noreturn.c +++ b/test/Sema/attr-noreturn.c @@ -11,7 +11,7 @@ static void __attribute__((noreturn)) f0(void) { // On K&R int f1() __attribute__((noreturn)); -int g0 __attribute__((noreturn)); // expected-warning {{'noreturn' attribute only applies to function types}} +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)}} diff --git a/test/Sema/block-args.c b/test/Sema/block-args.c index 08af9b3..a07c82e 100644 --- a/test/Sema/block-args.c +++ b/test/Sema/block-args.c @@ -27,3 +27,9 @@ int main(int argc, char** argv) { argCount = 3; }(argc); } + +// radar 7528255 +void f0() { + ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \ + // expected-error {{parameter name omitted}} +} diff --git a/test/Sema/block-printf-attribute-1.c b/test/Sema/block-printf-attribute-1.c index 8ea77ec..c19b378 100644 --- a/test/Sema/block-printf-attribute-1.c +++ b/test/Sema/block-printf-attribute-1.c @@ -6,7 +6,6 @@ int main() { void (^z) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 2, 3))) = ^ __attribute__ ((__format__ (__printf__, 2, 3))) (int arg, const char * format, ...) {}; - // FIXME: argument type poking not yet supportted. - z(1, "%s", 1); /* { dg-warning "format \\'\%s\\' expects type \\'char \\*\\'\, but argument 3 has type \\'int\\'" } */ - z(1, "%s", "HELLO"); // OK + z(1, "%s", 1); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} + z(1, "%s", "HELLO"); // no-warning } diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index 6416545..2385106 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -109,7 +109,7 @@ void foo6() { void foo7() { - const int (^BB) (void) = ^{ const int i = 1; return i; }; // OK + const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int (^)(void)', expected 'int const (^)(void)'}} const int (^CC) (void) = ^const int{ const int i = 1; return i; }; // OK int i; @@ -123,9 +123,8 @@ void foo7() __block const int k; const int cint = 100; - int (^MM) (void) = ^{ return k; }; // expected-error {{incompatible block pointer types initializing 'int const (^)(void)', expected 'int (^)(void)'}} - int (^NN) (void) = ^{ return cint; }; // expected-error {{incompatible block pointer types initializing 'int const (^)(void)', expected 'int (^)(void)'}} - + int (^MM) (void) = ^{ return k; }; + int (^NN) (void) = ^{ return cint; }; } diff --git a/test/Sema/builtin-unary-fp.c b/test/Sema/builtin-unary-fp.c index 8f48d7f..57568db 100644 --- a/test/Sema/builtin-unary-fp.c +++ b/test/Sema/builtin-unary-fp.c @@ -9,4 +9,8 @@ void a() { check(__builtin_isfinite(1)); // expected-error{{requires argument of floating point type}} check(__builtin_isinf()); // expected-error{{too few arguments}} check(__builtin_isnan(1,2)); // expected-error{{too many arguments}} + check(__builtin_fpclassify(0, 0, 0, 0, 0, 1.0)); + check(__builtin_fpclassify(0, 0, 0, 0, 0, 1)); // expected-error{{requires argument of floating point type}} + check(__builtin_fpclassify(0, 0, 0, 0, 1)); // expected-error{{too few arguments}} + check(__builtin_fpclassify(0, 0, 0, 0, 0, 1, 0)); // expected-error{{too many arguments}} } diff --git a/test/Sema/callingconv.c b/test/Sema/callingconv.c index a32a495..0752606 100644 --- a/test/Sema/callingconv.c +++ b/test/Sema/callingconv.c @@ -9,15 +9,30 @@ 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)) 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}} +void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic function cannot use fastcall calling convention}} } void __attribute__((cdecl)) ctest0() {} void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{attribute requires 0 argument(s)}} + +void (__attribute__((fastcall)) *pfoo)(float*) = foo; + +void (__attribute__((stdcall)) *pbar)(float*) = bar; + +void (__attribute__((cdecl)) *ptest1)(void) = test1; // expected-warning {{incompatible pointer types}} + +void (*pctest0)() = ctest0; + +void ctest2() {} +void (__attribute__((cdecl)) *pctest2)() = ctest2; + +typedef void (__attribute__((fastcall)) *Handler) (float *); +Handler H = foo; + diff --git a/test/Sema/compare.c b/test/Sema/compare.c index 579c3e5..2821a93 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s -Wno-unreachable-code int test(char *C) { // nothing here should warn. return C != ((void*)0); diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index fee8d97..9c53725 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -75,3 +75,4 @@ EVAL_EXPR(35, constbool) EVAL_EXPR(36, constbool) EVAL_EXPR(37, (1,2.0) == 2.0) +EVAL_EXPR(38, __builtin_expect(1,1) == 1) diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 298bf75..8b93a46 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wconversion -triple x86_64-apple-darwin %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wconversion -nostdinc -isystem %S/Inputs -triple x86_64-apple-darwin %s -Wno-unreachable-code + +#include <conversion.h> #define BIG 0x7f7f7f7f7f7f7f7fL @@ -271,3 +273,9 @@ unsigned char test19(unsigned long u64) { unsigned char x3 = u64 & mask; return x1 + x2 + x3; } + +// <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 cast loses integer precision: 'long' to 'char'}} +} diff --git a/test/Sema/declspec.c b/test/Sema/declspec.c index 5b11960..d9f4157 100644 --- a/test/Sema/declspec.c +++ b/test/Sema/declspec.c @@ -7,11 +7,13 @@ void foof(const char *, ...) __attribute__((__format__(__printf__, 1, 2))), barf int typedef validTypeDecl() { } // expected-error {{function definition declared 'typedef'}} -struct _zend_module_entry { } -typedef struct _zend_function_entry { } // expected-error {{cannot combine with previous 'struct' declaration specifier}} -static void buggy(int *x) { } // expected-error {{function definition declared 'typedef'}} \ - // expected-error {{cannot combine with previous 'typedef' declaration specifier}} \ - // expected-error {{cannot combine with previous 'struct' declaration specifier}} +struct _zend_module_entry { } // expected-error {{expected ';' after struct}} +int gv1; +typedef struct _zend_function_entry { } // expected-error {{expected ';' after struct}} \ + // expected-error {{declaration does not declare anything}} +int gv2; + +static void buggy(int *x) { } // Type qualifiers. typedef int f(void); @@ -22,3 +24,10 @@ __restrict__ fptr v3; // expected-error {{pointer to function type 'f' (aka 'int f *__restrict__ v4; // expected-error {{pointer to function type 'f' (aka 'int (void)') may not be 'restrict' qualified}} restrict struct hallo; // expected-error {{restrict requires a pointer or reference}} + +// PR6180 +struct test1 { +} // expected-error {{expected ';' after struct}} + +void test2() {} + diff --git a/test/Sema/enum.c b/test/Sema/enum.c index 916de41..9b46500 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -92,3 +92,7 @@ typedef enum { } an_enum; // FIXME: why is this only a warning? char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'an_enum', expected 'char *'}} + +// PR4515 +enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2}; +int CheckPR4515[PR4515b==0?1:-1]; diff --git a/test/Sema/format-string-percentm.c b/test/Sema/format-string-percentm.c index f2e9dd8..1ffc439 100644 --- a/test/Sema/format-string-percentm.c +++ b/test/Sema/format-string-percentm.c @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -triple i686-pc-linux-gnu +// PR 4142 - support glibc extension to printf: '%m' (which prints strerror(errno)). int printf(char const*,...); void percentm(void) { printf("%m"); diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 20e4dcd..f1fa658 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -40,18 +40,22 @@ void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { // rdar://6079877 printf("abc" - "%*d", (unsigned) 1, 1); // expected-warning {{field width should have type 'int'}} + "%*d", 1, 1); // no-warning printf("abc\ def" - "%*d", (unsigned) 1, 1); // expected-warning {{field width should have type 'int'}} - + "%*d", 1, 1); // no-warning + + // <rdar://problem/6079850>, allow 'unsigned' (instead of 'int') to be used for both + // the field width and precision. This deviates from C99, but is reasonably safe + // and is also accepted by GCC. + printf("%*d", (unsigned) 1, 1); // no-warning } void check_conditional_literal(const char* s, int i) { printf(i == 1 ? "yes" : "no"); // no-warning printf(i == 0 ? (i == 1 ? "yes" : "no") : "dont know"); // no-warning printf(i == 0 ? (i == 1 ? s : "no") : "dont know"); // expected-warning{{format string is not a string literal}} - printf("yes" ?: "no %d", 1); // expected-warning{{more data arguments than '%' conversions}} + printf("yes" ?: "no %d", 1); // expected-warning{{more data arguments than format specifiers}} } void check_writeback_specifier() @@ -65,10 +69,10 @@ void check_writeback_specifier() void check_invalid_specifier(FILE* fp, char *buf) { - printf("%s%lb%d","unix",10,20); // expected-warning {{lid conversion '%lb'}} - fprintf(fp,"%%%l"); // expected-warning {{lid conversion '%l'}} - sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // no-warning - snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning {{sion '%;'}} + printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion specifier 'b'}} + fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}} + sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // expected-warning{{conversion specifies type 'long' but the argument has type 'int'}} + snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning{{conversion specifies type 'long' but the argument has type 'int'}} expected-warning {{invalid conversion specifier ';'}} } void check_null_char_string(char* b) @@ -137,5 +141,66 @@ void test9(char *P) { void torture(va_list v8) { vprintf ("%*.*d", v8); // no-warning + +} + +void test10(int x, float f, int i, long long lli) { + printf("%@", 12); // expected-warning{{invalid conversion specifier '@'}} + printf("\0"); // expected-warning{{format string contains '\0' within the string body}} + printf("xs\0"); // expected-warning{{format string contains '\0' within the string body}} + printf("%*d\n"); // expected-warning{{'*' specified field width is missing a matching 'int' argument}} + printf("%*.*d\n", x); // expected-warning{{'.*' specified field precision is missing a matching 'int' argument}} + printf("%*d\n", f, x); // expected-warning{{field width should have type 'int', but argument has type 'double'}} + printf("%*.*d\n", x, f, x); // expected-warning{{field precision should have type 'int', but argument has type 'double'}} + printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}} + printf("%n", &i); // expected-warning{{use of '%n' in format string discouraged (potentially insecure)}} + printf("%d%d\n", x); // expected-warning{{more '%' conversions than data arguments}} + printf("%d\n", x, x); // expected-warning{{more data arguments than format specifiers}} + printf("%W%d%Z\n", x, x, x); // expected-warning{{invalid conversion specifier 'W'}} expected-warning{{invalid conversion specifier 'Z'}} + printf("%"); // expected-warning{{incomplete format specifier}} + printf("%.d", x); // no-warning + printf("%.", x); // expected-warning{{incomplete format specifier}} + printf("%f", 4); // expected-warning{{conversion specifies type 'double' but the argument has type 'int'}} + printf("%qd", lli); + printf("hhX %hhX", (unsigned char)10); // no-warning + printf("llX %llX", (long long) 10); // no-warning + // This is fine, because there is an implicit conversion to an int. + printf("%d", (unsigned char) 10); // no-warning + printf("%d", (long long) 10); // expected-warning{{conversion specifies type 'int' but the argument has type 'long long'}} + printf("%Lf\n", (long double) 1.0); // no-warning + printf("%f\n", (long double) 1.0); // expected-warning{{conversion specifies type 'double' but the argument has type 'long double'}} +} + +void test11(void *p, char *s) { + printf("%p", p); // no-warning + printf("%.4p", p); // expected-warning{{precision used in 'p' conversion specifier (where it has no meaning)}} + printf("%+p", p); // expected-warning{{flag '+' results in undefined behavior in 'p' conversion specifier}} + printf("% p", p); // expected-warning{{flag ' ' results in undefined behavior in 'p' conversion specifier}} + printf("%0p", p); // expected-warning{{flag '0' results in undefined behavior in 'p' conversion specifier}} + printf("%s", s); // no-warning + printf("%+s", p); // expected-warning{{flag '+' results in undefined behavior in 's' conversion specifier}} + printf("% s", p); // expected-warning{{flag ' ' results in undefined behavior in 's' conversion specifier}} + printf("%0s", p); // expected-warning{{flag '0' results in undefined behavior in 's' conversion specifier}} +} + +void test12(char *b) { + unsigned char buf[4]; + printf ("%.4s\n", buf); // no-warning + printf ("%.4s\n", &buf); // expected-warning{{conversion specifies type 'char *' but the argument has type 'unsigned char (*)[4]'}} + + // Verify that we are checking asprintf + asprintf(&b, "%d", "asprintf"); // expected-warning{{conversion specifies type 'int' but the argument has type 'char *'}} +} + +typedef struct __aslclient *aslclient; +typedef struct __aslmsg *aslmsg; +int asl_log(aslclient asl, aslmsg msg, int level, const char *format, ...) __attribute__((__format__ (__printf__, 4, 5))); +void test_asl(aslclient asl) { + // Test case from <rdar://problem/7341605>. + asl_log(asl, 0, 3, "Error: %m"); // no-warning + asl_log(asl, 0, 3, "Error: %W"); // expected-warning{{invalid conversion specifier 'W'}} } +// <rdar://problem/7595366> +typedef enum { A } int_t; +void f0(int_t x) { printf("%d\n", x); } diff --git a/test/Sema/function-redecl.c b/test/Sema/function-redecl.c index 9544dc9..1302b34 100644 --- a/test/Sema/function-redecl.c +++ b/test/Sema/function-redecl.c @@ -125,3 +125,7 @@ void test_x() { x(5); x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int', expected 'int *'}} } + +enum e0 {}; +void f3(); +void f3(enum e0 x) {} diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c index 753d9c0..e5b6d5f 100644 --- a/test/Sema/incomplete-decl.c +++ b/test/Sema/incomplete-decl.c @@ -16,7 +16,7 @@ int ary[]; // expected-warning {{tentative array definition assumed to have one struct foo bary[]; // expected-error {{array has incomplete element type 'struct foo'}} void func() { - int ary[]; // expected-error{{variable has incomplete type 'int []'}} + int ary[]; // expected-error{{definition of variable with array type needs an explicit size or an initializer}} void b; // expected-error {{variable has incomplete type 'void'}} struct foo f; // expected-error {{variable has incomplete type 'struct foo'}} } diff --git a/test/Sema/indirect-goto.c b/test/Sema/indirect-goto.c index 134ccd8..4c1c6c3 100644 --- a/test/Sema/indirect-goto.c +++ b/test/Sema/indirect-goto.c @@ -2,6 +2,9 @@ struct c {int x;}; int a(struct c x, long long y) { + void const* l1_ptr = &&l1; + goto *l1_ptr; +l1: goto *x; // expected-error{{incompatible type}} goto *y; // expected-warning{{incompatible integer to pointer conversion}} } diff --git a/test/Sema/return-noreturn.c b/test/Sema/return-noreturn.c index 198ab11..ff43754 100644 --- a/test/Sema/return-noreturn.c +++ b/test/Sema/return-noreturn.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn +// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wmissing-noreturn -Wno-unreachable-code int j; void test1() { // expected-warning {{function could be attribute 'noreturn'}} diff --git a/test/Sema/return.c b/test/Sema/return.c index 17d2178..5d1c97f 100644 --- a/test/Sema/return.c +++ b/test/Sema/return.c @@ -1,4 +1,4 @@ -// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks +// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wno-unreachable-code // clang emits the following warning by default. // With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the diff --git a/test/Sema/scope-check.c b/test/Sema/scope-check.c index 74bc7c4..7d293f2 100644 --- a/test/Sema/scope-check.c +++ b/test/Sema/scope-check.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=gnu99 %s +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=gnu99 %s -Wno-unreachable-code int test1(int x) { goto L; // expected-error{{illegal goto into protected scope}} diff --git a/test/Sema/statements.c b/test/Sema/statements.c index 3cd2460..6da2daa 100644 --- a/test/Sema/statements.c +++ b/test/Sema/statements.c @@ -33,3 +33,11 @@ void *test10() { bar: return &&bar; // expected-warning {{returning address of label, which is local}} } + +// PR6034 +void test11(int bit) { + switch (bit) + switch (env->fpscr) // expected-error {{use of undeclared identifier 'env'}} + { + } +} diff --git a/test/Sema/stdcall-fastcall.c b/test/Sema/stdcall-fastcall.c index c45f93e..a069526 100644 --- a/test/Sema/stdcall-fastcall.c +++ b/test/Sema/stdcall-fastcall.c @@ -1,10 +1,10 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // CC qualifier can be applied only to functions -int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' attribute only applies to function types}} -int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' attribute only applies to function types}} +int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies to function types; type here is 'int'}} +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)) foo4(); -void __attribute__((fastcall)) foo4(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'}} diff --git a/test/Sema/switch.c b/test/Sema/switch.c index 08ab0e0..2690ad2 100644 --- a/test/Sema/switch.c +++ b/test/Sema/switch.c @@ -85,3 +85,141 @@ int f0(int var) { // expected-note{{'var' declared here}} } return 2; } + +void test7() { + enum { + A = 1, + B + } a; + switch(a) { //expected-warning{{enumeration value 'B' not handled in switch}} + case A: + break; + } + switch(a) { + case B: + case A: + break; + } + switch(a) { + case A: + case B: + case 3: // expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case A: + case B: + case 3 ... //expected-warning{{case value not in enumerated type ''}} + 4: //expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case 1 ... 2: + break; + } + switch(a) { + case 0 ... 2: //expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case 1 ... 3: //expected-warning{{case value not in enumerated type ''}} + break; + } + switch(a) { + case 0 ... //expected-warning{{case value not in enumerated type ''}} + 3: //expected-warning{{case value not in enumerated type ''}} + break; + } + +} + +void test8() { + enum { + A, + B, + C = 1 + } a; + switch(a) { + case A: + case B: + break; + } + switch(a) { + case A: + case C: + break; + } + switch(a) { //expected-warning{{enumeration value 'B' not handled in switch}} + case A: + break; + } +} + +void test9() { + enum { + A = 3, + C = 1 + } a; + switch(a) { + case 0: //expected-warning{{case value not in enumerated type ''}} + case 1: + case 2: //expected-warning{{case value not in enumerated type ''}} + case 3: + case 4: //expected-warning{{case value not in enumerated type ''}} + break; + } +} + +void test10() { + enum { + A = 10, + C = 2, + B = 4, + D = 12 + } a; + switch(a) { + case 0 ... //expected-warning{{case value not in enumerated type ''}} + 1: //expected-warning{{case value not in enumerated type ''}} + case 2 ... 4: + case 5 ... //expected-warning{{case value not in enumerated type ''}} + 9: //expected-warning{{case value not in enumerated type ''}} + case 10 ... 12: + case 13 ... //expected-warning{{case value not in enumerated type ''}} + 16: //expected-warning{{case value not in enumerated type ''}} + break; + } +} + +void test11() { + enum { + A = -1, + B, + C + } a; + switch(a) { //expected-warning{{enumeration value 'A' not handled in switch}} + case B: + case C: + break; + } + + switch(a) { + case B: + case C: + break; + + default: + break; + } +} + +void test12() { + enum { + A = -1, + B = 4294967286 + } a; + switch(a) { + case A: + case B: + break; + } +} diff --git a/test/Sema/ucn-cstring.c b/test/Sema/ucn-cstring.c index f5bf457..ac1d37f 100644 --- a/test/Sema/ucn-cstring.c +++ b/test/Sema/ucn-cstring.c @@ -5,8 +5,8 @@ int printf(const char *, ...); int main(void) { int a[sizeof("hello \u2192 \u2603 \u2190 world") == 24 ? 1 : -1]; - printf("%s (%d)\n", "hello \u2192 \u2603 \u2190 world", sizeof("hello \u2192 \u2603 \u2190 world")); - printf("%s (%d)\n", "\U00010400\U0001D12B", sizeof("\U00010400\U0001D12B")); + printf("%s (%zd)\n", "hello \u2192 \u2603 \u2190 world", sizeof("hello \u2192 \u2603 \u2190 world")); + printf("%s (%zd)\n", "\U00010400\U0001D12B", sizeof("\U00010400\U0001D12B")); // Some error conditions... printf("%s\n", "\U"); // expected-error{{\u used with no following hex digits}} printf("%s\n", "\U00"); // expected-error{{incomplete universal character name}} diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c index 68503bd..4c6c47b 100644 --- a/test/Sema/unused-expr.c +++ b/test/Sema/unused-expr.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code int foo(int X, int Y); diff --git a/test/Sema/vla.c b/test/Sema/vla.c index 7ddd432..ebf9b88 100644 --- a/test/Sema/vla.c +++ b/test/Sema/vla.c @@ -54,3 +54,9 @@ int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}} const int f5_ci = 1; void f5() { char a[][f5_ci] = {""}; } // expected-error {{variable-sized object may not be initialized}} + +// PR5185 +void pr5185(int a[*]); +void pr5185(int a[*]) // expected-error {{variable length array must be bound in function definition}} +{ +} diff --git a/test/Sema/warn-unused-function.c b/test/Sema/warn-unused-function.c new file mode 100644 index 0000000..178527f --- /dev/null +++ b/test/Sema/warn-unused-function.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunused-function -verify %s + +void foo() {} +static void f2() {} +static void f1() {f2();} // expected-warning{{unused}} + +static int f0() { return 17; } // expected-warning{{unused}} +int x = sizeof(f0()); + +static void f3(); +extern void f3() { } // expected-warning{{unused}} + +// FIXME: This will trigger a warning when it should not. +// Update once PR6281 is fixed. +//inline static void f4(); +//void f4() { }
\ No newline at end of file diff --git a/test/Sema/x86-attr-force-align-arg-pointer.c b/test/Sema/x86-attr-force-align-arg-pointer.c new file mode 100644 index 0000000..9609fad --- /dev/null +++ b/test/Sema/x86-attr-force-align-arg-pointer.c @@ -0,0 +1,18 @@ +// 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}} + +// It doesn't matter where the attribute is located. +void b(void) __attribute__((force_align_arg_pointer)); +void __attribute__((force_align_arg_pointer)) c(void); + +// Functions only have to be declared force_align_arg_pointer once. +void b(void) {} + +// It doesn't matter which declaration has the attribute. +void d(void); +void __attribute__((force_align_arg_pointer)) d(void) {} + +// Attribute is ignored on function pointer types. +void (__attribute__((force_align_arg_pointer)) *p)(); //expected-warning{{force_align_arg_pointer used on function pointer; attribute ignored}} + |