diff options
Diffstat (limited to 'test/Sema')
35 files changed, 316 insertions, 74 deletions
diff --git a/test/Sema/arm-neon-types.c b/test/Sema/arm-neon-types.c index 1e8c9bf..4be83da 100644 --- a/test/Sema/arm-neon-types.c +++ b/test/Sema/arm-neon-types.c @@ -18,3 +18,10 @@ float32x2_t test3(uint32x2_t x) { // removed when that is fixed. return vcvt_n_f32_u32(x, 0); // expected-error {{argument should be a value from 1 to 32}} expected-error {{incompatible result type}} } + +typedef signed int vSInt32 __attribute__((__vector_size__(16))); +int32x4_t test4(int32x4_t a, vSInt32 b) { + a += b; + b += a; + return b += a; +} diff --git a/test/Sema/asm.c b/test/Sema/asm.c index d8161c8..359431c 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -5,7 +5,7 @@ void f() { asm ("foo\n" : : "a" (i + 2)); asm ("foo\n" : : "a" (f())); // expected-error {{invalid type 'void' in asm input}} - + asm ("foo\n" : "=a" (f())); // expected-error {{invalid lvalue in asm output}} asm ("foo\n" : "=a" (i + 2)); // expected-error {{invalid lvalue in asm output}} @@ -21,7 +21,7 @@ void clobbers() { asm ("nop" : : : "0", "%0", "#0"); asm ("nop" : : : "foo"); // expected-error {{unknown register name 'foo' in asm}} asm ("nop" : : : "52"); - asm ("nop" : : : "53"); // expected-error {{unknown register name '53' in asm}} + asm ("nop" : : : "54"); // expected-error {{unknown register name '54' in asm}} asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}} asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}} } @@ -47,7 +47,7 @@ void test4(const volatile void *addr) // <rdar://problem/6512595> void test5() { - asm("nop" : : "X" (8)); + asm("nop" : : "X" (8)); } // PR3385 @@ -56,7 +56,7 @@ void test6(long i) { } void asm_string_tests(int i) { - asm("%!"); // simple asm string, %! is not an error. + asm("%!"); // simple asm string, %! is not an error. asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}} asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}} @@ -64,7 +64,7 @@ void asm_string_tests(int i) { asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}} asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}} asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}} - + // PR3258 asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}} asm("%1" : "+r"(i)); // ok, referring to input. @@ -113,3 +113,13 @@ void test11(void) { _Bool b; asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L)); } + +void test12(void) { + register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}} +} + +// PR10223 +void test13(void) { + void *esp; + __asm__ volatile ("mov %%esp, %o" : "=r"(esp) : : ); // expected-error {{invalid % escape in inline assembly string}} +} diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c index b26171b..eeef0d7 100644 --- a/test/Sema/attr-deprecated.c +++ b/test/Sema/attr-deprecated.c @@ -37,6 +37,8 @@ struct foo { void test1(struct foo *F) { ++F->x; // expected-warning {{'x' is deprecated}} + struct foo f1 = { .x = 17 }; // expected-warning {{'x' is deprecated}} + struct foo f2 = { 17 }; // expected-warning {{'x' is deprecated}} } typedef struct foo foo_dep __attribute__((deprecated)); diff --git a/test/Sema/attr-naked.c b/test/Sema/attr-naked.c index 1ebd784..d9fa542 100644 --- a/test/Sema/attr-naked.c +++ b/test/Sema/attr-naked.c @@ -2,6 +2,10 @@ int a __attribute__((naked)); // expected-warning {{'naked' attribute only applies to functions}} +__attribute__((naked)) int t0(void) { + __asm__ volatile("mov r0, #0"); +} + void t1() __attribute__((naked)); void t2() __attribute__((naked(2))); // expected-error {{attribute takes no arguments}} diff --git a/test/Sema/attr-unavailable-message.c b/test/Sema/attr-unavailable-message.c index a1e047c..9f663fc 100644 --- a/test/Sema/attr-unavailable-message.c +++ b/test/Sema/attr-unavailable-message.c @@ -16,3 +16,13 @@ void test_foo() { } char test2[__has_feature(attribute_unavailable_with_message) ? 1 : -1]; + +// rdar://9623855 +void unavail(void) __attribute__((__unavailable__)); +void unavail(void) { + // No complains inside an unavailable function. + int ir = foo(1); + double dr = dfoo(1.0); + void (*fp)() = &bar; + double (*fp4)(double) = dfoo; +} diff --git a/test/Sema/attr-weak.c b/test/Sema/attr-weak.c index 41c9fd7..adedf12 100644 --- a/test/Sema/attr-weak.c +++ b/test/Sema/attr-weak.c @@ -12,3 +12,7 @@ struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute only struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variables and functions}} static int x __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} + +// rdar://9538608 +int C; // expected-note {{previous definition is here}} +extern int C __attribute__((weak_import)); // expected-warning {{an already-declared variable is made a weak_import declaration}} diff --git a/test/Sema/bitfield.c b/test/Sema/bitfield.c index 49c1c7d..a1ce894 100644 --- a/test/Sema/bitfield.c +++ b/test/Sema/bitfield.c @@ -32,6 +32,7 @@ int y; struct {unsigned x : 2;} x2; __typeof__((x.x+=1)+1) y; +__typeof__((0,x.x)+1) y; __typeof__(x.x<<1) y; int y; diff --git a/test/Sema/compare.c b/test/Sema/compare.c index 5221b17..cd973d4 100644 --- a/test/Sema/compare.c +++ b/test/Sema/compare.c @@ -312,3 +312,18 @@ int rdar8511238() { return 0; return 20; } + +// PR10336 +int test9(int sv, unsigned uv, long slv) { + return sv == (uv ^= slv); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}} +} + +void test10(void) { + int si; + unsigned int ui; + long sl; + + _Bool b; + b = (si == (ui = sl)); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}} + b = (si == (ui = sl&15)); +} diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index 56c429c..bdb40ae 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -36,7 +36,7 @@ int g17[(3?:1) - 2]; EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1); struct s { - int a[(int)-1.0f]; // expected-error {{array size is negative}} + int a[(int)-1.0f]; // expected-error {{'a' declared as an array with a negative size}} }; EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1)); diff --git a/test/Sema/conversion-64-32.c b/test/Sema/conversion-64-32.c index aa72829..112e995 100644 --- a/test/Sema/conversion-64-32.c +++ b/test/Sema/conversion-64-32.c @@ -3,3 +3,13 @@ int test0(long v) { return v; // expected-warning {{implicit conversion loses integer precision}} } + + +// rdar://9546171 +typedef int int4 __attribute__ ((vector_size(16))); +typedef long long long2 __attribute__((__vector_size__(16))); + +int4 test1(long2 a) { + int4 v127 = a; // no warning. + return v127; +} diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 1eaf708..03204c6 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -335,3 +335,11 @@ void test_8559831(enum E8559831b value_a, E8559831c value_c) { enum E8559831a a3 = value_d; a3 = value_d; } + +void test26(int si, long sl) { + si = sl % sl; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}} + si = sl % si; + si = si % sl; + si = si / sl; + si = sl / si; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}} +} diff --git a/test/Sema/ext_vector_casts.c b/test/Sema/ext_vector_casts.c index 75d41ca..848ec1f 100644 --- a/test/Sema/ext_vector_casts.c +++ b/test/Sema/ext_vector_casts.c @@ -37,7 +37,7 @@ static void test() { vec4 /= 5.2f; vec4 %= 4; // expected-error {{invalid operands to binary expression ('float4' and 'int')}} ivec4 %= 4; - ivec4 += vec4; // expected-error {{can't convert between vector values of different size ('float4' and 'int4')}} + ivec4 += vec4; // expected-error {{can't convert between vector values of different size ('int4' and 'float4')}} ivec4 += (int4)vec4; ivec4 -= ivec4; ivec4 |= ivec4; diff --git a/test/Sema/extern-redecl.c b/test/Sema/extern-redecl.c index 067e3c2..c176725 100644 --- a/test/Sema/extern-redecl.c +++ b/test/Sema/extern-redecl.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // rdar: // 8125274 static int a16[]; // expected-warning {{tentative array definition assumed to have one element}} @@ -7,3 +7,16 @@ void f16(void) { extern int a16[]; } + +// PR10013: Scope of extern declarations extend past enclosing block +extern int PR10013_x; +int PR10013(void) { + int *PR10013_x = 0; + { + extern int PR10013_x; + extern int PR10013_x; + } + + return PR10013_x; // expected-warning{{incompatible pointer to integer conversion}} +} + diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index c78095a..b47d3ca 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -358,3 +358,17 @@ void pr9314() { printf(__func__); // no-warning } +int printf(const char * restrict, ...) __attribute__((__format__ (__printf__, 1, 2))); + +void rdar9612060(void) { + printf("%s", 2); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} +} + +void check_char(unsigned char x, signed char y) { + printf("%c", y); // no-warning + printf("%hhu", x); // no-warning + printf("%hhi", y); // no-warning + printf("%hhi", x); // no-warning + printf("%c", x); // no-warning + printf("%hhu", y); // no-warning +} diff --git a/test/Sema/i-c-e.c b/test/Sema/i-c-e.c index 4d7007c..1aac51e 100644 --- a/test/Sema/i-c-e.c +++ b/test/Sema/i-c-e.c @@ -1,4 +1,4 @@ -// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings +// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings -std=c99 #include <stdint.h> #include <limits.h> diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c index e5b6d5f..0214a0c 100644 --- a/test/Sema/incomplete-decl.c +++ b/test/Sema/incomplete-decl.c @@ -22,7 +22,7 @@ void func() { } int h[]; // expected-warning {{tentative array definition assumed to have one element}} -int (*i)[] = &h+1; // expected-error {{arithmetic on pointer to incomplete type 'int (*)[]'}} +int (*i)[] = &h+1; // expected-error {{arithmetic on a pointer to an incomplete type 'int []'}} struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \ expected-note {{forward declaration of 'struct bar'}} diff --git a/test/Sema/inline-redef.c b/test/Sema/inline-redef.c new file mode 100644 index 0000000..4a46e11 --- /dev/null +++ b/test/Sema/inline-redef.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -std=gnu89 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#if __STDC_VERSION__ >= 199901 +#define GNU_INLINE __attribute((__gnu_inline__)) +#else +#define GNU_INLINE +#endif + +// PR5253 +// rdar://9559708 (same extension in C99 mode) +// GNU Extension: check that we can redefine an extern inline function +GNU_INLINE extern inline int f(int a) {return a;} +int f(int b) {return b;} // expected-note{{previous definition is here}} +// And now check that we can't redefine a normal function +int f(int c) {return c;} // expected-error{{redefinition of 'f'}} + +// Check that we can redefine an extern inline function as a static function +GNU_INLINE extern inline int g(int a) {return a;} +static int g(int b) {return b;} + +// Check that we ensure the types of the two definitions are the same +GNU_INLINE extern inline int h(int a) {return a;} // expected-note{{previous definition is here}} +int h(short b) {return b;} // expected-error{{conflicting types for 'h'}} diff --git a/test/Sema/inline.c b/test/Sema/inline.c index b4795d3..3c99f24 100644 --- a/test/Sema/inline.c +++ b/test/Sema/inline.c @@ -1,22 +1,6 @@ -// RUN: %clang_cc1 -std=gnu89 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s // Check that we don't allow illegal uses of inline inline int a; // expected-error{{'inline' can only appear on functions}} typedef inline int b; // expected-error{{'inline' can only appear on functions}} int d(inline int a); // expected-error{{'inline' can only appear on functions}} - -// PR5253 -// GNU Extension: check that we can redefine an extern inline function -extern inline int f(int a) {return a;} -int f(int b) {return b;} // expected-note{{previous definition is here}} -// And now check that we can't redefine a normal function -int f(int c) {return c;} // expected-error{{redefinition of 'f'}} - -// Check that we can redefine an extern inline function as a static function -extern inline int g(int a) {return a;} -static int g(int b) {return b;} - -// Check that we ensure the types of the two definitions are the same -extern inline int h(int a) {return a;} // expected-note{{previous definition is here}} -int h(short b) {return b;} // expected-error{{conflicting types for 'h'}} - diff --git a/test/Sema/no-format-y2k-turnsoff-format.c b/test/Sema/no-format-y2k-turnsoff-format.c new file mode 100644 index 0000000..bd06e50 --- /dev/null +++ b/test/Sema/no-format-y2k-turnsoff-format.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -Wformat -Wno-format-y2k +// rdar://9504680 + +void foo(const char *, ...) __attribute__((__format__ (__printf__, 1, 2))); + +void bar(unsigned int a) { + foo("%s", a); // expected-warning {{conversion specifies type 'char *' but the argument has type 'unsigned int'}} +} + diff --git a/test/Sema/nonnull.c b/test/Sema/nonnull.c new file mode 100644 index 0000000..cea8e3d --- /dev/null +++ b/test/Sema/nonnull.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only %s +// rdar://9584012 + +typedef struct { + char *str; +} Class; + +typedef union { + Class *object; +} Instance __attribute__((transparent_union)); + +__attribute__((nonnull(1))) void Class_init(Instance this, char *str) { + this.object->str = str; +} + +int main(void) { + Class *obj; + Class_init(0, "Hello World"); // expected-warning {{null passed to a callee which requires a non-null argument}} + Class_init(obj, "Hello World"); +} + diff --git a/test/Sema/paren-list-expr-type.cpp b/test/Sema/paren-list-expr-type.cpp new file mode 100644 index 0000000..ad5b7fb --- /dev/null +++ b/test/Sema/paren-list-expr-type.cpp @@ -0,0 +1,17 @@ +// RUN: %clang -cc1 -ast-dump %s | not grep NULL +// Makes sure that we don't introduce null types when handling +// ParenListExpr. + +template<typename T> class X { void f() { X x(*this); } }; + +template<typename T> class Y { Y() : t(1) {} T t; }; + +template<typename T> class Z { Z() : b(true) {} const bool b; }; + +template<typename T> class A : public Z<T> { A() : Z<T>() {} }; + +class C {}; +template<typename T> class D : public C { D(): C() {} }; + +void f() { (int)(1, 2); } + diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c index fa3c3c2..13ea3ec 100644 --- a/test/Sema/parentheses.c +++ b/test/Sema/parentheses.c @@ -26,6 +26,12 @@ 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 '|'}} \ + // expected-note {{place parentheses around the '&' expression to silence this warning}} + + (void)(i | i & i); // expected-warning {{'&' within '|'}} \ + // expected-note {{place parentheses around the '&' expression to silence this warning}} + (void)(i || i && i); // expected-warning {{'&&' within '||'}} \ // expected-note {{place parentheses around the '&&' expression to silence this warning}} @@ -42,21 +48,21 @@ void bitwise_rel(unsigned i) { _Bool someConditionFunc(); void conditional_op(int x, int y, _Bool b) { - (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: has lower precedence than +}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the + expression to silence this warning}} + (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} - (void)(x - b ? 1 : 2); // expected-warning {{?: has lower precedence than -}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the - expression to silence this warning}} + (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '-' expression to silence this warning}} - (void)(x * (x == y) ? 1 : 2); // expected-warning {{?: has lower precedence than *}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the * expression to silence this warning}} + (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '*' expression to silence this warning}} - (void)(x / !x ? 1 : 2); // expected-warning {{?: has lower precedence than /}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the / expression to silence this warning}} + (void)(x / !x ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '/'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '/' expression to silence this warning}} (void)(x % 2 ? 1 : 2); // no warning diff --git a/test/Sema/parentheses.cpp b/test/Sema/parentheses.cpp index a25f2a0..252455d 100644 --- a/test/Sema/parentheses.cpp +++ b/test/Sema/parentheses.cpp @@ -4,17 +4,17 @@ bool someConditionFunc(); void conditional_op(int x, int y, bool b) { - (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: has lower precedence than +}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the + expression to silence this warning}} + (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} - (void)(x - b ? 1 : 2); // expected-warning {{?: has lower precedence than -}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the - expression to silence this warning}} + (void)(x - b ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '-'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '-' expression to silence this warning}} - (void)(x * (x == y) ? 1 : 2); // expected-warning {{?: has lower precedence than *}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the * expression to silence this warning}} + (void)(x * (x == y) ? 1 : 2); // expected-warning {{operator '?:' has lower precedence than '*'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '*' expression to silence this warning}} } class Stream { @@ -25,7 +25,21 @@ public: }; void f(Stream& s, bool b) { - (void)(s << b ? "foo" : "bar"); // expected-warning {{?: has lower precedence than <<}} \ - // expected-note {{place parentheses around the ?: expression to evaluate it first}} \ - // expected-note {{place parentheses around the << expression to silence this warning}} + (void)(s << b ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '<<'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '<<' expression to silence this warning}} +} + +struct S { + operator int() { return 42; } + friend S operator+(const S &lhs, bool) { return S(); } +}; + +void test(S *s, bool (S::*m_ptr)()) { + (void)(*s + true ? "foo" : "bar"); // expected-warning {{operator '?:' has lower precedence than '+'}} \ + // expected-note {{place parentheses around the '?:' expression to evaluate it first}} \ + // expected-note {{place parentheses around the '+' expression to silence this warning}} + + // Don't crash on unusual member call expressions. + (void)((s->*m_ptr)() ? "foo" : "bar"); } diff --git a/test/Sema/pointer-addition.c b/test/Sema/pointer-addition.c index aa425a7..21ce63b 100644 --- a/test/Sema/pointer-addition.c +++ b/test/Sema/pointer-addition.c @@ -3,18 +3,19 @@ typedef struct S S; // expected-note 3 {{forward declaration of 'struct S'}} void a(S* b, void* c) { void (*fp)(int) = 0; - b++; // expected-error {{arithmetic on pointer to incomplete type}} - b += 1; // expected-error {{arithmetic on pointer to incomplete type}} - c++; // expected-warning {{use of GNU void* extension}} - c += 1; // expected-warning {{use of GNU void* extension}} - c--; // expected-warning {{use of GNU void* extension}} - c -= 1; // expected-warning {{use of GNU void* extension}} - (void) c[1]; // expected-warning {{use of GNU void* extension}} - b = 1+b; // expected-error {{arithmetic on pointer to incomplete type}} + b++; // expected-error {{arithmetic on a pointer to an incomplete type}} + b += 1; // expected-error {{arithmetic on a pointer to an incomplete type}} + c++; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + c += 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + c--; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + c -= 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}} + (void) c[1]; // expected-warning {{subscript of a pointer to void is a GNU extension}} + b = 1+b; // expected-error {{arithmetic on a pointer to an incomplete type}} /* The next couple tests are only pedantic warnings in gcc */ void (*d)(S*,void*) = a; - d += 1; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}} - d++; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}} - d--; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}} - d -= 1; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}} + d += 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + d++; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + d--; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + d -= 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} + (void)(1 + d); // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}} } diff --git a/test/Sema/pointer-subtract-compat.c b/test/Sema/pointer-subtract-compat.c index 70340c6..b801f81 100644 --- a/test/Sema/pointer-subtract-compat.c +++ b/test/Sema/pointer-subtract-compat.c @@ -7,5 +7,5 @@ int a(char* a, rchar* b) { // <rdar://problem/6520707> void f0(void (*fp)(void)) { - int x = fp - fp; // expected-warning{{arithmetic on pointer to function type 'void (*)(void)' is a GNU extension}} + int x = fp - fp; // expected-warning{{arithmetic on pointers to the function type 'void (void)' is a GNU extension}} } diff --git a/test/Sema/shift.c b/test/Sema/shift.c index 28407be..142d83c 100644 --- a/test/Sema/shift.c +++ b/test/Sema/shift.c @@ -38,7 +38,7 @@ void test() { int i; i = 1 << (WORD_BIT - 2); i = 2 << (WORD_BIT - 1); // expected-warning {{bits to represent, but 'int' only has}} - i = 1 << (WORD_BIT - 1); // expected-warning {{overrides the sign bit of the shift expression}} + i = 1 << (WORD_BIT - 1); // expected-warning {{sets the sign bit of the shift expression}} i = -1 << (WORD_BIT - 1); i = 0 << (WORD_BIT - 1); i = (char)1 << (WORD_BIT - 2); diff --git a/test/Sema/sign-conversion.c b/test/Sema/sign-conversion.c new file mode 100644 index 0000000..4b1ee75 --- /dev/null +++ b/test/Sema/sign-conversion.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wsign-conversion %s + +// PR9345: make a subgroup of -Wconversion for signedness changes + +void test(int x) { + unsigned t0 = x; // expected-warning {{implicit conversion changes signedness}} + unsigned t1 = (t0 == 5 ? x : 0); // expected-warning {{operand of ? changes signedness}} +} diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c index e1c7073..6070e87 100644 --- a/test/Sema/struct-decl.c +++ b/test/Sema/struct-decl.c @@ -6,7 +6,7 @@ struct bar { struct foo { char name[(int)&((struct bar *)0)->n]; - char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{array size is negative}} + char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{'name2' declared as an array with a negative size}} }; // PR3430 diff --git a/test/Sema/typecheck-binop.c b/test/Sema/typecheck-binop.c index 712dad2..be52d0b 100644 --- a/test/Sema/typecheck-binop.c +++ b/test/Sema/typecheck-binop.c @@ -7,15 +7,15 @@ int sub1(int *a, double *b) { } void *sub2(struct incomplete *P) { - return P-4; /* expected-error{{subtraction of pointer 'struct incomplete *' requires pointee to be a complete object type}} */ + return P-4; /* expected-error{{arithmetic on a pointer to an incomplete type 'struct incomplete'}} */ } void *sub3(void *P) { - return P-4; /* expected-warning{{GNU void* extension}} */ + return P-4; /* expected-warning{{arithmetic on a pointer to void is a GNU extension}} */ } int sub4(void *P, void *Q) { - return P-Q; /* expected-warning{{GNU void* extension}} */ + return P-Q; /* expected-warning{{arithmetic on pointers to void is a GNU extension}} */ } int sub5(void *P, int *Q) { diff --git a/test/Sema/typedef-variable-type.c b/test/Sema/typedef-variable-type.c index b805b1e..8a7ee8b 100644 --- a/test/Sema/typedef-variable-type.c +++ b/test/Sema/typedef-variable-type.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic -Wno-typedef-redefinition +// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic -Wno-typedef-redefinition -std=c99 // Make sure we accept a single typedef typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}} diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c index b70a295..0caab3d 100644 --- a/test/Sema/uninit-variables.c +++ b/test/Sema/uninit-variables.c @@ -352,3 +352,18 @@ int test52(int a, int b) { } return x; // expected-warning {{variable 'x' may be uninitialized when used here}} } + +// This CFG caused the uninitialized values warning to inf-loop. +extern int PR10379_g(); +void PR10379_f(int *len) { + int new_len; // expected-note {{variable 'new_len' is declared here}} expected-note{{add initialization to silence this warning}} + for (int i = 0; i < 42 && PR10379_g() == 0; i++) { + if (PR10379_g() == 1) + continue; + if (PR10379_g() == 2) + PR10379_f(&new_len); + else if (PR10379_g() == 3) + PR10379_f(&new_len); + *len += new_len; // expected-warning {{variable 'new_len' may be uninitialized when used here}} + } +} diff --git a/test/Sema/varargs.c b/test/Sema/varargs.c index e399f89..07081ed 100644 --- a/test/Sema/varargs.c +++ b/test/Sema/varargs.c @@ -61,3 +61,18 @@ void f7(int a, ...) { __builtin_va_end(ap); } +void f8(int a, ...) { + __builtin_va_list ap; + __builtin_va_start(ap, a); + (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}} + __builtin_va_end(ap); +} + +enum E { x = -1, y = 2, z = 10000 }; +void f9(__builtin_va_list args) +{ + (void)__builtin_va_arg(args, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'}} + (void)__builtin_va_arg(args, enum E); // Don't warn here in C + (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}} + (void)__builtin_va_arg(args, char); // expected-warning {{second argument to 'va_arg' is of promotable type 'char'}} +} diff --git a/test/Sema/vla.c b/test/Sema/vla.c index ebf9b88..fd7a6bf 100644 --- a/test/Sema/vla.c +++ b/test/Sema/vla.c @@ -42,7 +42,7 @@ void f3() } // PR3663 -static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{size of static array must be an integer constant expression}} +static const unsigned array[((2 * (int)((((4) / 2) + 1.0/3.0) * (4) - 1e-8)) + 1)]; // expected-warning {{variable length array folded to constant array as an extension}} int a[*]; // expected-error {{star modifier used outside of function prototype}} int f4(int a[*][*]); @@ -53,7 +53,7 @@ int pr2044b; 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}} +void f5() { char a[][f5_ci] = {""}; } // expected-warning {{variable length array folded to constant array as an extension}} // PR5185 void pr5185(int a[*]); diff --git a/test/Sema/warn-sizeof-arrayarg.c b/test/Sema/warn-sizeof-arrayarg.c new file mode 100644 index 0000000..ba8a5fa --- /dev/null +++ b/test/Sema/warn-sizeof-arrayarg.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef int Arr[10]; + +typedef int trungl_int; + +void f(int a[10], Arr arr) { // \ +// expected-note {{declared here}} \ +// expected-note {{declared here}} \ +// expected-note {{declared here}} \ +// expected-note {{declared here}} + + /* Should warn. */ + (void)sizeof(a); // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}} + (void)sizeof((((a)))); // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}} + (void)sizeof a; // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'int [10]'}} + (void)sizeof arr; // \ + // expected-warning{{sizeof on array function parameter will return size of 'int *' instead of 'Arr' (aka 'int [10]')}} + + /* Shouldn't warn. */ + int b[10]; + (void)sizeof b; + Arr brr; + (void)sizeof brr; + (void)sizeof(Arr); + (void)sizeof(int); +} diff --git a/test/Sema/x86-builtin-palignr.c b/test/Sema/x86-builtin-palignr.c index 83719a3..6e1303c 100644 --- a/test/Sema/x86-builtin-palignr.c +++ b/test/Sema/x86-builtin-palignr.c @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify -triple x86_64-pc-linux-gnu %s -// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify -triple i686-apple-darwin10 %s +// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple x86_64-pc-linux-gnu %s +// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -target-feature +mmx -verify -triple i686-apple-darwin10 %s #include <tmmintrin.h> |