summaryrefslogtreecommitdiffstats
path: root/test/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/altivec-init.c19
-rw-r--r--test/Sema/array-init.c8
-rw-r--r--test/Sema/array-size-64.c7
-rw-r--r--test/Sema/array-size.c10
-rw-r--r--test/Sema/block-misc.c5
-rw-r--r--test/Sema/builtins-arm.c11
-rw-r--r--test/Sema/builtins.c20
-rw-r--r--test/Sema/cast-incomplete.c14
-rw-r--r--test/Sema/compound-literal.c2
-rw-r--r--test/Sema/const-eval.c8
-rw-r--r--test/Sema/enum.c6
-rw-r--r--test/Sema/expr-comma-c89.c6
-rw-r--r--test/Sema/expr-comma.c8
-rw-r--r--test/Sema/exprs.c5
-rw-r--r--test/Sema/ext_vector_casts.c2
-rw-r--r--test/Sema/format-strings-scanf.c34
-rw-r--r--test/Sema/format-strings.c17
-rw-r--r--test/Sema/knr-def-call.c11
-rw-r--r--test/Sema/overloadable.c11
-rw-r--r--test/Sema/pragma-align-packed.c7
-rw-r--r--test/Sema/recover-goto.c3
-rw-r--r--test/Sema/scope-check.c32
-rw-r--r--test/Sema/switch.c6
-rw-r--r--test/Sema/typedef-variable-type.c7
-rw-r--r--test/Sema/vector-ops.c25
-rw-r--r--test/Sema/warn-cast-align.c41
-rw-r--r--test/Sema/warn-unused-function.c12
-rw-r--r--test/Sema/warn-write-strings.c6
28 files changed, 305 insertions, 38 deletions
diff --git a/test/Sema/altivec-init.c b/test/Sema/altivec-init.c
index 57abc93..b5758bc 100644
--- a/test/Sema/altivec-init.c
+++ b/test/Sema/altivec-init.c
@@ -14,3 +14,22 @@ v8 foo(void) {
// FIXME: test that (type)(fn)(args) still works with -faltivec
// FIXME: test that c++ overloaded commas still work -faltivec
}
+
+void __attribute__((__overloadable__)) f(v4 a)
+{
+}
+
+void __attribute__((__overloadable__)) f(int a)
+{
+}
+
+void test()
+{
+ v4 vGCC;
+ vector int vAltiVec;
+
+ f(vAltiVec);
+ vGCC = vAltiVec;
+ vGCC = vGCC > vAltiVec;
+ vAltiVec = 0 ? vGCC : vGCC;
+}
diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c
index f93b087..0ee22c0 100644
--- a/test/Sema/array-init.c
+++ b/test/Sema/array-init.c
@@ -210,7 +210,7 @@ struct bittest bittestvar = {1, 2, 3, 4}; //expected-warning{{excess elements in
// Not completely sure what should happen here...
int u1 = {}; //expected-warning{{use of GNU empty initializer extension}} expected-error{{scalar initializer cannot be empty}}
-int u2 = {{3}}; //expected-error{{too many braces around scalar initializer}}
+int u2 = {{3}}; //expected-warning{{too many braces around scalar initializer}}
// PR2362
void varArray() {
@@ -218,7 +218,8 @@ void varArray() {
}
// PR2151
-void emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct extension}} expected-error{{initializer for aggregate with no elements}}
+void emptyInit() {struct {} x[] = {6};} //expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}} \
+// expected-error{{initializer for aggregate with no elements}}
void noNamedInit() {
struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}}
@@ -241,7 +242,8 @@ struct soft_segment_descriptor gdt_segs[] = {
};
static void sppp_ipv6cp_up();
-const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct extension}} expected-warning{{excess elements in struct initializer}}
+const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}} \
+// expected-warning{{excess elements in struct initializer}}
struct _Matrix { union { float m[4][4]; }; }; //expected-warning{{anonymous unions are a GNU extension in C}}
typedef struct _Matrix Matrix;
diff --git a/test/Sema/array-size-64.c b/test/Sema/array-size-64.c
new file mode 100644
index 0000000..f22e8e7
--- /dev/null
+++ b/test/Sema/array-size-64.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -verify %s
+
+void f() {
+ int a[2147483647U][2147483647U]; // expected-error{{array is too large}}
+ int b[1073741825U - 1U][2147483647U];
+ int c[18446744073709551615U/sizeof(int)/2];
+}
diff --git a/test/Sema/array-size.c b/test/Sema/array-size.c
new file mode 100644
index 0000000..7580e3e
--- /dev/null
+++ b/test/Sema/array-size.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin -verify %s
+
+void f() {
+ int x0[1073741824]; // expected-error{{array is too large}}
+ int x1[1073741824 + 1]; // expected-error{{array is too large}}
+ int x2[(unsigned)1073741824]; // expected-error{{array is too large}}
+ int x3[(unsigned)1073741824 + 1]; // expected-error{{array is too large}}
+ int x4[1073741824 - 1];
+}
+
diff --git a/test/Sema/block-misc.c b/test/Sema/block-misc.c
index 92be5b1..ec74a63 100644
--- a/test/Sema/block-misc.c
+++ b/test/Sema/block-misc.c
@@ -221,3 +221,8 @@ void test21() {
(void)b[1]; // expected-error {{cannot refer to declaration with an array type inside block}}
}();
}
+
+// rdar ://8218839
+const char * (^func)(void) = ^{ return __func__; };
+const char * (^function)(void) = ^{ return __FUNCTION__; };
+const char * (^pretty)(void) = ^{ return __PRETTY_FUNCTION__; };
diff --git a/test/Sema/builtins-arm.c b/test/Sema/builtins-arm.c
new file mode 100644
index 0000000..4dd31e7
--- /dev/null
+++ b/test/Sema/builtins-arm.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify -DTEST0 %s
+// RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify -DTEST1 %s
+
+#ifdef TEST0
+void __clear_cache(char*, char*);
+#endif
+
+#ifdef TEST1
+void __clear_cache(void*, void*);
+#endif
+
diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c
index c0a2131..787630c 100644
--- a/test/Sema/builtins.c
+++ b/test/Sema/builtins.c
@@ -44,6 +44,11 @@ void test9(short v) {
// PR7600: Pointers are implicitly casted to integers and back.
void *old_ptr = __sync_val_compare_and_swap((void**)0, 0, 0);
+
+ // Ensure the return type is correct even when implicit casts are stripped
+ // away. This triggers an assertion while checking the comparison otherwise.
+ if (__sync_fetch_and_add(&old, 1) == 1) {
+ }
}
@@ -75,3 +80,18 @@ void test12(void) {
void test_unknown_builtin(int a, int b) {
__builtin_foo(a, b); // expected-error{{use of unknown builtin}}
}
+
+int test13() {
+ __builtin_eh_return(0, 0); // no warning, eh_return never returns.
+}
+
+// <rdar://problem/8228293>
+void test14() {
+ int old;
+ old = __sync_fetch_and_min((volatile int *)&old, 1);
+}
+
+// <rdar://problem/8336581>
+void test15(const char *s) {
+ __builtin_printf("string is %s\n", s);
+}
diff --git a/test/Sema/cast-incomplete.c b/test/Sema/cast-incomplete.c
new file mode 100644
index 0000000..dd10e00
--- /dev/null
+++ b/test/Sema/cast-incomplete.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// PR5692
+
+enum x; // expected-note {{forward declaration}}
+extern struct y a; // expected-note {{forward declaration}}
+extern union z b; // expected-note 2 {{forward declaration}}
+
+void foo() {
+ (enum x)1; // expected-error {{cast to incomplete type}}
+ (struct y)a; // expected-error {{cast to incomplete type}}
+ (union z)b; // expected-error {{cast to incomplete type}}
+ (union z)1; // expected-error {{cast to incomplete type}}
+}
+
diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c
index 08c30b3..aade464 100644
--- a/test/Sema/compound-literal.c
+++ b/test/Sema/compound-literal.c
@@ -11,7 +11,7 @@ static int x = (int){1};
static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}}
static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}}
-typedef struct { } cache_t; // -expected-warning{{use of empty struct extension}}
+typedef struct { } cache_t; // -expected-warning{{empty struct (accepted as an extension) has size 0 in C, size 1 in C++}}
static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}}
typedef struct Test {int a;int b;} Test;
diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c
index c132b34..42097e7 100644
--- a/test/Sema/const-eval.c
+++ b/test/Sema/const-eval.c
@@ -74,5 +74,9 @@ const _Bool constbool = 0;
EVAL_EXPR(35, constbool)
EVAL_EXPR(36, constbool)
-EVAL_EXPR(37, (1,2.0) == 2.0) // expected-warning {{expression result unused}}
-EVAL_EXPR(38, __builtin_expect(1,1) == 1)
+EVAL_EXPR(37, (1,2.0) == 2.0 ? 1 : -1)
+EVAL_EXPR(38, __builtin_expect(1,1) == 1 ? 1 : -1)
+
+// PR7884
+EVAL_EXPR(39, __real__(1.f) == 1 ? 1 : -1)
+EVAL_EXPR(40, __imag__(1.f) == 0 ? 1 : -1)
diff --git a/test/Sema/enum.c b/test/Sema/enum.c
index 0570150..64aa31b 100644
--- a/test/Sema/enum.c
+++ b/test/Sema/enum.c
@@ -96,3 +96,9 @@ char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer t
// PR4515
enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2};
int CheckPR4515[PR4515b==0?1:-1];
+
+// PR7911
+extern enum PR7911T PR7911V; // expected-warning{{ISO C forbids forward references to 'enum' types}}
+void PR7911F() {
+ switch (PR7911V); // expected-error {{statement requires expression of integer type}}
+}
diff --git a/test/Sema/expr-comma-c89.c b/test/Sema/expr-comma-c89.c
index dc42702..d0883ba 100644
--- a/test/Sema/expr-comma-c89.c
+++ b/test/Sema/expr-comma-c89.c
@@ -11,7 +11,7 @@ int B[sizeof((a.c)) == 17 ? 1 : -1];
// comma does array/function promotion in c99.
-int X[sizeof(0, (foo().c)) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}}
-int Y[sizeof(0, (a,b).c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
-int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}}
+int X[sizeof(0, (foo().c)) == sizeof(char*) ? 1 : -1];
+int Y[sizeof(0, (a,b).c) == sizeof(char*) ? 1 : -1];
+int Z[sizeof(0, (a=b).c) == sizeof(char*) ? 1 : -1];
diff --git a/test/Sema/expr-comma.c b/test/Sema/expr-comma.c
index b004fc1..d3e4020 100644
--- a/test/Sema/expr-comma.c
+++ b/test/Sema/expr-comma.c
@@ -11,7 +11,7 @@ int B[sizeof((a.c)) == 17 ? 1 : -1];
// comma does not promote array/function in c90 unless they are lvalues.
-int W[sizeof(0, a.c) == sizeof(char*) ? 1 : -1]; // expected-warning {{expression result unused}}
-int X[sizeof(0, (foo().c)) == 17 ? 1 : -1]; // expected-warning {{expression result unused}}
-int Y[sizeof(0, (a,b).c) == 17 ? 1 : -1]; // expected-warning {{expression result unused}} // expected-warning {{expression result unused}}
-int Z[sizeof(0, (a=b).c) == 17 ? 1 : -1]; // expected-warning {{expression result unused}}
+int W[sizeof(0, a.c) == sizeof(char*) ? 1 : -1];
+int X[sizeof(0, (foo().c)) == 17 ? 1 : -1];
+int Y[sizeof(0, (a,b).c) == 17 ? 1 : -1];
+int Z[sizeof(0, (a=b).c) == 17 ? 1 : -1];
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
index 9d3da90..56a52be 100644
--- a/test/Sema/exprs.c
+++ b/test/Sema/exprs.c
@@ -145,5 +145,8 @@ void test19() {
int test20(int x) {
return x && 4; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
- return x && sizeof(int) == 4; // no warning.
+ return x && sizeof(int) == 4; // no warning, RHS is logical op.
+
+ // no warning, this is an idiom for "true" in old C style.
+ return x && (signed char)1;
}
diff --git a/test/Sema/ext_vector_casts.c b/test/Sema/ext_vector_casts.c
index 7681953..75d41ca 100644
--- a/test/Sema/ext_vector_casts.c
+++ b/test/Sema/ext_vector_casts.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fno-lax-vector-conversions %s
typedef __attribute__(( ext_vector_type(2) )) float float2;
typedef __attribute__(( ext_vector_type(4) )) int int4;
diff --git a/test/Sema/format-strings-scanf.c b/test/Sema/format-strings-scanf.c
new file mode 100644
index 0000000..42b6c03
--- /dev/null
+++ b/test/Sema/format-strings-scanf.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
+
+typedef __typeof(sizeof(int)) size_t;
+typedef struct _FILE FILE;
+typedef __WCHAR_TYPE__ wchar_t;
+
+int fscanf(FILE * restrict, const char * restrict, ...) ;
+int scanf(const char * restrict, ...) ;
+int sscanf(const char * restrict, const char * restrict, ...) ;
+
+void test(const char *s, int *i) {
+ scanf(s, i); // expected-warning{{ormat string is not a string literal}}
+ scanf("%0d", i); // expected-warning{{zero field width in scanf format string is unused}}
+ scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}}
+ scanf("%d%[asdfasdfd", i, s); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+
+ unsigned short s_x;
+ scanf ("%" "hu" "\n", &s_x); // no-warning
+ scanf("%y", i); // expected-warning{{invalid conversion specifier 'y'}}
+ scanf("%%"); // no-warning
+ scanf("%%%1$d", i); // no-warning
+ scanf("%1$d%%", i); // no-warning
+ scanf("%d", i, i); // expected-warning{{data argument not used by format string}}
+ scanf("%*d", i); // // expected-warning{{data argument not used by format string}}
+ scanf("%*d", i); // // expected-warning{{data argument not used by format string}}
+ scanf("%*d%1$d", i); // no-warning
+}
+
+void bad_length_modifiers(char *s, void *p, wchar_t *ws, long double *ld) {
+ scanf("%hhs", "foo"); // expected-warning{{length modifier 'hh' results in undefined behavior or no effect with 's' conversion specifier}}
+ scanf("%1$zp", p); // expected-warning{{length modifier 'z' results in undefined behavior or no effect with 'p' conversion specifier}}
+ scanf("%ls", ws); // no-warning
+ scanf("%#.2Lf", ld); // expected-warning{{invalid conversion specifier '#'}}
+}
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index c6dee68..2325454 100644
--- a/test/Sema/format-strings.c
+++ b/test/Sema/format-strings.c
@@ -239,6 +239,8 @@ void test_positional_arguments() {
printf("%1$2.2d", (int) 2); // no-warning
printf("%2$*1$.2d", (int) 2, (int) 3); // no-warning
printf("%2$*8$d", (int) 2, (int) 3); // expected-warning{{specified field width is missing a matching 'int' argument}}
+ printf("%%%1$d", (int) 2); // no-warning
+ printf("%1$d%%", (int) 2); // no-warning
}
// PR 6697 - Handle format strings where the data argument is not adjacent to the format string
@@ -284,3 +286,18 @@ void bug7377_bad_length_mod_usage() {
printf("%-0f", 1.23); // expected-warning{{flag '0' is ignored when flag '-' is present}}
printf("%-+f", 1.23); // no-warning
}
+
+// PR 7981 - handle '%lc' (wint_t)
+#ifndef wint_t
+typedef int __darwin_wint_t;
+typedef __darwin_wint_t wint_t;
+#endif
+
+void pr7981(wint_t c, wchar_t c2) {
+ printf("%lc", c); // no-warning
+ printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}}
+ printf("%lc", (char) 1); // no-warning
+ printf("%lc", &c); // expected-warning{{the argument has type 'wint_t *' (aka 'int *')}}
+ printf("%lc", c2); // no-warning
+}
+
diff --git a/test/Sema/knr-def-call.c b/test/Sema/knr-def-call.c
index 8ae0550..66f2ec0 100644
--- a/test/Sema/knr-def-call.c
+++ b/test/Sema/knr-def-call.c
@@ -16,3 +16,14 @@ void f2(x) float x; { } // expected-warning{{promoted type 'double' of K&R funct
typedef void (*f3)(void);
f3 t3(int b) { return b? f0 : f1; } // okay
+
+// <rdar://problem/8193107>
+void f4() {
+ char *rindex();
+}
+
+char *rindex(s, c)
+ register char *s, c; // expected-warning{{promoted type 'char *' of K&R function parameter is not compatible with the parameter type 'char const *' declared in a previous prototype}}
+{
+ return 0;
+}
diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c
index 28c3e4c..8fb41a9 100644
--- a/test/Sema/overloadable.c
+++ b/test/Sema/overloadable.c
@@ -41,7 +41,6 @@ double promote(float) __attribute__((__overloadable__)); // expected-note {{cand
double promote(double) __attribute__((__overloadable__)); // expected-note {{candidate}}
long double promote(long double) __attribute__((__overloadable__)); // expected-note {{candidate}}
-void promote() __attribute__((__overloadable__)); // expected-error{{'overloadable' function 'promote' must have a prototype}}
void promote(...) __attribute__((__overloadable__, __unavailable__)); // \
// expected-note{{candidate function}}
@@ -60,3 +59,13 @@ double magnitude(IntVec) __attribute__((__overloadable__));
double test_p6600(DoubleVec d) {
return magnitude(d) * magnitude(d);
}
+
+// PR7738
+extern int __attribute__((overloadable)) f0(); // expected-error{{'overloadable' function 'f0' must have a prototype}}
+typedef int f1_type();
+f1_type __attribute__((overloadable)) f1; // expected-error{{'overloadable' function 'f1' must have a prototype}}
+
+void test() {
+ f0();
+ f1();
+}
diff --git a/test/Sema/pragma-align-packed.c b/test/Sema/pragma-align-packed.c
index 30b87bf..74fbd13 100644
--- a/test/Sema/pragma-align-packed.c
+++ b/test/Sema/pragma-align-packed.c
@@ -21,3 +21,10 @@ struct s2 {
};
extern int a[sizeof(struct s2) == 5 ? 1 : -1];
#pragma options align=reset
+
+#pragma pack(1)
+struct s3_0 { unsigned char f0; unsigned int f1; };
+int t3_0[sizeof(struct s3_0) == 5 ? 1 : -1];
+#pragma options align=reset
+struct s3_1 { unsigned char f0; unsigned int f1; };
+int t3_1[sizeof(struct s3_1) == 8 ? 1 : -1];
diff --git a/test/Sema/recover-goto.c b/test/Sema/recover-goto.c
index 0d665f9..0e8f6d3 100644
--- a/test/Sema/recover-goto.c
+++ b/test/Sema/recover-goto.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only %s -verify
-void a() {goto A; // expected-error {{use of undeclared label}}
+void a() { // expected-note {{to match this '{'}}
+ goto A; // expected-error {{use of undeclared label}}
// expected-error {{expected '}'}}
diff --git a/test/Sema/scope-check.c b/test/Sema/scope-check.c
index f3881ed..4ccb64c 100644
--- a/test/Sema/scope-check.c
+++ b/test/Sema/scope-check.c
@@ -1,7 +1,7 @@
// 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}}
+ goto L; // expected-error{{goto into protected scope}}
int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
int b[x]; // expected-note {{jump bypasses initialization of variable length array}}
L:
@@ -9,7 +9,7 @@ int test1(int x) {
}
int test2(int x) {
- goto L; // expected-error{{illegal goto into protected scope}}
+ goto L; // expected-error{{goto into protected scope}}
typedef int a[x]; // expected-note {{jump bypasses initialization of VLA typedef}}
L:
return sizeof(a);
@@ -18,14 +18,14 @@ int test2(int x) {
void test3clean(int*);
int test3() {
- goto L; // expected-error{{illegal goto into protected scope}}
+ goto L; // expected-error{{goto into protected scope}}
int a __attribute((cleanup(test3clean))); // expected-note {{jump bypasses initialization of variable with __attribute__((cleanup))}}
L:
return a;
}
int test4(int x) {
- goto L; // expected-error{{illegal goto into protected scope}}
+ goto L; // expected-error{{goto into protected scope}}
int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
test4(x);
L:
@@ -50,7 +50,7 @@ void test7(int x) {
switch (x) {
case 1: ;
int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
- case 2: // expected-error {{illegal switch case into protected scope}}
+ case 2: // expected-error {{switch case is in protected scope}}
a[1] = 2;
break;
}
@@ -58,17 +58,17 @@ void test7(int x) {
int test8(int x) {
// For statement.
- goto L2; // expected-error {{illegal goto into protected scope}}
+ goto L2; // expected-error {{goto into protected scope}}
for (int arr[x]; // expected-note {{jump bypasses initialization of variable length array}}
; ++x)
L2:;
// Statement expressions.
- goto L3; // expected-error {{illegal goto into protected scope}}
+ goto L3; // expected-error {{goto into protected scope}}
int Y = ({ int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
L3: 4; });
- goto L4; // expected-error {{illegal goto into protected scope}}
+ goto L4; // expected-error {{goto into protected scope}}
{
int A[x], // expected-note {{jump bypasses initialization of variable length array}}
B[x]; // expected-note {{jump bypasses initialization of variable length array}}
@@ -91,7 +91,7 @@ int test8(int x) {
int A[x], B = ({ if (x)
goto L7;
else
- goto L8; // expected-error {{illegal goto into protected scope}}
+ goto L8; // expected-error {{goto into protected scope}}
4; }),
C[x]; // expected-note {{jump bypasses initialization of variable length array}}
L8:; // bad
@@ -103,7 +103,7 @@ int test8(int x) {
goto L9;
else
// FIXME:
- goto L10; // fixme-error {{illegal goto into protected scope}}
+ goto L10; // fixme-error {{goto into protected scope}}
4; })];
L10:; // bad
}
@@ -123,7 +123,7 @@ int test8(int x) {
}
// Statement expressions 2.
- goto L1; // expected-error {{illegal goto into protected scope}}
+ goto L1; // expected-error {{goto into protected scope}}
return x == ({
int a[x]; // expected-note {{jump bypasses initialization of variable length array}}
L1:
@@ -151,14 +151,14 @@ L4:
}
void test10(int n, void *P) {
- goto L0; // expected-error {{illegal goto into protected scope}}
+ goto L0; // expected-error {{goto into protected scope}}
typedef int A[n]; // expected-note {{jump bypasses initialization of VLA typedef}}
L0:
- goto L1; // expected-error {{illegal goto into protected scope}}
+ goto L1; // expected-error {{goto into protected scope}}
A b, c[10]; // expected-note 2 {{jump bypasses initialization of variable length array}}
L1:
- goto L2; // expected-error {{illegal goto into protected scope}}
+ goto L2; // expected-error {{goto into protected scope}}
A d[n]; // expected-note {{jump bypasses initialization of variable length array}}
L2:
return;
@@ -171,7 +171,7 @@ void test11(int n) {
case 2:
case 3:;
int Arr[n]; // expected-note {{jump bypasses initialization of variable length array}}
- case 4: // expected-error {{illegal switch case into protected scope}}
+ case 4: // expected-error {{switch case is in protected scope}}
return;
}
};
@@ -185,7 +185,7 @@ void test12(int n) {
L1:
goto L2;
L2:
- goto L3; // expected-error {{illegal goto into protected scope}}
+ goto L3; // expected-error {{goto into protected scope}}
int Arr[n]; // expected-note {{jump bypasses initialization of variable length array}}
L3:
goto L4;
diff --git a/test/Sema/switch.c b/test/Sema/switch.c
index 4e39e0f..bb48229 100644
--- a/test/Sema/switch.c
+++ b/test/Sema/switch.c
@@ -50,14 +50,12 @@ void test4()
}
switch (cond) {
- case g() && 0: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} \
- expected-warning {{use of logical && with constant operand}}
+ case g() && 0: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}}
break;
}
switch (cond) {
- case 0 ... g() || 1: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}} \\
- expected-warning {{use of logical || with constant operand}}
+ case 0 ... g() || 1: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}}
break;
}
}
diff --git a/test/Sema/typedef-variable-type.c b/test/Sema/typedef-variable-type.c
index f298968..b805b1e 100644
--- a/test/Sema/typedef-variable-type.c
+++ b/test/Sema/typedef-variable-type.c
@@ -1,3 +1,8 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic
+// RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic -Wno-typedef-redefinition
+// Make sure we accept a single typedef
+typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}}
+
+// And make sure we accept identical redefinitions in system headers
+// (The test uses -Wno-typedef-redefinition to simulate this.)
typedef int (*a)[!.0]; // expected-warning{{size of static array must be an integer constant expression}}
diff --git a/test/Sema/vector-ops.c b/test/Sema/vector-ops.c
new file mode 100644
index 0000000..20575ec
--- /dev/null
+++ b/test/Sema/vector-ops.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -Wvector-conversions
+typedef unsigned int v2u __attribute__ ((vector_size (8)));
+typedef int v2s __attribute__ ((vector_size (8)));
+typedef float v2f __attribute__ ((vector_size(8)));
+
+void test1(v2u v2ua, v2s v2sa, v2f v2fa) {
+ // Bitwise binary operators
+ (void)(v2ua & v2ua);
+ (void)(v2fa & v2fa); // expected-error{{invalid operands to binary expression}}
+
+ // Unary operators
+ (void)(~v2ua);
+ (void)(~v2fa); // expected-error{{invalid argument type 'v2f' to unary}}
+
+ // Arrays
+ int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u'}}
+ int array2[17];
+ // FIXME: error message below needs type!
+ (void)(array2[v2ua]); // expected-error{{array subscript is not an integer}}
+
+ v2u *v2u_ptr = 0;
+ v2s *v2s_ptr;
+ v2s_ptr = v2u_ptr; // expected-warning{{converts between pointers to integer types with different sign}}
+}
+
diff --git a/test/Sema/warn-cast-align.c b/test/Sema/warn-cast-align.c
new file mode 100644
index 0000000..11e3c41
--- /dev/null
+++ b/test/Sema/warn-cast-align.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s
+
+// Simple casts.
+void test0(char *P) {
+ char *a = (char*) P;
+ short *b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}}
+ int *c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}}
+}
+
+// Casts from void* are a special case.
+void test1(void *P) {
+ char *a = (char*) P;
+ short *b = (short*) P;
+ int *c = (int*) P;
+
+ const volatile void *P2 = P;
+ char *d = (char*) P2;
+ short *e = (short*) P2;
+ int *f = (int*) P2;
+
+ const char *g = (const char*) P2;
+ const short *h = (const short*) P2;
+ const int *i = (const int*) P2;
+
+ const volatile char *j = (const volatile char*) P2;
+ const volatile short *k = (const volatile short*) P2;
+ const volatile int *l = (const volatile int*) P2;
+}
+
+// Aligned struct.
+__attribute__((align(16))) struct A {
+ char buffer[16];
+};
+void test2(char *P) {
+ struct A *a = (struct A*) P; // expected-warning {{cast from 'char *' to 'struct A *' increases required alignment from 1 to 16}}
+}
+
+// Incomplete type.
+void test3(char *P) {
+ struct B *b = (struct B*) P;
+}
diff --git a/test/Sema/warn-unused-function.c b/test/Sema/warn-unused-function.c
index d5e676b..24d4fad 100644
--- a/test/Sema/warn-unused-function.c
+++ b/test/Sema/warn-unused-function.c
@@ -35,3 +35,15 @@ void bar2(void) { }
__attribute__((destructor)) static void bar3(void);
void bar3(void) { }
+
+static void f10(void); // expected-warning{{unused}}
+static void f10(void);
+
+static void f11(void);
+static void f11(void) { } // expected-warning{{unused}}
+
+static void f12(void) { } // expected-warning{{unused}}
+static void f12(void);
+
+// PR7923
+static void unused(void) { unused(); } // expected-warning{{unused}}
diff --git a/test/Sema/warn-write-strings.c b/test/Sema/warn-write-strings.c
index 04af00c..c936a12 100644
--- a/test/Sema/warn-write-strings.c
+++ b/test/Sema/warn-write-strings.c
@@ -2,3 +2,9 @@
// PR4804
char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'char const [4]' discards qualifiers}}
+
+// PR7192
+#include <stddef.h>
+void test(wchar_t *dst) {
+ dst[0] = 0; // Ok.
+}
OpenPOWER on IntegriCloud