summaryrefslogtreecommitdiff
path: root/test/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/address_spaces.c16
-rw-r--r--test/Sema/align-arm-apcs.c4
-rw-r--r--test/Sema/altivec-init.c16
-rw-r--r--test/Sema/arg-scope-c99.c2
-rw-r--r--test/Sema/arg-scope.c2
-rw-r--r--test/Sema/array-constraint.c2
-rw-r--r--test/Sema/array-init.c23
-rw-r--r--test/Sema/attr-decl-after-definition.c19
-rw-r--r--test/Sema/attr-deprecated.c2
-rw-r--r--test/Sema/attr-format_arg.c2
-rw-r--r--test/Sema/attr-malloc.c25
-rw-r--r--test/Sema/attr-noreturn.c10
-rw-r--r--test/Sema/attr-section.c10
-rw-r--r--test/Sema/attr-weak.c4
-rw-r--r--test/Sema/bitfield-promote-int-16bit.c25
-rw-r--r--test/Sema/bitfield-promote.c34
-rw-r--r--test/Sema/bitfield.c2
-rw-r--r--test/Sema/block-args.c2
-rw-r--r--test/Sema/block-call.c52
-rw-r--r--test/Sema/block-literal.c82
-rw-r--r--test/Sema/block-misc.c39
-rw-r--r--test/Sema/block-printf-attribute-1.c17
-rw-r--r--test/Sema/block-return-1.c6
-rw-r--r--test/Sema/block-return-2.c5
-rw-r--r--test/Sema/block-return-3.c5
-rw-r--r--test/Sema/block-return.c6
-rw-r--r--test/Sema/block-sentinel-attribute.c25
-rw-r--r--test/Sema/builtin-prefetch.c2
-rw-r--r--test/Sema/builtin-unary-fp.c12
-rw-r--r--test/Sema/builtins.c32
-rw-r--r--test/Sema/c89-2.c6
-rw-r--r--test/Sema/c89.c4
-rw-r--r--test/Sema/compare.c23
-rw-r--r--test/Sema/complex-int.c5
-rw-r--r--test/Sema/conditional.c10
-rw-r--r--test/Sema/darwin-align-cast.c5
-rw-r--r--test/Sema/decl-type-merging.c10
-rw-r--r--test/Sema/enum.c2
-rw-r--r--test/Sema/exprs.c11
-rw-r--r--test/Sema/floating-point-compare.c4
-rw-r--r--test/Sema/format-attr-pr4470.c1
-rw-r--r--test/Sema/format-attribute-printf0.c26
-rw-r--r--test/Sema/freemain.c9
-rw-r--r--test/Sema/function-pointer-sentinel-attribute.c23
-rw-r--r--test/Sema/function-sentinel-attr.c2
-rw-r--r--test/Sema/function.c2
-rw-r--r--test/Sema/heinous-extensions-on.c13
-rw-r--r--test/Sema/implicit-builtin-redecl.c12
-rw-r--r--test/Sema/implicit-int.c9
-rw-r--r--test/Sema/incomplete-call.c4
-rw-r--r--test/Sema/incomplete-decl.c5
-rw-r--r--test/Sema/pragma-pack-4.c19
-rw-r--r--test/Sema/pragma-unused.c9
-rw-r--r--test/Sema/predefined-function.c17
-rw-r--r--test/Sema/promote-int-16bit.c6
-rw-r--r--test/Sema/redefinition.c4
-rw-r--r--test/Sema/return-noreturn.c29
-rw-r--r--test/Sema/return.c210
-rw-r--r--test/Sema/shift.c38
-rw-r--r--test/Sema/static-init.c4
-rw-r--r--test/Sema/struct-decl.c20
-rw-r--r--test/Sema/tentative-decls.c2
-rw-r--r--test/Sema/transparent-union-pointer.c8
-rw-r--r--test/Sema/type-spec-struct-union.c2
-rw-r--r--test/Sema/unused-expr.c54
-rw-r--r--test/Sema/va_arg_x86_64.c9
-rw-r--r--test/Sema/vector-cast.c2
-rw-r--r--test/Sema/warn-char-subscripts.c64
-rw-r--r--test/Sema/warn-unused-variables.c19
-rw-r--r--test/Sema/x86-intrinsics-headers.c24
70 files changed, 948 insertions, 261 deletions
diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c
index b79799f0230c..d9d23edb3cf4 100644
--- a/test/Sema/address_spaces.c
+++ b/test/Sema/address_spaces.c
@@ -4,7 +4,11 @@
#define _AS2 __attribute__((address_space(2)))
#define _AS3 __attribute__((address_space(3)))
-void foo(_AS3 float *a) {
+void bar(_AS2 int a); // expected-error {{parameter may not be qualified with an address space}}
+
+void foo(_AS3 float *a,
+ _AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
+{
_AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
_AS1 float * _AS2 *B;
@@ -15,7 +19,13 @@ void foo(_AS3 float *a) {
_AS1 int array[5]; // expected-error {{automatic variable qualified with an address space}}
_AS1 int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}}
- *a = 5.0f;
+ __attribute__((address_space(-1))) int *_boundsA; // expected-error {{address space is negative}}
+ __attribute__((address_space(0xFFFFFF))) int *_boundsB;
+ __attribute__((address_space(0x1000000))) int *_boundsC; // expected-error {{address space is larger than the maximum supported}}
+ // chosen specifically to overflow 32 bits and come out reasonable
+ __attribute__((address_space(4294967500))) int *_boundsD; // expected-error {{address space is larger than the maximum supported}}
+
+ *a = 5.0f + b;
}
struct _st {
@@ -27,6 +37,6 @@ struct _st {
__attribute__((address_space(256))) void * * const base = 0;
void * get_0(void) {
return base[0]; // expected-error {{illegal implicit cast between two pointers with different address spaces}} \
- expected-warning {{returning 'void __attribute__((address_space(256)))*' discards qualifiers, expected 'void *'}}
+ expected-warning {{returning 'void __attribute__((address_space(256))) *' discards qualifiers, expected 'void *'}}
}
diff --git a/test/Sema/align-arm-apcs.c b/test/Sema/align-arm-apcs.c
new file mode 100644
index 000000000000..924ba9034d8b
--- /dev/null
+++ b/test/Sema/align-arm-apcs.c
@@ -0,0 +1,4 @@
+// RUN: clang-cc -triple arm-unknown-unknown -target-abi=apcs-gnu -fsyntax-only -verify %s
+
+struct s0 { double f0; int f1; };
+char chk0[__alignof__(struct s0) == 4 ? 1 : -1];
diff --git a/test/Sema/altivec-init.c b/test/Sema/altivec-init.c
new file mode 100644
index 000000000000..6185186903b0
--- /dev/null
+++ b/test/Sema/altivec-init.c
@@ -0,0 +1,16 @@
+// RUN: clang-cc %s -faltivec -verify -pedantic -fsyntax-only -fblocks=0
+
+typedef int v4 __attribute((vector_size(16)));
+typedef short v8 __attribute((vector_size(16)));
+
+v8 foo(void) {
+ v8 a;
+ v4 b;
+ a = (v8){4, 2}; // expected-error {{too few elements in vector initialization (expected 8 elements, have 2)}}
+ b = (v4)(5, 6, 7, 8, 9); // expected-warning {{excess elements in vector initializer}}
+ b = (v4)(5, 6, 8, 8.0f);
+ return (v8){0, 1, 2, 3, 1, 2, 3, 4};
+
+ // FIXME: test that (type)(fn)(args) still works with -faltivec
+ // FIXME: test that c++ overloaded commas still work -faltivec
+}
diff --git a/test/Sema/arg-scope-c99.c b/test/Sema/arg-scope-c99.c
index b5b1c8a812c1..1d81410b8d01 100644
--- a/test/Sema/arg-scope-c99.c
+++ b/test/Sema/arg-scope-c99.c
@@ -1,2 +1,2 @@
// RUN: clang-cc -fsyntax-only -std=c99 -verify %s
-int bb(int sz, int ar[sz][sz]) { }
+void bb(int sz, int ar[sz][sz]) { }
diff --git a/test/Sema/arg-scope.c b/test/Sema/arg-scope.c
index c1cc7e112f88..d5e59603cfbf 100644
--- a/test/Sema/arg-scope.c
+++ b/test/Sema/arg-scope.c
@@ -1,5 +1,5 @@
// RUN: clang-cc -fsyntax-only -verify %s
-int aa(int b, int x[sizeof b]) {}
+void aa(int b, int x[sizeof b]) {}
void foo(int i, int A[i]) {}
diff --git a/test/Sema/array-constraint.c b/test/Sema/array-constraint.c
index 5a09e20ecbff..6407b5daf56a 100644
--- a/test/Sema/array-constraint.c
+++ b/test/Sema/array-constraint.c
@@ -45,7 +45,7 @@ typedef int TA[I]; // expected-error {{variable length array declaration not all
void strFunc(char *);
const char staticAry[] = "test";
-int checkStaticAry() {
+void checkStaticAry() {
strFunc(staticAry); // expected-warning{{passing 'char const [5]' discards qualifiers, expected 'char *'}}
}
diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c
index 50148a83ae13..c78fd29a89c1 100644
--- a/test/Sema/array-init.c
+++ b/test/Sema/array-init.c
@@ -144,12 +144,11 @@ int xx_sizecheck[(sizeof(xx) / sizeof(char)) == 5? 1 : -1];
static char const yy[5] = "test";
static char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}}
-void charArrays()
-{
- static char const test[] = "test";
- int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1];
- static char const test2[] = { "weird stuff" };
- static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}}
+void charArrays() {
+ static char const test[] = "test";
+ int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1];
+ static char const test2[] = { "weird stuff" };
+ static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}}
char* cp[] = { "Hello" };
@@ -219,10 +218,10 @@ void varArray() {
}
// PR2151
-int 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 extension}} expected-error{{initializer for aggregate with no elements}}
-int noNamedInit() {
-struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}}
+void noNamedInit() {
+ struct {int:5;} x[] = {6}; //expected-error{{initializer for aggregate with no elements}}
}
struct {int a; int:5;} noNamedImplicit[] = {1,2,3};
int noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit) ? 1 : -1];
@@ -230,15 +229,15 @@ int noNamedImplicitCheck[sizeof(noNamedImplicit) == 3 * sizeof(*noNamedImplicit)
// ptrs are constant
struct soft_segment_descriptor {
- long ssd_base;
+ long ssd_base;
};
static int dblfault_tss;
union uniao { int ola; } xpto[1];
struct soft_segment_descriptor gdt_segs[] = {
- {(long) &dblfault_tss},
- { (long)xpto},
+ {(long) &dblfault_tss},
+ { (long)xpto},
};
static void sppp_ipv6cp_up();
diff --git a/test/Sema/attr-decl-after-definition.c b/test/Sema/attr-decl-after-definition.c
new file mode 100644
index 000000000000..c1d1b536fc69
--- /dev/null
+++ b/test/Sema/attr-decl-after-definition.c
@@ -0,0 +1,19 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+void foo();
+void foo() __attribute__((unused));
+void foo() __attribute__((unused));
+void foo(){} // expected-note {{previous definition is here}}
+void foo() __attribute__((constructor)); // expected-warning {{must precede definition}}
+void foo();
+
+int bar;
+extern int bar;
+int bar;
+int bar __attribute__((weak));
+int bar __attribute__((used));
+extern int bar __attribute__((weak));
+int bar = 0; // expected-note {{previous definition is here}}
+int bar __attribute__((weak)); // expected-warning {{must precede definition}}
+int bar;
+
diff --git a/test/Sema/attr-deprecated.c b/test/Sema/attr-deprecated.c
index 6597bad4b572..e15381e4c6d1 100644
--- a/test/Sema/attr-deprecated.c
+++ b/test/Sema/attr-deprecated.c
@@ -21,7 +21,7 @@ int a() {
// test if attributes propagate to variables
extern int var;
int w() {
- return var; // expected-warning {{'var' is deprecated}}
+ return var; // expected-warning {{'var' is deprecated}}
}
int old_fn() __attribute__ ((deprecated));
diff --git a/test/Sema/attr-format_arg.c b/test/Sema/attr-format_arg.c
index 6f953155f8c8..0830951acc89 100644
--- a/test/Sema/attr-format_arg.c
+++ b/test/Sema/attr-format_arg.c
@@ -1,3 +1,5 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
#include <stdio.h>
const char* f(const char *s) __attribute__((format_arg(1)));
diff --git a/test/Sema/attr-malloc.c b/test/Sema/attr-malloc.c
new file mode 100644
index 000000000000..1adcf074a499
--- /dev/null
+++ b/test/Sema/attr-malloc.c
@@ -0,0 +1,25 @@
+// RUN: clang-cc -verify -fsyntax-only %s &&
+// RUN: clang-cc -emit-llvm -o %t %s &&
+
+#include <stdlib.h>
+
+int no_vars __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+
+void returns_void (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+int returns_int (void) __attribute((malloc)); // expected-warning {{functions returning a pointer type}}
+int * returns_intptr(void) __attribute((malloc)); // no-warning
+typedef int * iptr;
+iptr returns_iptr (void) __attribute((malloc)); // no-warning
+
+__attribute((malloc)) void *(*f)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
+__attribute((malloc)) int (*g)(); // expected-warning{{'malloc' attribute only applies to functions returning a pointer type}}
+
+__attribute((malloc))
+void * xalloc(unsigned n) { return malloc(n); } // no-warning
+// RUN: grep 'define noalias .* @xalloc(' %t &&
+
+#define malloc_like __attribute((__malloc__))
+void * xalloc2(unsigned) malloc_like;
+void * xalloc2(unsigned n) { return malloc(n); }
+// RUN: grep 'define noalias .* @xalloc2(' %t
+
diff --git a/test/Sema/attr-noreturn.c b/test/Sema/attr-noreturn.c
index d1417f093ffb..b83eb94e0582 100644
--- a/test/Sema/attr-noreturn.c
+++ b/test/Sema/attr-noreturn.c
@@ -4,7 +4,7 @@ static void (*fp0)(void) __attribute__((noreturn));
static void __attribute__((noreturn)) f0(void) {
fatal();
-}
+} // expected-warning {{function declared 'noreturn' should not return}}
// On K&R
int f1() __attribute__((noreturn));
@@ -25,3 +25,11 @@ void f4() {
return; // expected-warning {{function 'f4' declared 'noreturn' should not return}}
}
+// PR4685
+extern void f5 (unsigned long) __attribute__ ((__noreturn__));
+
+void
+f5 (unsigned long size)
+{
+
+}
diff --git a/test/Sema/attr-section.c b/test/Sema/attr-section.c
new file mode 100644
index 000000000000..c61ed80cbf7a
--- /dev/null
+++ b/test/Sema/attr-section.c
@@ -0,0 +1,10 @@
+// RUN: clang-cc -verify -fsyntax-only -triple x86_64-apple-darwin9 %s
+
+int x __attribute__((section(
+ 42))); // expected-error {{argument to section attribute was not a string literal}}
+
+
+// rdar://4341926
+int y __attribute__((section(
+ "sadf"))); // expected-error {{mach-o section specifier requires a segment and section separated by a comma}}
+
diff --git a/test/Sema/attr-weak.c b/test/Sema/attr-weak.c
index b79e1e7dfca7..4532cccf98d9 100644
--- a/test/Sema/attr-weak.c
+++ b/test/Sema/attr-weak.c
@@ -5,9 +5,11 @@ extern int g1 __attribute__((weak_import));
int g2 __attribute__((weak));
int g3 __attribute__((weak_import)); // expected-warning {{'weak_import' attribute cannot be specified on a definition}}
int __attribute__((weak_import)) g4(void);
-int __attribute__((weak_import)) g5(void) {
+void __attribute__((weak_import)) g5(void) {
}
struct __attribute__((weak)) s0 {}; // expected-warning {{'weak' attribute only applies to variable and function types}}
struct __attribute__((weak_import)) s1 {}; // expected-warning {{'weak_import' attribute only applies to variable and function types}}
+static int x __attribute__((weak)); // expected-error {{weak declaration of 'x' must be public}}
+
diff --git a/test/Sema/bitfield-promote-int-16bit.c b/test/Sema/bitfield-promote-int-16bit.c
new file mode 100644
index 000000000000..12d47205e87d
--- /dev/null
+++ b/test/Sema/bitfield-promote-int-16bit.c
@@ -0,0 +1,25 @@
+// RUN: clang-cc -fsyntax-only -verify %s -triple pic16-unknown-unknown
+
+// Check that int-sized unsigned bit-fields promote to unsigned int
+// on targets where sizeof(unsigned short) == sizeof(unsigned int)
+
+enum E { ec1, ec2, ec3 };
+struct S {
+ enum E e : 16;
+ unsigned short us : 16;
+ unsigned long ul1 : 8;
+ unsigned long ul2 : 16;
+} s;
+
+__typeof(s.e + s.e) x_e;
+unsigned x_e;
+
+__typeof(s.us + s.us) x_us;
+unsigned x_us;
+
+__typeof(s.ul1 + s.ul1) x_ul1;
+signed x_ul1;
+
+__typeof(s.ul2 + s.ul2) x_ul2;
+unsigned x_ul2;
+
diff --git a/test/Sema/bitfield-promote.c b/test/Sema/bitfield-promote.c
new file mode 100644
index 000000000000..066f5d78e715
--- /dev/null
+++ b/test/Sema/bitfield-promote.c
@@ -0,0 +1,34 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+struct {unsigned x : 2;} x;
+__typeof__((x.x+=1)+1) y;
+__typeof__(x.x<<1) y;
+int y;
+
+
+struct { int x : 8; } x1;
+long long y1;
+__typeof__(((long long)x1.x + 1)) y1;
+
+
+// Check for extensions: variously sized unsigned bit-fields fitting
+// into a signed int promote to signed int.
+enum E { ec1, ec2, ec3 };
+struct S {
+ enum E e : 2;
+ unsigned short us : 4;
+ unsigned long long ul1 : 8;
+ unsigned long long ul2 : 50;
+} s;
+
+__typeof(s.e + s.e) x_e;
+int x_e;
+
+__typeof(s.us + s.us) x_us;
+int x_us;
+
+__typeof(s.ul1 + s.ul1) x_ul1;
+int x_ul1;
+
+__typeof(s.ul2 + s.ul2) x_ul2;
+unsigned long long x_ul2;
+
diff --git a/test/Sema/bitfield.c b/test/Sema/bitfield.c
index 655f74121a32..581af6d0c5ea 100644
--- a/test/Sema/bitfield.c
+++ b/test/Sema/bitfield.c
@@ -21,7 +21,7 @@ struct a {
int g : (_Bool)1;
// PR4017
- char : 10; // expected-error {{size of anonymous bitfield exceeds size of its type (8 bits)}}
+ char : 10; // expected-error {{size of anonymous bit-field exceeds size of its type (8 bits)}}
unsigned : -2; // expected-error {{anonymous bit-field has negative width (-2)}}
float : 12; // expected-error {{anonymous bit-field has non-integral type 'float'}}
};
diff --git a/test/Sema/block-args.c b/test/Sema/block-args.c
index 27bee77da6c6..3a58735f23a3 100644
--- a/test/Sema/block-args.c
+++ b/test/Sema/block-args.c
@@ -22,7 +22,7 @@ void test() {
^(int x, ...){return 5;}(arg, arg); // Explicit varargs, ok.
}
-int main(int argc) {
+int main(int argc, char** argv) {
^(int argCount) {
argCount = 3;
}(argc);
diff --git a/test/Sema/block-call.c b/test/Sema/block-call.c
index c42b642337ca..893a8f61da8d 100644
--- a/test/Sema/block-call.c
+++ b/test/Sema/block-call.c
@@ -5,51 +5,47 @@ int (^IFP) ();
int (^II) (int);
int main() {
int (*FPL) (int) = FP; // C doesn't consider this an error.
-
+
// For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
int (^PFR) (int) = IFP; // OK
- PFR = II; // OK
-
- int (^IFP) () = PFR; // OK
-
+ PFR = II; // OK
- const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}}
+ int (^IFP) () = PFR; // OK
- const int (^CICC) () = CIC;
+ const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}}
- int * const (^IPCC) () = 0;
+ const int (^CICC) () = CIC;
- int * const (^IPCC1) () = IPCC;
+ int * const (^IPCC) () = 0;
- int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}}
+ int * const (^IPCC1) () = IPCC;
- int (^IPCC3) (const int) = PFR;
+ int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}}
+ int (^IPCC3) (const int) = PFR;
- int (^IPCC4) (int, char (^CArg) (double));
+ int (^IPCC4) (int, char (^CArg) (double));
+ int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
- int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
+ int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(double))', expected 'int (^)(int, char (^)(float))'}}
- int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(double))', expected 'int (^)(int, char (^)(float))'}}
-
- IPCC2 = 0;
- IPCC2 = 1; // expected-error {{invalid conversion assigning integer 'int', expected block pointer 'int *(^)()'}}
- int (^x)() = 0;
- int (^y)() = 3; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
- int a = 1;
- int (^z)() = a+4; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
+ IPCC2 = 0;
+ IPCC2 = 1; // expected-error {{invalid conversion assigning integer 'int', expected block pointer 'int *(^)()'}}
+ int (^x)() = 0;
+ int (^y)() = 3; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
+ int a = 1;
+ int (^z)() = a+4; // expected-error {{invalid conversion initializing integer 'int', expected block pointer 'int (^)()'}}
}
int blah() {
- int (^IFP) (float);
- char (^PCP)(double, double, char);
+ int (^IFP) (float);
+ char (^PCP)(double, double, char);
- IFP(1.0);
- IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
+ IFP(1.0);
+ IFP (1.0, 2.0); // expected-error {{too many arguments to block call}}
- char ch = PCP(1.0, 2.0, 'a');
- return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
+ char ch = PCP(1.0, 2.0, 'a');
+ return PCP(1.0, 2.0); // expected-error {{too few arguments to block}}
}
-
diff --git a/test/Sema/block-literal.c b/test/Sema/block-literal.c
index 19d476fc294f..9f5022dc6387 100644
--- a/test/Sema/block-literal.c
+++ b/test/Sema/block-literal.c
@@ -8,40 +8,40 @@ int printf(const char*, ...);
typedef void (^T) (void);
-void takeclosure(T);
+void takeblock(T);
int takeintint(int (^C)(int)) { return C(4); }
T somefunction() {
- if (^{ })
- nothing();
+ if (^{ })
+ nothing();
- noop = ^{};
+ noop = ^{};
- noop = ^{printf("\nClosure\n"); };
+ noop = ^{printf("\nClosure\n"); };
- I(^{ });
+ I(^{ });
- return ^{printf("\nClosure\n"); };
+ return ^{printf("\nClosure\n"); };
}
void test2() {
- int x = 4;
+ int x = 4;
- takeclosure(^{ printf("%d\n", x); });
+ takeblock(^{ printf("%d\n", x); });
while (1) {
- takeclosure(^{
- break; // expected-error {{'break' statement not in loop or switch statement}}
- continue; // expected-error {{'continue' statement not in loop statement}}
- while(1) break; // ok
- goto foo; // expected-error {{goto not allowed}}
- });
+ takeblock(^{
+ break; // expected-error {{'break' statement not in loop or switch statement}}
+ continue; // expected-error {{'continue' statement not in loop statement}}
+ while(1) break; // ok
+ goto foo; // expected-error {{goto not allowed}}
+ });
break;
- }
+ }
-foo:
- takeclosure(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
+ foo:
+ takeblock(^{ x = 4; }); // expected-error {{variable is not assignable (missing __block type specifier)}}
__block y = 7; // expected-warning {{type specifier missing, defaults to 'int'}}
- takeclosure(^{ y = 8; });
+ takeblock(^{ y = 8; });
}
@@ -59,11 +59,11 @@ void myfunc(int (^block)(int)) {}
void myfunc3(const int *x);
void test5() {
- int a;
+ int a;
- myfunc(^(int abcd) {
- myfunc3(&a);
- return 1;
+ myfunc(^(int abcd) {
+ myfunc3(&a);
+ return 1;
});
}
@@ -86,39 +86,3 @@ typedef void (^void_block_t)(void);
static const void_block_t myBlock = ^{ };
static const void_block_t myBlock2 = ^ void(void) { };
-
-#if 0
-// Old syntax. FIXME: convert/test.
-void test_byref() {
- int i;
-
- X = ^{| g |}; // error {{use of undeclared identifier 'g'}}
-
- X = ^{| i,i,i | };
-
- X = ^{|i| i = 0; };
-
-}
-
-// TODO: global closures someday.
-void *A = ^{};
-void *B = ^(int){ A = 0; };
-
-
-// Closures can not take return types at this point.
-void test_retvals() {
- // Explicit return value.
- ^int{}; // error {{closure with explicit return type requires argument list}}
- X = ^void(){};
-
- // Optional specification of return type.
- X = ^char{ return 'x'; }; // error {{closure with explicit return type requires argument list}}
-
- X = ^/*missing declspec*/ *() { return (void*)0; };
- X = ^void*() { return (void*)0; };
-
- //X = ^char(short c){ if (c) return c; else return (int)4; };
-
-}
-
-#endif
diff --git a/test/Sema/block-misc.c b/test/Sema/block-misc.c
index 294c295c5f8c..8661fd8a5227 100644
--- a/test/Sema/block-misc.c
+++ b/test/Sema/block-misc.c
@@ -4,37 +4,37 @@ void donotwarn();
int (^IFP) ();
int (^II) (int);
int test1() {
- int (^PFR) (int) = 0; // OK
- PFR = II; // OK
+ int (^PFR) (int) = 0; // OK
+ PFR = II; // OK
- if (PFR == II) // OK
+ if (PFR == II) // OK
donotwarn();
- if (PFR == IFP) // OK
+ if (PFR == IFP) // OK
donotwarn();
if (PFR == (int (^) (int))IFP) // OK
donotwarn();
- if (PFR == 0) // OK
+ if (PFR == 0) // OK
donotwarn();
- if (PFR) // OK
+ if (PFR) // OK
donotwarn();
- if (!PFR) // OK
+ if (!PFR) // OK
donotwarn();
- return PFR != IFP; // OK
+ return PFR != IFP; // OK
}
int test2(double (^S)()) {
double (^I)(int) = (void*) S;
- (void*)I = (void *)S; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
+ (void*)I = (void *)S; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
void *pv = I;
- pv = S;
+ pv = S;
I(1);
@@ -44,7 +44,7 @@ int test2(double (^S)()) {
int^ x; // expected-error {{block pointer to non-function type is invalid}}
int^^ x1; // expected-error {{block pointer to non-function type is invalid}} expected-error {{block pointer to non-function type is invalid}}
-int test3() {
+void test3() {
char *^ y; // expected-error {{block pointer to non-function type is invalid}}
}
@@ -114,7 +114,7 @@ void test11(int i) {
void (^test12f)(void);
void test12() {
- test12f = ^test12f; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}}
+ test12f = ^test12f; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}}
}
// rdar://6808730
@@ -144,7 +144,7 @@ void foo(long (^comp)()) {
void (^test15f)(void);
void test15() {
- foo(^{ return LESS; }); // expected-error {{incompatible block pointer types passing 'int (^)(void)', expected 'long (^)()'}}
+ foo(^{ return LESS; }); // expected-error {{incompatible block pointer types passing 'int (^)(void)', expected 'long (^)()'}}
}
__block int test16i; // expected-error {{__block attribute not allowed, only allowed on local variables}}
@@ -185,3 +185,16 @@ void test18() {
void (^const blockA)(void) = ^{ };
blockA = ^{ }; // expected-error {{read-only variable is not assignable}}
}
+
+// rdar://7072507
+int test19() {
+ goto L0; // expected-error {{illegal goto into protected scope}}
+
+ __block int x; // expected-note {{jump bypasses setup of __block variable}}
+L0:
+ x = 0;
+ ^(){ ++x; }();
+ return x;
+}
+
+
diff --git a/test/Sema/block-printf-attribute-1.c b/test/Sema/block-printf-attribute-1.c
index ce30b8e855b7..4941ae7bc679 100644
--- a/test/Sema/block-printf-attribute-1.c
+++ b/test/Sema/block-printf-attribute-1.c
@@ -1,15 +1,12 @@
// RUN: clang-cc %s -fsyntax-only -verify -fblocks
-int main()
-{
- void (^b) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 1, 3))) = // expected-error {{format argument not a string type}}
- ^ __attribute__ ((__format__ (__printf__, 1, 3))) (int arg, const char * format, ...) {}; // expected-error {{format argument not a string type}}
+int main() {
+ void (^b) (int arg, const char * format, ...) __attribute__ ((__format__ (__printf__, 1, 3))) = // expected-error {{format argument not a string type}}
+ ^ __attribute__ ((__format__ (__printf__, 1, 3))) (int arg, const char * format, ...) {}; // expected-error {{format argument not a string type}}
- 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
+ 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
}
-
diff --git a/test/Sema/block-return-1.c b/test/Sema/block-return-1.c
new file mode 100644
index 000000000000..2da87351e4f5
--- /dev/null
+++ b/test/Sema/block-return-1.c
@@ -0,0 +1,6 @@
+// RUN: clang-cc -fsyntax-only %s -verify -fblocks
+
+int j;
+void foo() {
+ ^ (void) { if (j) return 1; }(); // expected-error {{control may reach end of non-void block}}
+}
diff --git a/test/Sema/block-return-2.c b/test/Sema/block-return-2.c
new file mode 100644
index 000000000000..d389f4e4ffcc
--- /dev/null
+++ b/test/Sema/block-return-2.c
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only %s -verify -fblocks
+
+void foo() {
+ ^ (void) __attribute__((noreturn)) { }(); // expected-error {{block declared 'noreturn' should not return}}
+}
diff --git a/test/Sema/block-return-3.c b/test/Sema/block-return-3.c
new file mode 100644
index 000000000000..e7e9342e02f4
--- /dev/null
+++ b/test/Sema/block-return-3.c
@@ -0,0 +1,5 @@
+// RUN: clang-cc -fsyntax-only %s -verify -fblocks
+
+void foo() {
+ ^ int (void) { }(); // expected-error {{control reaches end of non-void block}}
+}
diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c
index 87f4040be9d0..98a72731d672 100644
--- a/test/Sema/block-return.c
+++ b/test/Sema/block-return.c
@@ -31,7 +31,7 @@ CL foo() {
return (float)1.0;
else
if (2)
- return (double)2.0;
+ return (double)2.0;
return 1;
};
char *(^B)(void) = ^{
@@ -66,7 +66,7 @@ int foo3() {
Boolean (*value_equal)(uintptr_t, uintptr_t) = 0;
cb.isEqual = ^(const CFBasicHash *table, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key) {
- return (Boolean)(uintptr_t)INVOKE_CALLBACK2(value_equal, (uintptr_t)stack_value_or_key1, (uintptr_t)stack_value_or_key2);
+ return (Boolean)(uintptr_t)INVOKE_CALLBACK2(value_equal, (uintptr_t)stack_value_or_key1, (uintptr_t)stack_value_or_key2);
};
}
@@ -91,6 +91,8 @@ bptr foo5(int j) {
if (j)
return ^{ ^{ i=0; }(); }; // expected-error {{returning block that lives on the local stack}}
return ^{ i=0; }; // expected-error {{returning block that lives on the local stack}}
+ return (^{ i=0; }); // expected-error {{returning block that lives on the local stack}}
+ return (void*)(^{ i=0; }); // expected-error {{returning block that lives on the local stack}}
}
int (*funcptr3[5])(long);
diff --git a/test/Sema/block-sentinel-attribute.c b/test/Sema/block-sentinel-attribute.c
index a7d4df108ea7..5628a2c7801f 100644
--- a/test/Sema/block-sentinel-attribute.c
+++ b/test/Sema/block-sentinel-attribute.c
@@ -2,24 +2,23 @@
void (^e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
-int main()
-{
- void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{sentinel' attribute only supported for variadic blocks}}
- void (^b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)) = // expected-note {{block has been explicitly marked sentinel here}}
- ^ __attribute__ ((__sentinel__)) (int arg, const char * format, ...) {};
- void (^z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))) = ^ __attribute__ ((__sentinel__ (2))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}
+int main() {
+ void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{sentinel' attribute only supported for variadic blocks}}
+ void (^b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)) = // expected-note {{block has been explicitly marked sentinel here}}
+ ^ __attribute__ ((__sentinel__)) (int arg, const char * format, ...) {};
+ void (^z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))) = ^ __attribute__ ((__sentinel__ (2))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}
- void (^y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))) = ^ __attribute__ ((__sentinel__ (5))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}
+ void (^y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))) = ^ __attribute__ ((__sentinel__ (5))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}}
- b(1, "%s", (void*)0); // OK
- b(1, "%s", 0); // expected-warning {{missing sentinel in block call}}
- z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in block call}}
- z(1, "%s", (void*)0, 1, 0); // OK
+ b(1, "%s", (void*)0); // OK
+ b(1, "%s", 0); // expected-warning {{missing sentinel in block call}}
+ z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in block call}}
+ z(1, "%s", (void*)0, 1, 0); // OK
- y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in block call}}
+ y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in block call}}
- y(1, "%s", (void*)0,3,4,5,6,7); // OK
+ y(1, "%s", (void*)0,3,4,5,6,7); // OK
}
diff --git a/test/Sema/builtin-prefetch.c b/test/Sema/builtin-prefetch.c
index 6b39e75d5257..bf28277acb81 100644
--- a/test/Sema/builtin-prefetch.c
+++ b/test/Sema/builtin-prefetch.c
@@ -1,6 +1,6 @@
// RUN: clang-cc -fsyntax-only -verify %s
-int foo() {
+void foo() {
int a;
__builtin_prefetch(&a);
__builtin_prefetch(&a, 1);
diff --git a/test/Sema/builtin-unary-fp.c b/test/Sema/builtin-unary-fp.c
new file mode 100644
index 000000000000..70c7a297fbe3
--- /dev/null
+++ b/test/Sema/builtin-unary-fp.c
@@ -0,0 +1,12 @@
+// RUN: clang-cc %s -fsyntax-only -verify -pedantic
+void check(int);
+void a() {
+ check(__builtin_isfinite(1.0f));
+ check(__builtin_isinf(1.0));
+ check(__builtin_isinf_sign(1.0L));
+ check(__builtin_isnan(1.0f));
+ check(__builtin_isnormal(1.0f));
+ 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}}
+}
diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c
index 78b75624ea24..e133d626ee52 100644
--- a/test/Sema/builtins.c
+++ b/test/Sema/builtins.c
@@ -34,10 +34,40 @@ void test7() {
// atomics.
-unsigned char test9(short v) {
+void test9(short v) {
unsigned i, old;
old = __sync_fetch_and_add(); // expected-error {{too few arguments to function call}}
old = __sync_fetch_and_add(&old); // expected-error {{too few arguments to function call}}
old = __sync_fetch_and_add((int**)0, 42i); // expected-warning {{imaginary constants are an extension}}
}
+
+
+// rdar://7236819
+void test10(void) __attribute__((noreturn));
+
+void test10(void) {
+ __asm__("int3");
+ __builtin_unreachable();
+
+ // No warning about falling off the end of a noreturn function.
+}
+
+void test11(int X) {
+ switch (X) {
+ case __builtin_eh_return_data_regno(0): // constant foldable.
+ break;
+ }
+
+ __builtin_eh_return_data_regno(X); // expected-error {{not an integer constant expression}}
+}
+
+// PR5062
+void test12(void) __attribute__((__noreturn__));
+void test12(void) {
+ __builtin_trap(); // no warning because trap is noreturn.
+}
+
+void test_unknown_builtin(int a, int b) {
+ __builtin_foo(a, b); // expected-error{{use of unknown builtin}}
+}
diff --git a/test/Sema/c89-2.c b/test/Sema/c89-2.c
index 723bd7c18d88..50c5f4e5a840 100644
--- a/test/Sema/c89-2.c
+++ b/test/Sema/c89-2.c
@@ -1,7 +1,5 @@
-/* RUN: not clang-cc %s -std=c89 -pedantic-errors
+/* RUN: clang-cc %s -std=c89 -pedantic-errors -verify
*/
-/* We can't put expected-warning lines on #if lines. */
-
-#if 1LL /* expected-warning {{long long}} */
+#if 1LL /* expected-error {{long long}} */
#endif
diff --git a/test/Sema/c89.c b/test/Sema/c89.c
index e7585c31926c..fc50ebed6631 100644
--- a/test/Sema/c89.c
+++ b/test/Sema/c89.c
@@ -25,7 +25,7 @@ void test3(int i) {
int A[i]; /* expected-warning {{variable length array}} */
}
-int test4 = 0LL; /* expected-warning {{long long}} */
+int test4 = 0LL; /* expected-warning {{long long}} */
/* PR1999 */
void test5(register);
@@ -36,7 +36,7 @@ int *__restrict; /* expected-error {{expected identifier}} */
/* Implicit int, always ok */
-test6() {}
+test6() { return 0; }
/* PR2012 */
test7; /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
diff --git a/test/Sema/compare.c b/test/Sema/compare.c
index 51f77317385c..87131bb62183 100644
--- a/test/Sema/compare.c
+++ b/test/Sema/compare.c
@@ -3,11 +3,11 @@
int test(char *C) { // nothing here should warn.
return C != ((void*)0);
return C != (void*)0;
- return C != 0;
+ return C != 0;
+ return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
}
-int equal(char *a, const char *b)
-{
+int equal(char *a, const char *b) {
return a == b;
}
@@ -16,16 +16,21 @@ int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
return a == b; // expected-warning {{comparison of distinct pointer types}}
}
-int pointers(int *a)
-{
- return a > 0; // expected-warning {{ordered comparison between pointer and integer}}
+int pointers(int *a) {
+ return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
+ return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
}
-int function_pointers(int (*a)(int), int (*b)(int))
-{
+int function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) {
return a > b; // expected-warning {{ordered comparison of function pointers}}
return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
+ return a > c; // expected-warning {{comparison of distinct pointer types}}
return a == (void *) 0;
- return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}}
+ return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
+}
+
+int void_pointers(void* foo) {
+ return foo == (void*) 0;
+ return foo == (void*) 1;
}
diff --git a/test/Sema/complex-int.c b/test/Sema/complex-int.c
index 5977b4d1e0cb..6c660899e8a1 100644
--- a/test/Sema/complex-int.c
+++ b/test/Sema/complex-int.c
@@ -44,9 +44,8 @@ TestPairs(7); TestPairs(8);
// rdar://6097730
void test3(_Complex int *x) {
*x = ~*x;
-}
+}
void test4(_Complex float *x) {
*x = ~*x;
-}
-
+}
diff --git a/test/Sema/conditional.c b/test/Sema/conditional.c
index 1c7486a6133e..9f48c349c964 100644
--- a/test/Sema/conditional.c
+++ b/test/Sema/conditional.c
@@ -4,12 +4,10 @@ const char* test1 = 1 ? "i" : 1 == 1 ? "v" : "r";
void _efree(void *ptr);
-int _php_stream_free1()
-{
- return (1 ? free(0) : _efree(0)); // expected-error {{incompatible type returning 'void', expected 'int'}}
+int _php_stream_free1() {
+ return (1 ? free(0) : _efree(0)); // expected-error {{incompatible type returning 'void', expected 'int'}}
}
-int _php_stream_free2()
-{
- return (1 ? _efree(0) : free(0)); // expected-error {{incompatible type returning 'void', expected 'int'}}
+int _php_stream_free2() {
+ return (1 ? _efree(0) : free(0)); // expected-error {{incompatible type returning 'void', expected 'int'}}
}
diff --git a/test/Sema/darwin-align-cast.c b/test/Sema/darwin-align-cast.c
index 09808b5af2e8..fed898319157 100644
--- a/test/Sema/darwin-align-cast.c
+++ b/test/Sema/darwin-align-cast.c
@@ -8,10 +8,10 @@ struct cmsghdr {};
#if 0
This code below comes from the following system headers:
-sys/socket.h:#define CMSG_SPACE(l) (__DARWIN_ALIGN(sizeof(struct
+sys/socket.h:#define CMSG_SPACE(l) (__DARWIN_ALIGN(sizeof(struct
cmsghdr)) + __DARWIN_ALIGN(l))
-i386/_param.h:#define __DARWIN_ALIGN(p) ((__darwin_size_t)((char *)(p)
+i386/_param.h:#define __DARWIN_ALIGN(p) ((__darwin_size_t)((char *)(p)
+ __DARWIN_ALIGNBYTES) &~ __DARWIN_ALIGNBYTES)
#endif
@@ -19,5 +19,6 @@ ssize_t sendFileDescriptor(int fd, void *data, size_t nbytes, int sendfd) {
union {
char control[(((__darwin_size_t)((char *)(sizeof(struct cmsghdr)) + (sizeof(__darwin_size_t) - 1)) &~ (sizeof(__darwin_size_t) - 1)) + ((__darwin_size_t)((char *)(sizeof(int)) + (sizeof(__darwin_size_t) - 1)) &~ (sizeof(__darwin_size_t) - 1)))];
} control_un;
+ return 0;
}
diff --git a/test/Sema/decl-type-merging.c b/test/Sema/decl-type-merging.c
index 1b789a142ade..1a8601298e9a 100644
--- a/test/Sema/decl-type-merging.c
+++ b/test/Sema/decl-type-merging.c
@@ -6,11 +6,11 @@ int testx[(sizeof(x) == sizeof(int) * 10) ? 1 : -1];
int (*a)(int (*x)[10], int (*y)[]);
int (*a)(int (*x)[], int (*y)[5]);
-int b() {
-int x[10], y[5];
-a(&x, &y);
-a(&y, &y); // expected-warning {{incompatible pointer}}
-a(&x, &x); // expected-warning {{incompatible pointer}}
+void b() {
+ int x[10], y[5];
+ a(&x, &y);
+ a(&y, &y); // expected-warning {{incompatible pointer}}
+ a(&x, &x); // expected-warning {{incompatible pointer}}
}
diff --git a/test/Sema/enum.c b/test/Sema/enum.c
index adb937551237..31649e0ae9ed 100644
--- a/test/Sema/enum.c
+++ b/test/Sema/enum.c
@@ -43,7 +43,7 @@ void test4() {
;
(_Bool)ve2; // expected-error {{arithmetic or pointer type is required}}
- for (; ;ve2)
+ for (; ;ve2) // expected-warning {{expression result unused}}
;
(void)ve2;
ve2; // expected-warning {{expression result unused}}
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
index 3fd1437da880..69a2320397fd 100644
--- a/test/Sema/exprs.c
+++ b/test/Sema/exprs.c
@@ -60,9 +60,9 @@ int test8(void) {
struct f { int x : 4; float y[]; };
int test9(struct f *P) {
int R;
- R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bitfield}}
+ R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bit-field}}
R = __alignof(P->y); // ok.
- R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bitfield}}
+ R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bit-field}}
return R;
}
@@ -94,15 +94,12 @@ void test13(
P = ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
}
-
-// rdar://6326239 - Vector comparisons are not fully trusted yet, until the
-// backend is known to work, just unconditionally reject them.
void test14() {
typedef long long __m64 __attribute__((__vector_size__(8)));
typedef short __v4hi __attribute__((__vector_size__(8)));
+ // Ok.
__v4hi a;
- __m64 mask = (__m64)((__v4hi)a > // expected-error {{comparison of vector types ('__v4hi' and '__v4hi') not supported yet}}
- (__v4hi)a);
+ __m64 mask = (__m64)((__v4hi)a > (__v4hi)a);
}
diff --git a/test/Sema/floating-point-compare.c b/test/Sema/floating-point-compare.c
index 763a8f4b86b4..9888105518d9 100644
--- a/test/Sema/floating-point-compare.c
+++ b/test/Sema/floating-point-compare.c
@@ -13,11 +13,11 @@ int f3(float x) {
}
int f4(float x) {
- return x == 0.0; // no-warning {{comparing}}
+ return x == 0.0; // no-warning {{comparing}}
}
int f5(float x) {
- return x == __builtin_inf(); // no-warning
+ return x == __builtin_inf(); // no-warning
}
int f7(float x) {
diff --git a/test/Sema/format-attr-pr4470.c b/test/Sema/format-attr-pr4470.c
index cba3adf1d6de..c03c573b7274 100644
--- a/test/Sema/format-attr-pr4470.c
+++ b/test/Sema/format-attr-pr4470.c
@@ -1,6 +1,7 @@
// RUN: clang-cc -fsyntax-only -verify -Wformat=2 %s
#include <stdio.h>
+#include <stdarg.h>
const char *foo(const char *format) __attribute__((format_arg(1)));
diff --git a/test/Sema/format-attribute-printf0.c b/test/Sema/format-attribute-printf0.c
new file mode 100644
index 000000000000..fa7eafd52fb8
--- /dev/null
+++ b/test/Sema/format-attribute-printf0.c
@@ -0,0 +1,26 @@
+//RUN: clang-cc -fsyntax-only -verify %s
+
+#include <stdarg.h>
+
+// same as format(printf(...))...
+void a2(const char *a, ...) __attribute__((format(printf0, 1,2))); // no-error
+void b2(const char *a, ...) __attribute__((format(printf0, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}}
+void c2(const char *a, ...) __attribute__((format(printf0, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}}
+void d2(const char *a, int c) __attribute__((format(printf0, 1,2))); // expected-error {{format attribute requires variadic function}}
+void e2(char *str, int c, ...) __attribute__((format(printf0, 2,3))); // expected-error {{format argument not a string type}}
+
+// FreeBSD usage
+#define __printf0like(fmt,va) __attribute__((__format__(__printf0__,fmt,va)))
+void null(int i, const char *a, ...) __printf0like(2,0); // no-error
+void null(int i, const char *a, ...) {
+ if (a)
+ (void)0/* vprintf(...) would go here */;
+}
+
+void callnull(void){
+ null(0, 0); // no error
+ null(0, (char*)0); // no error
+ null(0, (void*)0); // no error
+ null(0, (int*)0); // expected-warning {{incompatible pointer types}}
+}
+
diff --git a/test/Sema/freemain.c b/test/Sema/freemain.c
new file mode 100644
index 000000000000..a2364df259bf
--- /dev/null
+++ b/test/Sema/freemain.c
@@ -0,0 +1,9 @@
+// RUN: clang-cc -fsyntax-only -verify -ffreestanding %s
+
+// Tests that -ffreestanding disables all special treatment of main().
+
+void* allocate(long size);
+
+void* main(void* context, long size) {
+ if (context) return allocate(size);
+} // expected-warning {{control may reach end of non-void function}}
diff --git a/test/Sema/function-pointer-sentinel-attribute.c b/test/Sema/function-pointer-sentinel-attribute.c
index 0de02fa5363c..6d3fb1718076 100644
--- a/test/Sema/function-pointer-sentinel-attribute.c
+++ b/test/Sema/function-pointer-sentinel-attribute.c
@@ -2,22 +2,19 @@
void (*e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1)));
-int main()
-{
- void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}}
- void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}
+int main() {
+ void (*b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)); // expected-note {{function has been explicitly marked sentinel here}}
+ void (*z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))); // expected-note {{function has been explicitly marked sentinel here}}
- void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}
+ void (*y) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (5))); // expected-note {{function has been explicitly marked sentinel here}}
- b(1, "%s", (void*)0); // OK
- b(1, "%s", 0); // expected-warning {{missing sentinel in function call}}
- z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}}
- z(1, "%s", (void*)0, 1, 0); // OK
+ b(1, "%s", (void*)0); // OK
+ b(1, "%s", 0); // expected-warning {{missing sentinel in function call}}
+ z(1, "%s",4 ,1,0); // expected-warning {{missing sentinel in function call}}
+ z(1, "%s", (void*)0, 1, 0); // OK
- y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
-
- y(1, "%s", (void*)0,3,4,5,6,7); // OK
+ y(1, "%s", 1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
+ y(1, "%s", (void*)0,3,4,5,6,7); // OK
}
-
diff --git a/test/Sema/function-sentinel-attr.c b/test/Sema/function-sentinel-attr.c
index 66304796127f..b33b4a063ce2 100644
--- a/test/Sema/function-sentinel-attr.c
+++ b/test/Sema/function-sentinel-attr.c
@@ -18,7 +18,7 @@ int main ()
foo1(1, 0) ; // expected-warning {{missing sentinel in function call}}
foo5(1, NULL, 2); // OK
foo5(1,2,NULL, 1); // OK
- foo5(1, NULL, 2, 1); // expected-warning {{missing sentinel in function call}}
+ foo5(1, NULL, 2, 1); // expected-warning {{missing sentinel in function call}}
foo6(1,2,3,4,5,6,7); // expected-warning {{missing sentinel in function call}}
foo6(1,NULL,3,4,5,6,7); // OK
diff --git a/test/Sema/function.c b/test/Sema/function.c
index c9d8630c47f6..e7a37f1a2fc1 100644
--- a/test/Sema/function.c
+++ b/test/Sema/function.c
@@ -87,3 +87,5 @@ unknown_type t19(int* P) { // expected-error {{unknown type name 'unknown_type
P = P+1; // no warning.
}
+// missing ',' before '...'
+void t20(int i...) { } // expected-error {{requires a comma}}
diff --git a/test/Sema/heinous-extensions-on.c b/test/Sema/heinous-extensions-on.c
index 480b1b41e906..a56f1f6f625c 100644
--- a/test/Sema/heinous-extensions-on.c
+++ b/test/Sema/heinous-extensions-on.c
@@ -1,10 +1,9 @@
// RUN: clang-cc %s -verify -fheinous-gnu-extensions
-int foo() {
- int a;
- // PR3788
- asm("nop" : : "m"((int)(a))); // expected-warning {{cast in a inline asm context requiring an l-value}}
- // PR3794
- asm("nop" : "=r"((unsigned)a)); // expected-warning {{cast in a inline asm context requiring an l-value}}
+void foo() {
+ int a;
+ // PR3788
+ asm("nop" : : "m"((int)(a))); // expected-warning {{cast in a inline asm context requiring an l-value}}
+ // PR3794
+ asm("nop" : "=r"((unsigned)a)); // expected-warning {{cast in a inline asm context requiring an l-value}}
}
-
diff --git a/test/Sema/implicit-builtin-redecl.c b/test/Sema/implicit-builtin-redecl.c
index cd99b5455318..36513bafb050 100644
--- a/test/Sema/implicit-builtin-redecl.c
+++ b/test/Sema/implicit-builtin-redecl.c
@@ -12,3 +12,15 @@ void *calloc(int, int, int); // expected-warning{{incompatible redeclaration of
void f1(void) {
calloc(0, 0, 0);
}
+
+void f2() {
+ int index = 1;
+}
+
+static int index;
+
+int f3() {
+ return index << 2;
+}
+
+typedef int rindex; \ No newline at end of file
diff --git a/test/Sema/implicit-int.c b/test/Sema/implicit-int.c
index 04b27a8f0ea9..5190bdbf934b 100644
--- a/test/Sema/implicit-int.c
+++ b/test/Sema/implicit-int.c
@@ -1,6 +1,7 @@
// RUN: clang-cc -fsyntax-only %s -verify -pedantic
foo() { // expected-warning {{type specifier missing, defaults to 'int'}}
+ return 0;
}
y; // expected-warning {{type specifier missing, defaults to 'int'}}
@@ -11,19 +12,19 @@ void f((x)); // expected-warning {{type specifier missing, defaults to 'int'}}
// PR3702
#define PAD(ms10) { \
- register i; \
+ register i; \
}
-#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
+#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
void
h19_insline(n) // expected-warning {{parameter 'n' was not declared, defaulting to type 'int'}}
{
- ILPAD(); // expected-warning {{type specifier missing, defaults to 'int'}}
+ ILPAD(); // expected-warning {{type specifier missing, defaults to 'int'}}
}
struct foo {
- __extension__ __attribute__((packed)) x : 4; // expected-warning {{type specifier missing, defaults to 'int'}}
+ __extension__ __attribute__((packed)) x : 4;
};
diff --git a/test/Sema/incomplete-call.c b/test/Sema/incomplete-call.c
index aedfe50bbfdd..15d97683c5a0 100644
--- a/test/Sema/incomplete-call.c
+++ b/test/Sema/incomplete-call.c
@@ -2,12 +2,12 @@
struct foo; // expected-note 3 {{forward declaration of 'struct foo'}}
-struct foo a();
+struct foo a(); // expected-note {{'a' declared here}}
void b(struct foo);
void c();
void func() {
- a(); // expected-error{{return type of called function ('struct foo') is incomplete}}
+ a(); // expected-error{{calling 'a' with incomplete return type 'struct foo'}}
b(*(struct foo*)0); // expected-error{{argument type 'struct foo' is incomplete}}
c(*(struct foo*)0); // expected-error{{argument type 'struct foo' is incomplete}}
}
diff --git a/test/Sema/incomplete-decl.c b/test/Sema/incomplete-decl.c
index eb93e8e38031..6a6ba753f3fe 100644
--- a/test/Sema/incomplete-decl.c
+++ b/test/Sema/incomplete-decl.c
@@ -1,12 +1,13 @@
// RUN: clang-cc -fsyntax-only -verify %s
-struct foo; // expected-note 4 {{forward declaration of 'struct foo'}}
+struct foo; // expected-note 5 {{forward declaration of 'struct foo'}}
void b; // expected-error {{variable has incomplete type 'void'}}
struct foo f; // expected-error{{tentative definition has type 'struct foo' that is never completed}}
static void c; // expected-error {{variable has incomplete type 'void'}}
-static struct foo g; // expected-error {{variable has incomplete type 'struct foo'}}
+static struct foo g; // expected-warning {{tentative definition of variable with internal linkage has incomplete non-array type 'struct foo'}} \
+ expected-error{{tentative definition has type 'struct foo' that is never completed}}
extern void d;
extern struct foo e;
diff --git a/test/Sema/pragma-pack-4.c b/test/Sema/pragma-pack-4.c
new file mode 100644
index 000000000000..f6f107da742b
--- /dev/null
+++ b/test/Sema/pragma-pack-4.c
@@ -0,0 +1,19 @@
+// RUN: clang-cc -triple i686-apple-darwin9 %s -fsyntax-only -verify &&
+// RUN: clang-cc -triple x86_64-apple-darwin9 %s -fsyntax-only -verify
+
+// rdar://problem/7095436
+#pragma pack(4)
+
+struct s0 {
+ long long a __attribute__((aligned(8)));
+ long long b __attribute__((aligned(8)));
+ unsigned int c __attribute__((aligned(8)));
+ int d[12];
+};
+
+struct s1 {
+ int a[15];
+ struct s0 b;
+};
+
+int arr0[((sizeof(struct s1) % 64) == 0) ? 1 : -1];
diff --git a/test/Sema/pragma-unused.c b/test/Sema/pragma-unused.c
index fe8bf8608bc3..8b9498962646 100644
--- a/test/Sema/pragma-unused.c
+++ b/test/Sema/pragma-unused.c
@@ -16,7 +16,7 @@ void f2(void) {
}
void f3(void) {
- #pragma unused(x) // expected-error{{use of undeclared identifier 'x'}}
+ #pragma unused(x) // expected-warning{{undeclared variable 'x' used as an argument for '#pragma unused'}}
}
void f4(void) {
@@ -26,7 +26,7 @@ void f4(void) {
int k;
void f5(void) {
- #pragma unused(k) // expected-warning{{only local variables can be arguments to '#pragma unused' - ignored}}
+ #pragma unused(k) // expected-warning{{only local variables can be arguments to '#pragma unused'}}
}
void f6(void) {
@@ -36,3 +36,8 @@ void f6(void) {
}
}
+void f7() {
+ int y;
+ #pragma unused(undeclared, undefined, y) // expected-warning{{undeclared variable 'undeclared' used as an argument for '#pragma unused'}} expected-warning{{undeclared variable 'undefined' used as an argument for '#pragma unused'}}
+}
+
diff --git a/test/Sema/predefined-function.c b/test/Sema/predefined-function.c
index e8ccb3636b8e..c8d17f0078e6 100644
--- a/test/Sema/predefined-function.c
+++ b/test/Sema/predefined-function.c
@@ -8,31 +8,30 @@ int eli(float b); // expected-note {{previous declaration is here}}
int b(int c) {return 1;}
int foo();
-int foo()
-{
- int eli(int (int)); // expected-error {{conflicting types for 'eli'}}
- eli(b); // expected-error{{incompatible type passing}}
- return 0;
+int foo() {
+ int eli(int (int)); // expected-error {{conflicting types for 'eli'}}
+ eli(b); // expected-error{{incompatible type passing}}
+ return 0;
}
int bar();
int bar(int i) // expected-note {{previous definition is here}}
{
- return 0;
+ return 0;
}
int bar() // expected-error {{redefinition of 'bar'}}
{
- return 0;
+ return 0;
}
int foobar(int); // note {{previous declaration is here}}
int foobar() // error {{conflicting types for 'foobar'}}
{
- return 0;
+ return 0;
}
int wibble(); // expected-note {{previous declaration is here}}
float wibble() // expected-error {{conflicting types for 'wibble'}}
{
- return 0.0f;
+ return 0.0f;
}
diff --git a/test/Sema/promote-int-16bit.c b/test/Sema/promote-int-16bit.c
new file mode 100644
index 000000000000..fbd1215d90d2
--- /dev/null
+++ b/test/Sema/promote-int-16bit.c
@@ -0,0 +1,6 @@
+// RUN: clang-cc -fsyntax-only -verify %s -triple pic16-unknown-unknown
+
+// Check that unsigned short promotes to unsigned int on targets where
+// sizeof(unsigned short) == sizeof(unsigned int)
+__typeof(1+(unsigned short)1) x;
+unsigned x;
diff --git a/test/Sema/redefinition.c b/test/Sema/redefinition.c
index 26c90c8e6d4f..9339bb935f6c 100644
--- a/test/Sema/redefinition.c
+++ b/test/Sema/redefinition.c
@@ -1,7 +1,7 @@
// RUN: clang-cc %s -fsyntax-only -verify
-int f(int a) { } // expected-note {{previous definition is here}}
+int f(int a) { return 0; } // expected-note {{previous definition is here}}
int f(int);
-int f(int a) { } // expected-error {{redefinition of 'f'}}
+int f(int a) { return 0; } // expected-error {{redefinition of 'f'}}
// <rdar://problem/6097326>
int foo(x) {
diff --git a/test/Sema/return-noreturn.c b/test/Sema/return-noreturn.c
new file mode 100644
index 000000000000..e2452f407f4f
--- /dev/null
+++ b/test/Sema/return-noreturn.c
@@ -0,0 +1,29 @@
+// RUN: clang-cc %s -fsyntax-only -verify -fblocks -Wmissing-noreturn
+
+int j;
+void test1() { // expected-warning {{function could be attribute 'noreturn'}}
+ ^ (void) { while (1) { } }(); // expected-warning {{block could be attribute 'noreturn'}}
+ ^ (void) { if (j) while (1) { } }();
+ while (1) { }
+}
+
+void test2() {
+ if (j) while (1) { }
+}
+
+__attribute__((__noreturn__))
+void test2_positive() {
+ if (j) while (1) { }
+} // expected-warning{{function declared 'noreturn' should not return}}
+
+
+// This test case illustrates that we don't warn about the missing return
+// because the function is marked noreturn and there is an infinite loop.
+extern int foo_test_3();
+__attribute__((__noreturn__)) void* test3(int arg) {
+ while (1) foo_test_3();
+}
+
+__attribute__((__noreturn__)) void* test3_positive(int arg) {
+ while (0) foo_test_3();
+} // expected-warning{{function declared 'noreturn' should not return}}
diff --git a/test/Sema/return.c b/test/Sema/return.c
index d96cede68a61..64def306ebc8 100644
--- a/test/Sema/return.c
+++ b/test/Sema/return.c
@@ -1,4 +1,4 @@
-// RUN: clang-cc %s -fsyntax-only -verify
+// RUN: clang-cc %s -fsyntax-only -verify -fblocks
// clang emits the following warning by default.
// With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the
@@ -10,3 +10,211 @@ int t14() {
void t15() {
return 1; // expected-warning {{void function 't15' should not return a value}}
}
+
+int unknown();
+
+void test0() {
+}
+
+int test1() {
+} // expected-warning {{control reaches end of non-void function}}
+
+int test2() {
+ a: goto a;
+}
+
+int test3() {
+ goto a;
+ a: ;
+} // expected-warning {{control reaches end of non-void function}}
+
+
+void halt() {
+ a: goto a;
+}
+
+void halt2() __attribute__((noreturn));
+
+int test4() {
+ halt2();
+}
+
+int test5() {
+ halt2(), (void)1;
+}
+
+int test6() {
+ 1, halt2();
+}
+
+int j;
+int unknown_nohalt() {
+ return j;
+}
+
+int test7() {
+ unknown();
+} // expected-warning {{control reaches end of non-void function}}
+
+int test8() {
+ (void)(1 + unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int halt3() __attribute__((noreturn));
+
+int test9() {
+ (void)(halt3() + unknown());
+}
+
+int test10() {
+ (void)(unknown() || halt3());
+} // expected-warning {{control may reach end of non-void function}}
+
+int test11() {
+ (void)(unknown() && halt3());
+} // expected-warning {{control may reach end of non-void function}}
+
+int test12() {
+ (void)(halt3() || unknown());
+}
+
+int test13() {
+ (void)(halt3() && unknown());
+}
+
+int test14() {
+ (void)(1 || unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test15() {
+ (void)(0 || unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test16() {
+ (void)(0 && unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test17() {
+ (void)(1 && unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test18() {
+ (void)(unknown_nohalt() && halt3());
+} // expected-warning {{control may reach end of non-void function}}
+
+int test19() {
+ (void)(unknown_nohalt() && unknown());
+} // expected-warning {{control reaches end of non-void function}}
+
+int test20() {
+ int i;
+ if (i)
+ return 0;
+ else if (0)
+ return 2;
+} // expected-warning {{control may reach end of non-void function}}
+
+int test21() {
+ int i;
+ if (i)
+ return 0;
+ else if (1)
+ return 2;
+}
+
+int test22() {
+ int i;
+ switch (i) default: ;
+} // expected-warning {{control reaches end of non-void function}}
+
+int test23() {
+ int i;
+ switch (i) {
+ case 0:
+ return 0;
+ case 2:
+ return 2;
+ }
+} // expected-warning {{control may reach end of non-void function}}
+
+int test24() {
+ int i;
+ switch (i) {
+ case 0:
+ return 0;
+ case 2:
+ return 2;
+ default:
+ return -1;
+ }
+}
+
+int test25() {
+ 1 ? halt3() : unknown();
+}
+
+int test26() {
+ 0 ? halt3() : unknown();
+} // expected-warning {{control reaches end of non-void function}}
+
+int j;
+void (*fptr)() __attribute__((noreturn));
+int test27() {
+ switch (j) {
+ case 1:
+ do { } while (1);
+ break;
+ case 2:
+ for (;;) ;
+ break;
+ case 3:
+ for (;1;) ;
+ for (;0;) {
+ goto done;
+ }
+ return 1;
+ case 4:
+ while (0) { goto done; }
+ return 1;
+ case 5:
+ while (1) { return 1; }
+ break;
+ case 6:
+ fptr();
+ break;
+ default:
+ return 1;
+ }
+ done: ;
+}
+
+// PR4624
+void test28() __attribute__((noreturn));
+void test28(x) { while (1) { } }
+
+void exit(int);
+int test29() {
+ exit(1);
+}
+
+#include <setjmp.h>
+jmp_buf test30_j;
+int test30() {
+ if (j)
+ longjmp(test30_j, 1);
+ else
+ _longjmp(test30_j, 1);
+}
+
+typedef void test31_t(int status);
+void test31(test31_t *callback __attribute__((noreturn)));
+
+void test32() {
+ ^ (void) { while (1) { } }();
+ ^ (void) { if (j) while (1) { } }();
+ while (1) { }
+}
+
+void test33() {
+ if (j) while (1) { }
+}
diff --git a/test/Sema/shift.c b/test/Sema/shift.c
index 5acbe12ac33e..2516d1b86107 100644
--- a/test/Sema/shift.c
+++ b/test/Sema/shift.c
@@ -1,6 +1,40 @@
-// RUN: clang-cc -fsyntax-only %s
+// RUN: clang-cc -Wall -fsyntax-only -verify %s
+
+#include <limits.h>
+
+enum {
+ X = 1 << 0,
+ Y = 1 << 1,
+ Z = 1 << 2
+};
void test() {
char c;
- c <<= 14;
+
+ c = 0 << 0;
+ c = 0 << 1;
+ c = 1 << 0;
+ c = 1 << -0;
+ c = 1 >> -0;
+ c = 1 << -1; // expected-warning {{shift count is negative}}
+ c = 1 >> -1; // expected-warning {{shift count is negative}}
+ c = 1 << c;
+ c <<= 0;
+ c >>= 0;
+ c <<= 1;
+ c >>= 1;
+ c <<= -1; // expected-warning {{shift count is negative}}
+ c >>= -1; // expected-warning {{shift count is negative}}
+ c <<= 999999; // expected-warning {{shift count >= width of type}}
+ c >>= 999999; // expected-warning {{shift count >= width of type}}
+ c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+ c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+ c <<= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+ c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+ (void)((long)c << CHAR_BIT);
}
+
+#define a 0
+#define ashift 8
+enum { b = (a << ashift) };
+
diff --git a/test/Sema/static-init.c b/test/Sema/static-init.c
index cd495568ca3f..510f3ab099af 100644
--- a/test/Sema/static-init.c
+++ b/test/Sema/static-init.c
@@ -11,11 +11,11 @@ _Bool t = &t;
union bar {
- int i;
+ int i;
};
struct foo {
- unsigned ptr;
+ unsigned ptr;
};
union bar u[1];
diff --git a/test/Sema/struct-decl.c b/test/Sema/struct-decl.c
index 2c0945f9f86b..a5a299bf09b2 100644
--- a/test/Sema/struct-decl.c
+++ b/test/Sema/struct-decl.c
@@ -1,26 +1,26 @@
// RUN: clang-cc -fsyntax-only -verify %s
// PR3459
struct bar {
- char n[1];
+ char n[1];
};
struct foo {
- char name[(int)&((struct bar *)0)->n];
- char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{array size is negative}}
+ char name[(int)&((struct bar *)0)->n];
+ char name2[(int)&((struct bar *)0)->n - 1]; //expected-error{{array size is negative}}
};
// PR3430
struct s {
- struct st {
- int v;
- } *ts;
+ struct st {
+ int v;
+ } *ts;
};
struct st;
int foo() {
- struct st *f;
- return f->v + f[0].v;
+ struct st *f;
+ return f->v + f[0].v;
}
// PR3642, PR3671
@@ -29,8 +29,8 @@ struct pppoe_tag {
char tag_data[];
};
struct datatag {
- struct pppoe_tag hdr; //expected-warning{{field 'hdr' with variable sized type 'struct pppoe_tag' not at the end of a struct or class is a GNU extension}}
- char data;
+ struct pppoe_tag hdr; //expected-warning{{field 'hdr' with variable sized type 'struct pppoe_tag' not at the end of a struct or class is a GNU extension}}
+ char data;
};
diff --git a/test/Sema/tentative-decls.c b/test/Sema/tentative-decls.c
index e3c893c77718..c94af1160b89 100644
--- a/test/Sema/tentative-decls.c
+++ b/test/Sema/tentative-decls.c
@@ -2,7 +2,7 @@
// PR3310
struct a x1; // expected-note 2{{forward declaration of 'struct a'}}
-static struct a x2; // expected-error{{variable has incomplete type 'struct a'}}
+static struct a x2; // expected-warning{{tentative definition of variable with internal linkage has incomplete non-array type 'struct a'}}
struct a x3[10]; // expected-error{{array has incomplete element type 'struct a'}}
struct a {int x;};
static struct a x2_okay;
diff --git a/test/Sema/transparent-union-pointer.c b/test/Sema/transparent-union-pointer.c
index ea761f17e7d6..a58bd42f821f 100644
--- a/test/Sema/transparent-union-pointer.c
+++ b/test/Sema/transparent-union-pointer.c
@@ -1,14 +1,14 @@
// RUN: clang-cc %s -fsyntax-only -verify
typedef union {
- union wait *__uptr;
- int *__iptr;
+ union wait *__uptr;
+ int *__iptr;
} __WAIT_STATUS __attribute__ ((__transparent_union__));
extern int wait (__WAIT_STATUS __stat_loc);
void fastcgi_cleanup() {
- int status = 0;
- wait(&status);
+ int status = 0;
+ wait(&status);
}
diff --git a/test/Sema/type-spec-struct-union.c b/test/Sema/type-spec-struct-union.c
index 2b68b7877318..003efb14620b 100644
--- a/test/Sema/type-spec-struct-union.c
+++ b/test/Sema/type-spec-struct-union.c
@@ -57,7 +57,7 @@ struct bar_baz {
} mode;
int nowrap;
};
-int
+void
wizbiz_quxPoof(z)
z_foop z;
{
diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c
index 9c231e960a2a..acf488706f7e 100644
--- a/test/Sema/unused-expr.c
+++ b/test/Sema/unused-expr.c
@@ -25,7 +25,7 @@ void bar(volatile int *VP, int *P, int A,
__real__ VC;
// We know this can't change errno because of -fno-math-errno.
- sqrt(A); // expected-warning {{expression result unused}}
+ sqrt(A); // expected-warning {{ignoring return value of function declared with const attribute}}
}
extern void t1();
@@ -43,4 +43,56 @@ void nowarn(unsigned char* a, unsigned char* b)
{
unsigned char c = 1;
*a |= c, *b += c;
+
+
+ // PR4633
+ int y, x;
+ ((void)0), y = x;
+}
+
+void t4(int a) {
+ int b = 0;
+
+ if (a)
+ b == 1; // expected-warning{{expression result unused}}
+ else
+ b == 2; // expected-warning{{expression result unused}}
+
+ while (1)
+ b == 3; // expected-warning{{expression result unused}}
+
+ do
+ b == 4; // expected-warning{{expression result unused}}
+ while (1);
+
+ for (;;)
+ b == 5; // expected-warning{{expression result unused}}
+
+ for (b == 1;;) {} // expected-warning{{expression result unused}}
+ for (;b == 1;) {}
+ for (;;b == 1) {} // expected-warning{{expression result unused}}
}
+
+// rdar://7186119
+int t5f(void) __attribute__((warn_unused_result));
+void t5() {
+ t5f(); // expected-warning {{ignoring return value of function declared with warn_unused_result}}
+}
+
+
+int fn1() __attribute__ ((warn_unused_result));
+int fn2() __attribute__ ((pure));
+int fn3() __attribute__ ((const));
+// rdar://6587766
+int t6() {
+ if (fn1() < 0 || fn2(2,1) < 0 || fn3(2) < 0) // no warnings
+ return -1;
+
+ fn1(); // expected-warning {{ignoring return value of function declared with warn_unused_result attribute}}
+ fn2(92, 21); // expected-warning {{ignoring return value of function declared with pure attribute}}
+ fn3(42); // expected-warning {{ignoring return value of function declared with const attribute}}
+ return 0;
+}
+
+int t7 __attribute__ ((warn_unused_result)); // expected-warning {{warning: 'warn_unused_result' attribute only applies to function types}}
+
diff --git a/test/Sema/va_arg_x86_64.c b/test/Sema/va_arg_x86_64.c
index 680abb714b91..61ac97b7d451 100644
--- a/test/Sema/va_arg_x86_64.c
+++ b/test/Sema/va_arg_x86_64.c
@@ -8,9 +8,8 @@ char* foo(char *fmt, __builtin_va_list ap)
// PR2692
typedef __builtin_va_list va_list;
-static char *f (char * (*g) (char **, int), char **p, ...) {
- char *s;
- va_list v;
- s = g (p, __builtin_va_arg(v, int));
+static void f (char * (*g) (char **, int), char **p, ...) {
+ char *s;
+ va_list v;
+ s = g (p, __builtin_va_arg(v, int));
}
-
diff --git a/test/Sema/vector-cast.c b/test/Sema/vector-cast.c
index 9460cac6d187..8c607aad073e 100644
--- a/test/Sema/vector-cast.c
+++ b/test/Sema/vector-cast.c
@@ -20,7 +20,7 @@ void f()
type 't1' and scalar type 'char *'}}
v1 = (t1)(long long)10;
v1 = (t1)(short)10; // -expected-error {{invalid conversion between vector \
-type 't1' and integer type 'int' of different size}}
+type 't1' and integer type 'short' of different size}}
long long r1 = (long long)v1;
short r2 = (short)v1; // -expected-error {{invalid conversion between vector \
diff --git a/test/Sema/warn-char-subscripts.c b/test/Sema/warn-char-subscripts.c
new file mode 100644
index 000000000000..c6fd78cc1f74
--- /dev/null
+++ b/test/Sema/warn-char-subscripts.c
@@ -0,0 +1,64 @@
+// RUN: clang-cc -Wchar-subscripts -fsyntax-only -verify %s
+
+void t1() {
+ int array[1] = { 0 };
+ char subscript = 0;
+ int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t2() {
+ int array[1] = { 0 };
+ char subscript = 0;
+ int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t3() {
+ int *array = 0;
+ char subscript = 0;
+ int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t4() {
+ int *array = 0;
+ char subscript = 0;
+ int val = subscript[array]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+char returnsChar();
+void t5() {
+ int *array = 0;
+ int val = array[returnsChar()]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+void t6() {
+ int array[1] = { 0 };
+ signed char subscript = 0;
+ int val = array[subscript]; // no warning for explicit signed char
+}
+
+void t7() {
+ int array[1] = { 0 };
+ unsigned char subscript = 0;
+ int val = array[subscript]; // no warning for unsigned char
+}
+
+typedef char CharTy;
+void t8() {
+ int array[1] = { 0 };
+ CharTy subscript = 0;
+ int val = array[subscript]; // expected-warning{{array subscript is of type 'char'}}
+}
+
+typedef signed char SignedCharTy;
+void t9() {
+ int array[1] = { 0 };
+ SignedCharTy subscript = 0;
+ int val = array[subscript]; // no warning for explicit signed char
+}
+
+typedef unsigned char UnsignedCharTy;
+void t10() {
+ int array[1] = { 0 };
+ UnsignedCharTy subscript = 0;
+ int val = array[subscript]; // no warning for unsigned char
+}
diff --git a/test/Sema/warn-unused-variables.c b/test/Sema/warn-unused-variables.c
new file mode 100644
index 000000000000..fd225436be82
--- /dev/null
+++ b/test/Sema/warn-unused-variables.c
@@ -0,0 +1,19 @@
+// RUN: clang-cc -fsyntax-only -Wunused-variable -verify %s
+
+struct s0 {
+ unsigned int i;
+};
+
+int proto(int a, int b);
+
+void f0(void) {
+ int a __attribute__((unused)),
+ b; // expected-warning{{unused}}
+ return;
+}
+
+void f1(void) {
+ int i;
+ (void)sizeof(i);
+ return;
+}
diff --git a/test/Sema/x86-intrinsics-headers.c b/test/Sema/x86-intrinsics-headers.c
new file mode 100644
index 000000000000..dd7dd5caf017
--- /dev/null
+++ b/test/Sema/x86-intrinsics-headers.c
@@ -0,0 +1,24 @@
+// RUN: clang -fsyntax-only %s &&
+// RUN: clang -fsyntax-only -fno-lax-vector-conversions %s &&
+// RUN: clang -fsyntax-only -x c++ %s
+
+#if defined(i386) || defined(__x86_64__)
+
+# if defined(__MMX__)
+#include <emmintrin.h>
+#include <mm_malloc.h>
+# endif
+
+# if defined(__SSE__)
+#include <xmmintrin.h>
+# endif
+
+# if defined(__SSE3__)
+#include <pmmintrin.h>
+# endif
+
+# if defined(__SSSE3__)
+#include <tmmintrin.h>
+# endif
+
+#endif