aboutsummaryrefslogtreecommitdiff
path: root/test/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/MicrosoftExtensions.c2
-rw-r--r--test/Sema/aarch64-special-register.c28
-rw-r--r--test/Sema/address-packed-member-memops.c26
-rw-r--r--test/Sema/address-packed.c331
-rw-r--r--test/Sema/alloc-size.c25
-rw-r--r--test/Sema/arm-interrupt-attr.c3
-rw-r--r--test/Sema/arm-special-register.c24
-rw-r--r--test/Sema/asm.c10
-rw-r--r--test/Sema/atomic-ops.c19
-rw-r--r--test/Sema/attr-availability.c2
-rw-r--r--test/Sema/attr-naked.c18
-rw-r--r--test/Sema/attr-section.c4
-rw-r--r--test/Sema/attr-selectany.c8
-rw-r--r--test/Sema/attr-swiftcall.c5
-rw-r--r--test/Sema/attr-unavailable-message.c2
-rw-r--r--test/Sema/builtin-alloca-with-align.c33
-rw-r--r--test/Sema/builtin-unary-fp.c1
-rw-r--r--test/Sema/builtins-x86.c8
-rw-r--r--test/Sema/builtins-x86_64.c60
-rw-r--r--test/Sema/builtins.cl5
-rw-r--r--test/Sema/compound-literal.c8
-rw-r--r--test/Sema/constant-conversion.c32
-rw-r--r--test/Sema/decl-in-prototype.c59
-rw-r--r--test/Sema/dllimport.c4
-rw-r--r--test/Sema/ext_vector_components.c27
-rw-r--r--test/Sema/format-strings-enum.c16
-rw-r--r--test/Sema/format-strings.c48
-rw-r--r--test/Sema/generic-selection.c10
-rw-r--r--test/Sema/implicit-intel-builtin-decl.c40
-rw-r--r--test/Sema/implicit-ms-builtin-decl.c44
-rw-r--r--test/Sema/incompatible-function-pointer-types.c14
-rw-r--r--test/Sema/initialize-noreturn.c13
-rw-r--r--test/Sema/no-warn-unused-const-variables.c4
-rw-r--r--test/Sema/nullability.c119
-rw-r--r--test/Sema/overloadable.c33
-rw-r--r--test/Sema/pass-object-size.c2
-rw-r--r--test/Sema/pr30372.c12
-rw-r--r--test/Sema/shift.c11
-rw-r--r--test/Sema/transparent-union.c9
-rw-r--r--test/Sema/varargs.c20
-rw-r--r--test/Sema/vecshift.c99
-rw-r--r--test/Sema/vector-cast.c9
-rw-r--r--test/Sema/vfprintf-invalid-redecl.c2
-rw-r--r--test/Sema/vfprintf-valid-redecl.c8
-rw-r--r--test/Sema/warn-cast-align.c20
-rw-r--r--test/Sema/warn-documentation-unknown-command.cpp4
-rw-r--r--test/Sema/warn-documentation.cpp95
-rw-r--r--test/Sema/warn-main-returns-bool-literal.cpp20
-rw-r--r--test/Sema/warn-strict-prototypes.c62
-rw-r--r--test/Sema/warn-strict-prototypes.m20
50 files changed, 1424 insertions, 54 deletions
diff --git a/test/Sema/MicrosoftExtensions.c b/test/Sema/MicrosoftExtensions.c
index 62e5285970a7..79dba88a9903 100644
--- a/test/Sema/MicrosoftExtensions.c
+++ b/test/Sema/MicrosoftExtensions.c
@@ -28,6 +28,8 @@ struct D {
struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) IUnknown {}; /* expected-error {{'uuid' attribute is not supported in C}} */
+[uuid("00000000-0000-0000-C000-000000000046")] struct IUnknown2 {}; /* expected-error {{'uuid' attribute is not supported in C}} */
+
typedef struct notnested {
long bad1;
long bad2;
diff --git a/test/Sema/aarch64-special-register.c b/test/Sema/aarch64-special-register.c
index a4fb92b5235b..1e658fd90769 100644
--- a/test/Sema/aarch64-special-register.c
+++ b/test/Sema/aarch64-special-register.c
@@ -41,7 +41,7 @@ void wsr64_2(unsigned long v) {
}
unsigned rsr_2() {
- return __builtin_arm_rsr("0:1:2:3:4");
+ return __builtin_arm_rsr("0:1:15:15:4");
}
void *rsrp_2() {
@@ -49,7 +49,7 @@ void *rsrp_2() {
}
unsigned long rsr64_2() {
- return __builtin_arm_rsr64("0:1:2:3:4");
+ return __builtin_arm_rsr64("0:1:15:15:4");
}
void wsr_3(unsigned v) {
@@ -68,6 +68,18 @@ unsigned rsr_3() {
return __builtin_arm_rsr("0:1:2"); //expected-error {{invalid special register for builtin}}
}
+unsigned rsr_4() {
+ return __builtin_arm_rsr("0:1:2:3:8"); //expected-error {{invalid special register for builtin}}
+}
+
+unsigned rsr_5() {
+ return __builtin_arm_rsr("0:8:1:2:3"); //expected-error {{invalid special register for builtin}}
+}
+
+unsigned rsr_6() {
+ return __builtin_arm_rsr("0:1:16:16:2"); //expected-error {{invalid special register for builtin}}
+}
+
void *rsrp_3() {
return __builtin_arm_rsrp("0:1:2"); //expected-error {{invalid special register for builtin}}
}
@@ -75,3 +87,15 @@ void *rsrp_3() {
unsigned long rsr64_3() {
return __builtin_arm_rsr64("0:1:2"); //expected-error {{invalid special register for builtin}}
}
+
+unsigned long rsr64_4() {
+ return __builtin_arm_rsr64("0:1:2:3:8"); //expected-error {{invalid special register for builtin}}
+}
+
+unsigned long rsr64_5() {
+ return __builtin_arm_rsr64("0:8:2:3:4"); //expected-error {{invalid special register for builtin}}
+}
+
+unsigned long rsr64_6() {
+ return __builtin_arm_rsr64("0:1:16:16:2"); //expected-error {{invalid special register for builtin}}
+}
diff --git a/test/Sema/address-packed-member-memops.c b/test/Sema/address-packed-member-memops.c
new file mode 100644
index 000000000000..220132f33298
--- /dev/null
+++ b/test/Sema/address-packed-member-memops.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+struct B {
+ int x, y, z, w;
+} b;
+
+struct __attribute__((packed)) A {
+ struct B b;
+} a;
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *memcpy(void *dest, const void *src, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+void *memmove(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+
+int x;
+
+void foo(void) {
+ memcpy(&a.b, &b, sizeof(b));
+ memmove(&a.b, &b, sizeof(b));
+ memset(&a.b, 0, sizeof(b));
+ x = memcmp(&a.b, &b, sizeof(b));
+}
diff --git a/test/Sema/address-packed.c b/test/Sema/address-packed.c
new file mode 100644
index 000000000000..2799e19c48f1
--- /dev/null
+++ b/test/Sema/address-packed.c
@@ -0,0 +1,331 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#include <stdint.h>
+
+extern void f1(int *);
+extern void f2(char *);
+
+struct Ok {
+ char c;
+ int x;
+};
+
+struct __attribute__((packed)) Arguable {
+ char c0;
+ int x;
+ char c1;
+};
+
+union __attribute__((packed)) UnionArguable {
+ char c;
+ int x;
+};
+
+typedef struct Arguable ArguableT;
+
+struct Arguable *get_arguable();
+
+void to_void(void *);
+void to_intptr(intptr_t);
+
+void g0(void) {
+ {
+ struct Ok ok;
+ f1(&ok.x); // no-warning
+ f2(&ok.c); // no-warning
+ }
+ {
+ struct Arguable arguable;
+ f2(&arguable.c0); // no-warning
+ f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
+ f2(&arguable.c1); // no-warning
+
+ f1((int *)(void *)&arguable.x); // no-warning
+ to_void(&arguable.x); // no-warning
+ void *p = &arguable.x; // no-warning
+ to_void(p);
+ to_intptr((intptr_t)p); // no-warning
+ }
+ {
+ union UnionArguable arguable;
+ f2(&arguable.c); // no-warning
+ f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'UnionArguable'}}
+
+ f1((int *)(void *)&arguable.x); // no-warning
+ to_void(&arguable.x); // no-warning
+ to_intptr((intptr_t)&arguable.x); // no-warning
+ }
+ {
+ ArguableT arguable;
+ f2(&arguable.c0); // no-warning
+ f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
+ f2(&arguable.c1); // no-warning
+
+ f1((int *)(void *)&arguable.x); // no-warning
+ to_void(&arguable.x); // no-warning
+ to_intptr((intptr_t)&arguable.x); // no-warning
+ }
+ {
+ struct Arguable *arguable = get_arguable();
+ f2(&arguable->c0); // no-warning
+ f1(&arguable->x); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
+ f2(&arguable->c1); // no-warning
+
+ f1((int *)(void *)&arguable->x); // no-warning
+ to_void(&arguable->c1); // no-warning
+ to_intptr((intptr_t)&arguable->c1); // no-warning
+ }
+ {
+ ArguableT *arguable = get_arguable();
+ f2(&(arguable->c0)); // no-warning
+ f1(&(arguable->x)); // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
+ f2(&(arguable->c1)); // no-warning
+
+ f1((int *)(void *)&(arguable->x)); // no-warning
+ to_void(&(arguable->c1)); // no-warning
+ to_intptr((intptr_t)&(arguable->c1)); // no-warning
+ }
+}
+
+struct S1 {
+ char c;
+ int i __attribute__((packed));
+};
+
+int *g1(struct S1 *s1) {
+ return &s1->i; // expected-warning {{packed member 'i' of class or structure 'S1'}}
+}
+
+struct S2_i {
+ int i;
+};
+struct __attribute__((packed)) S2 {
+ char c;
+ struct S2_i inner;
+};
+
+int *g2(struct S2 *s2) {
+ return &s2->inner.i; // expected-warning {{packed member 'inner' of class or structure 'S2'}}
+}
+
+struct S2_a {
+ char c;
+ struct S2_i inner __attribute__((packed));
+};
+
+int *g2_a(struct S2_a *s2_a) {
+ return &s2_a->inner.i; // expected-warning {{packed member 'inner' of class or structure 'S2_a'}}
+}
+
+struct __attribute__((packed)) S3 {
+ char c;
+ struct {
+ int i;
+ } inner;
+};
+
+int *g3(struct S3 *s3) {
+ return &s3->inner.i; // expected-warning {{packed member 'inner' of class or structure 'S3'}}
+}
+
+struct S4 {
+ char c;
+ struct __attribute__((packed)) {
+ int i;
+ } inner;
+};
+
+int *g4(struct S4 *s4) {
+ return &s4->inner.i; // expected-warning {{packed member 'i' of class or structure 'S4::(anonymous)'}}
+}
+
+struct S5 {
+ char c;
+ struct {
+ char c1;
+ int i __attribute__((packed));
+ } inner;
+};
+
+int *g5(struct S5 *s5) {
+ return &s5->inner.i; // expected-warning {{packed member 'i' of class or structure 'S5::(anonymous)'}}
+}
+
+struct __attribute__((packed, aligned(2))) AlignedTo2 {
+ int x;
+};
+
+char *g6(struct AlignedTo2 *s) {
+ return (char *)&s->x; // no-warning
+}
+
+struct __attribute__((packed, aligned(2))) AlignedTo2Bis {
+ int x;
+};
+
+struct AlignedTo2Bis* g7(struct AlignedTo2 *s)
+{
+ return (struct AlignedTo2Bis*)&s->x; // no-warning
+}
+
+typedef struct {
+ char c;
+ int x;
+} __attribute__((packed)) TypedefStructArguable;
+
+typedef union {
+ char c;
+ int x;
+} __attribute((packed)) TypedefUnionArguable;
+
+typedef TypedefStructArguable TypedefStructArguableTheSecond;
+
+int *typedef1(TypedefStructArguable *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'TypedefStructArguable'}}
+}
+
+int *typedef2(TypedefStructArguableTheSecond *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'TypedefStructArguable'}}
+}
+
+int *typedef3(TypedefUnionArguable *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'TypedefUnionArguable'}}
+}
+
+struct S6 {
+ union {
+ char c;
+ int x;
+ } __attribute__((packed));
+};
+
+int *anonymousInnerUnion(struct S6 *s) {
+ return &s->x; // expected-warning {{packed member 'x' of class or structure 'S6::(anonymous)'}}
+}
+
+struct S6a {
+ int a;
+ int _;
+ int c;
+ char __;
+ int d;
+} __attribute__((packed, aligned(16))) s6;
+
+void g8()
+{
+ f1(&s6.a); // no-warning
+ f1(&s6.c); // no-warning
+ f1(&s6.d); // expected-warning {{packed member 'd' of class or structure 'S6a'}}
+}
+
+struct __attribute__((packed, aligned(1))) MisalignedContainee { double d; };
+struct __attribute__((aligned(8))) AlignedContainer { struct MisalignedContainee b; };
+
+struct AlignedContainer *p;
+double* g9() {
+ return &p->b.d; // no-warning
+}
+
+union OneUnion
+{
+ uint32_t a;
+ uint32_t b:1;
+};
+
+struct __attribute__((packed)) S7 {
+ uint8_t length;
+ uint8_t stuff;
+ uint8_t padding[2];
+ union OneUnion one_union;
+};
+
+union AnotherUnion {
+ long data;
+ struct S7 s;
+} *au;
+
+union OneUnion* get_OneUnion(void)
+{
+ return &au->s.one_union; // no-warning
+}
+
+struct __attribute__((packed)) S8 {
+ uint8_t data1;
+ uint8_t data2;
+ uint16_t wider_data;
+};
+
+#define LE_READ_2(p) \
+ ((uint16_t) \
+ ((((const uint8_t *)(p))[0] ) | \
+ (((const uint8_t *)(p))[1] << 8)))
+
+uint32_t get_wider_data(struct S8 *s)
+{
+ return LE_READ_2(&s->wider_data); // no-warning
+}
+
+struct S9 {
+ uint32_t x;
+ uint8_t y[2];
+ uint16_t z;
+} __attribute__((__packed__));
+
+typedef struct S9 __attribute__((__aligned__(16))) aligned_S9;
+
+void g10() {
+ struct S9 x;
+ struct S9 __attribute__((__aligned__(8))) y;
+ aligned_S9 z;
+
+ uint32_t *p32;
+ p32 = &x.x; // expected-warning {{packed member 'x' of class or structure 'S9'}}
+ p32 = &y.x; // no-warning
+ p32 = &z.x; // no-warning
+}
+
+typedef struct {
+ uint32_t msgh_bits;
+ uint32_t msgh_size;
+ int32_t msgh_voucher_port;
+ int32_t msgh_id;
+} S10Header;
+
+typedef struct {
+ uint32_t t;
+ uint64_t m;
+ uint32_t p;
+ union {
+ struct {
+ uint32_t a;
+ double z;
+ } __attribute__((aligned(8), packed)) a;
+ struct {
+ uint32_t b;
+ double z;
+ uint32_t a;
+ } __attribute__((aligned(8), packed)) b;
+ };
+} __attribute__((aligned(8), packed)) S10Data;
+
+typedef struct {
+ S10Header hdr;
+ uint32_t size;
+ uint8_t count;
+ S10Data data[] __attribute__((aligned(8)));
+} __attribute__((aligned(8), packed)) S10;
+
+void g11(S10Header *hdr);
+void g12(S10 *s) {
+ g11(&s->hdr); // no-warning
+}
+
+struct S11 {
+ uint32_t x;
+} __attribute__((__packed__));
+
+void g13(void) {
+ struct S11 __attribute__((__aligned__(4))) a[4];
+ uint32_t *p32;
+ p32 = &a[0].x; // no-warning
+}
diff --git a/test/Sema/alloc-size.c b/test/Sema/alloc-size.c
new file mode 100644
index 000000000000..7004a5a7d7f6
--- /dev/null
+++ b/test/Sema/alloc-size.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -verify
+
+void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' attribute takes at least 1 argument}}
+void *fail2(int a) __attribute__((alloc_size())); //expected-error{{'alloc_size' attribute takes at least 1 argument}}
+
+void *fail3(int a) __attribute__((alloc_size(0))); //expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
+void *fail4(int a) __attribute__((alloc_size(2))); //expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
+
+void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); //expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
+void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); //expected-error{{'alloc_size' attribute parameter 3 is out of bounds}}
+
+void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); //expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
+void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); //expected-error{{'alloc_size' attribute parameter 3 is out of bounds}}
+
+int fail9(int a) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to return values that are pointers}}
+
+int fail10 __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to functions}}
+
+void *fail11(void *a) __attribute__((alloc_size(1))); //expected-error{{'alloc_size' attribute argument may only refer to a function parameter of integer type}}
+
+void *fail12(int a) __attribute__((alloc_size("abc"))); //expected-error{{'alloc_size' attribute requires parameter 1 to be an integer constant}}
+void *fail12(int a) __attribute__((alloc_size(1, "abc"))); //expected-error{{'alloc_size' attribute requires parameter 2 to be an integer constant}}
+void *fail13(int a) __attribute__((alloc_size(1U<<31))); //expected-error{{integer constant expression evaluates to value 2147483648 that cannot be represented in a 32-bit signed integer type}}
+
+int (*PR31453)(int) __attribute__((alloc_size(1))); //expected-warning{{'alloc_size' attribute only applies to functions}}
diff --git a/test/Sema/arm-interrupt-attr.c b/test/Sema/arm-interrupt-attr.c
index e8f21ada7fc1..b9684f0b46c1 100644
--- a/test/Sema/arm-interrupt-attr.c
+++ b/test/Sema/arm-interrupt-attr.c
@@ -1,4 +1,7 @@
// RUN: %clang_cc1 %s -triple arm-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumb-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple armeb-none-eabi -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -verify -fsyntax-only
__attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' attribute requires a string}}
__attribute__((interrupt("irq"))) void foo1() {} // expected-warning {{'interrupt' attribute argument not supported: irq}}
diff --git a/test/Sema/arm-special-register.c b/test/Sema/arm-special-register.c
index 3ded628c137d..a9be80fba2ec 100644
--- a/test/Sema/arm-special-register.c
+++ b/test/Sema/arm-special-register.c
@@ -41,7 +41,7 @@ void wsr64_2(unsigned long v) {
}
unsigned rsr_2() {
- return __builtin_arm_rsr("cp0:1:c2:c3:4");
+ return __builtin_arm_rsr("cp0:1:c15:c15:4");
}
void *rsrp_2() {
@@ -73,13 +73,25 @@ void *rsrp_3() {
}
unsigned long rsr64_3() {
- return __builtin_arm_rsr64("cp0:1:c2");
+ return __builtin_arm_rsr64("cp0:1:c15");
}
unsigned rsr_4() {
return __builtin_arm_rsr("0:1:2:3:4"); //expected-error {{invalid special register for builtin}}
}
+unsigned rsr_5() {
+ return __builtin_arm_rsr("cp0:1:c2:c3:8"); //expected-error {{invalid special register for builtin}}
+}
+
+unsigned rsr_6() {
+ return __builtin_arm_rsr("cp0:8:c1:c2:3"); //expected-error {{invalid special register for builtin}}
+}
+
+unsigned rsr_7() {
+ return __builtin_arm_rsr("cp0:1:c16:c16:2"); //expected-error {{invalid special register for builtin}}
+}
+
void *rsrp_4() {
return __builtin_arm_rsrp("0:1:2:3:4"); //expected-error {{invalid special register for builtin}}
}
@@ -87,3 +99,11 @@ void *rsrp_4() {
unsigned long rsr64_4() {
return __builtin_arm_rsr64("0:1:2"); //expected-error {{invalid special register for builtin}}
}
+
+unsigned long rsr64_5() {
+ return __builtin_arm_rsr64("cp0:8:c1"); //expected-error {{invalid special register for builtin}}
+}
+
+unsigned long rsr64_6() {
+ return __builtin_arm_rsr64("cp0:1:c16"); //expected-error {{invalid special register for builtin}}
+}
diff --git a/test/Sema/asm.c b/test/Sema/asm.c
index 69c33f7ccf24..e49a1663a896 100644
--- a/test/Sema/asm.c
+++ b/test/Sema/asm.c
@@ -28,6 +28,16 @@ void clobbers() {
asm ("nop" : : : "204"); // expected-error {{unknown register name '204' in asm}}
asm ("nop" : : : "-1"); // expected-error {{unknown register name '-1' in asm}}
asm ("nop" : : : "+1"); // expected-error {{unknown register name '+1' in asm}}
+ register void *clobber_conflict asm ("%rcx");
+ register void *no_clobber_conflict asm ("%rax");
+ int a,b,c;
+ asm ("nop" : "=r" (no_clobber_conflict) : "r" (clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+ asm ("nop" : "=r" (clobber_conflict) : "r" (no_clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+ asm ("nop" : "=r" (clobber_conflict) : "r" (clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+ asm ("nop" : "=c" (a) : "r" (no_clobber_conflict) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+ asm ("nop" : "=r" (no_clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+ asm ("nop" : "=r" (clobber_conflict) : "c" (c) : "%rcx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
+ asm ("nop" : "=a" (a) : "b" (b) : "%rcx", "%rbx"); // expected-error {{asm-specifier for input or output variable conflicts with asm clobber list}}
}
// rdar://6094010
diff --git a/test/Sema/atomic-ops.c b/test/Sema/atomic-ops.c
index 05836214247c..8ebf3eaed4af 100644
--- a/test/Sema/atomic-ops.c
+++ b/test/Sema/atomic-ops.c
@@ -174,14 +174,14 @@ void f(_Atomic(int) *i, const _Atomic(int) *ci,
__atomic_fetch_or(D, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer}}
__atomic_fetch_and(s1, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer}}
- _Bool cmpexch_1 = __c11_atomic_compare_exchange_strong(i, 0, 1, memory_order_seq_cst, memory_order_seq_cst);
- _Bool cmpexch_2 = __c11_atomic_compare_exchange_strong(p, 0, (int*)1, memory_order_seq_cst, memory_order_seq_cst);
- _Bool cmpexch_3 = __c11_atomic_compare_exchange_strong(d, (int*)0, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{incompatible pointer types}}
+ _Bool cmpexch_1 = __c11_atomic_compare_exchange_strong(i, I, 1, memory_order_seq_cst, memory_order_seq_cst);
+ _Bool cmpexch_2 = __c11_atomic_compare_exchange_strong(p, P, (int*)1, memory_order_seq_cst, memory_order_seq_cst);
+ _Bool cmpexch_3 = __c11_atomic_compare_exchange_strong(d, I, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{incompatible pointer types}}
(void)__c11_atomic_compare_exchange_strong(i, CI, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{passing 'const int *' to parameter of type 'int *' discards qualifiers}}
- _Bool cmpexchw_1 = __c11_atomic_compare_exchange_weak(i, 0, 1, memory_order_seq_cst, memory_order_seq_cst);
- _Bool cmpexchw_2 = __c11_atomic_compare_exchange_weak(p, 0, (int*)1, memory_order_seq_cst, memory_order_seq_cst);
- _Bool cmpexchw_3 = __c11_atomic_compare_exchange_weak(d, (int*)0, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{incompatible pointer types}}
+ _Bool cmpexchw_1 = __c11_atomic_compare_exchange_weak(i, I, 1, memory_order_seq_cst, memory_order_seq_cst);
+ _Bool cmpexchw_2 = __c11_atomic_compare_exchange_weak(p, P, (int*)1, memory_order_seq_cst, memory_order_seq_cst);
+ _Bool cmpexchw_3 = __c11_atomic_compare_exchange_weak(d, I, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{incompatible pointer types}}
(void)__c11_atomic_compare_exchange_weak(i, CI, 1, memory_order_seq_cst, memory_order_seq_cst); // expected-warning {{passing 'const int *' to parameter of type 'int *' discards qualifiers}}
_Bool cmpexch_4 = __atomic_compare_exchange_n(I, I, 5, 1, memory_order_seq_cst, memory_order_seq_cst);
@@ -503,4 +503,9 @@ void memory_checks(_Atomic(int) *Ap, int *p, int val) {
(void)__atomic_compare_exchange_n(p, p, val, 0, memory_order_seq_cst, memory_order_relaxed);
}
-
+void nullPointerWarning(_Atomic(int) *Ap, int *p, int val) {
+ // The 'expected' pointer shouldn't be NULL.
+ (void)__c11_atomic_compare_exchange_strong(Ap, NULL, val, memory_order_relaxed, memory_order_relaxed); // expected-warning {{null passed to a callee that requires a non-null argument}}
+ (void)atomic_compare_exchange_weak(Ap, ((void*)0), val); // expected-warning {{null passed to a callee that requires a non-null argument}}
+ (void)__atomic_compare_exchange_n(p, NULL, val, 0, memory_order_relaxed, memory_order_relaxed); // expected-warning {{null passed to a callee that requires a non-null argument}}
+}
diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c
index 8fe6be3804ed..a4b40ff9e0c3 100644
--- a/test/Sema/attr-availability.c
+++ b/test/Sema/attr-availability.c
@@ -30,7 +30,7 @@ void test_10095131() {
ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in macOS 9.0 - use ATSFontGetFullPostScriptName}}
#if defined(WARN_PARTIAL)
- // expected-warning@+2 {{is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'PartiallyAvailable' to silence this warning}}
+ // expected-warning@+2 {{is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'PartiallyAvailable' in an @available check to silence this warning}}
#endif
PartiallyAvailable();
}
diff --git a/test/Sema/attr-naked.c b/test/Sema/attr-naked.c
index 6b1344a9860b..c9a3f1dbfcc1 100644
--- a/test/Sema/attr-naked.c
+++ b/test/Sema/attr-naked.c
@@ -48,3 +48,21 @@ __attribute__((naked)) void t9(int z) { // expected-note{{attribute is here}}
"r"(z) // expected-error{{parameter references not allowed in naked functions}}
);
}
+
+__attribute__((naked)) void t10() { // expected-note{{attribute is here}}
+ int a; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) void t11() { // expected-note{{attribute is here}}
+ register int a asm("eax") = x; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) void t12() { // expected-note{{attribute is here}}
+ register int a asm("eax"), b asm("ebx") = x; // expected-error{{non-ASM statement in naked function is not supported}}
+}
+
+__attribute__((naked)) void t13() {
+ register int a asm("eax");
+ register int b asm("ebx"), c asm("ecx");
+}
+
diff --git a/test/Sema/attr-section.c b/test/Sema/attr-section.c
index 812de067180c..c64b10d80ff6 100644
--- a/test/Sema/attr-section.c
+++ b/test/Sema/attr-section.c
@@ -10,7 +10,7 @@ int y __attribute__((section(
// PR6007
void test() {
- __attribute__((section("NEAR,x"))) int n1; // expected-error {{'section' attribute only applies to functions and global variables}}
+ __attribute__((section("NEAR,x"))) int n1; // expected-error {{'section' attribute only applies to functions, methods, properties, and global variables}}
__attribute__((section("NEAR,x"))) static int n2; // ok.
}
@@ -18,4 +18,4 @@ void test() {
void __attribute__((section("foo,zed"))) test2(void); // expected-note {{previous attribute is here}}
void __attribute__((section("bar,zed"))) test2(void) {} // expected-warning {{section does not match previous declaration}}
-enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' attribute only applies to functions and global variables}}
+enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' attribute only applies to functions, methods, properties, and global variables}}
diff --git a/test/Sema/attr-selectany.c b/test/Sema/attr-selectany.c
new file mode 100644
index 000000000000..01cca7d7cfa5
--- /dev/null
+++ b/test/Sema/attr-selectany.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-extensions -verify %s
+
+extern __declspec(selectany) const int x1 = 1; // no warning, const means we need extern in C++
+
+// Should we really warn on this?
+extern __declspec(selectany) int x2 = 1; // expected-warning {{'extern' variable has an initializer}}
+
+__declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
diff --git a/test/Sema/attr-swiftcall.c b/test/Sema/attr-swiftcall.c
index 3458167cf2e8..0323f059bab5 100644
--- a/test/Sema/attr-swiftcall.c
+++ b/test/Sema/attr-swiftcall.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows -fsyntax-only -verify %s
#define SWIFTCALL __attribute__((swiftcall))
#define INDIRECT_RESULT __attribute__((swift_indirect_result))
@@ -18,13 +19,13 @@ void indirect_result_single(INDIRECT_RESULT void *out) SWIFTCALL;
void indirect_result_multiple(INDIRECT_RESULT void *out1, INDIRECT_RESULT void *out2) SWIFTCALL;
void error_result_nonswift(ERROR_RESULT void **error); // expected-error {{'swift_error_result' parameter can only be used with swiftcall calling convention}} expected-error{{'swift_error_result' parameter must follow 'swift_context' parameter}}
-void error_result_bad_position(ERROR_RESULT void **error, int last) SWIFTCALL; // expected-error {{'swift_error_result' parameter must be last parameter of function}}
void error_result_bad_position2(int first, ERROR_RESULT void **error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must follow 'swift_context' parameter}}
void error_result_bad_type(CONTEXT void *context, ERROR_RESULT int error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must have pointer to unqualified pointer type; type here is 'int'}}
void error_result_bad_type2(CONTEXT void *context, ERROR_RESULT int *error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must have pointer to unqualified pointer type; type here is 'int *'}}
void error_result_okay(int a, int b, CONTEXT void *context, ERROR_RESULT void **error) SWIFTCALL;
+void error_result_okay2(CONTEXT void *context, ERROR_RESULT void **error, void *selfType, char **selfWitnessTable) SWIFTCALL;
void context_nonswift(CONTEXT void *context); // expected-error {{'swift_context' parameter can only be used with swiftcall calling convention}}
-void context_bad_position(CONTEXT void *context, int x) SWIFTCALL; // expected-error {{'swift_context' parameter can only be followed by 'swift_error_result' parameter}}
void context_bad_type(CONTEXT int context) SWIFTCALL; // expected-error {{'swift_context' parameter must have pointer type; type here is 'int'}}
void context_okay(CONTEXT void *context) SWIFTCALL;
+void context_okay2(CONTEXT void *context, void *selfType, char **selfWitnessTable) SWIFTCALL;
diff --git a/test/Sema/attr-unavailable-message.c b/test/Sema/attr-unavailable-message.c
index 400a2c632883..415cb2f079a2 100644
--- a/test/Sema/attr-unavailable-message.c
+++ b/test/Sema/attr-unavailable-message.c
@@ -1,6 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// rdar: //6734520
+void tooManyArgs() __attribute__((unavailable("a", "b"))); // expected-error {{'unavailable' attribute takes no more than 1 argument}}
+
int foo(int) __attribute__((__unavailable__("USE IFOO INSTEAD"))); // expected-note {{'foo' has been explicitly marked unavailable here}}
double dfoo(double) __attribute__((__unavailable__("NO LONGER"))); // expected-note 2 {{'dfoo' has been explicitly marked unavailable here}}
diff --git a/test/Sema/builtin-alloca-with-align.c b/test/Sema/builtin-alloca-with-align.c
new file mode 100644
index 000000000000..16d71da60080
--- /dev/null
+++ b/test/Sema/builtin-alloca-with-align.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void test1(int a) {
+ __builtin_alloca_with_align(a, 32);
+}
+
+void test2(int a) {
+ __builtin_alloca_with_align(a, -32); // expected-error {{requested alignment is not a power of 2}}
+}
+
+void test3(unsigned *b) {
+ __builtin_alloca_with_align(b, 32); // expected-warning {{incompatible pointer to integer conversion passing 'unsigned int *' to parameter of type}}
+}
+
+void test4(int a) {
+ __builtin_alloca_with_align(a, 32, 0); // expected-error {{too many arguments to function call, expected 2, have 3}}
+}
+
+void test5(int a) {
+ __builtin_alloca_with_align(a, 31); // expected-error {{requested alignment is not a power of 2}}
+}
+
+void test6(int a, int j) {
+ __builtin_alloca_with_align(a, j); // expected-error {{must be a constant integer}}
+}
+
+void test7(int a) {
+ __builtin_alloca_with_align(a, 2); // expected-error {{requested alignment must be 8 or greater}}
+}
+
+void test8() {
+ __builtin_alloca_with_align(sizeof(__INT64_TYPE__), __alignof__(__INT64_TYPE__)); // expected-warning {{second argument to __builtin_alloca_with_align is supposed to be in bits}}
+}
diff --git a/test/Sema/builtin-unary-fp.c b/test/Sema/builtin-unary-fp.c
index 57568db8ae3f..2b75b10fcbe5 100644
--- a/test/Sema/builtin-unary-fp.c
+++ b/test/Sema/builtin-unary-fp.c
@@ -11,6 +11,7 @@ void a() {
check(__builtin_isnan(1,2)); // expected-error{{too many arguments}}
check(__builtin_fpclassify(0, 0, 0, 0, 0, 1.0));
check(__builtin_fpclassify(0, 0, 0, 0, 0, 1)); // expected-error{{requires argument of floating point type}}
+ check(__builtin_fpclassify(0, 1, 2, 3, 4.5, 5.0)); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 4.5 to 4}}
check(__builtin_fpclassify(0, 0, 0, 0, 1)); // expected-error{{too few arguments}}
check(__builtin_fpclassify(0, 0, 0, 0, 0, 1, 0)); // expected-error{{too many arguments}}
}
diff --git a/test/Sema/builtins-x86.c b/test/Sema/builtins-x86.c
index 326d2a3a7a16..6929dcc65090 100644
--- a/test/Sema/builtins-x86.c
+++ b/test/Sema/builtins-x86.c
@@ -27,11 +27,11 @@ __m128d test__builtin_ia32_cmpsd(__m128d __a, __m128d __b) {
}
__mmask16 test__builtin_ia32_cmpps512_mask(__m512d __a, __m512d __b) {
- __builtin_ia32_cmpps512_mask(__a, __b, 32, -1, 0); // expected-error {{argument should be a value from 0 to 31}}
+ __builtin_ia32_cmpps512_mask(__a, __b, 32, -1, 4); // expected-error {{argument should be a value from 0 to 31}}
}
__mmask8 test__builtin_ia32_cmppd512_mask(__m512d __a, __m512d __b) {
- __builtin_ia32_cmppd512_mask(__a, __b, 32, -1, 0); // expected-error {{argument should be a value from 0 to 31}}
+ __builtin_ia32_cmppd512_mask(__a, __b, 32, -1, 4); // expected-error {{argument should be a value from 0 to 31}}
}
__m128i test__builtin_ia32_vpcomub(__m128i __a, __m128i __b) {
@@ -65,3 +65,7 @@ __m128i test__builtin_ia32_vpcomd(__m128i __a, __m128i __b) {
__m128i test__builtin_ia32_vpcomq(__m128i __a, __m128i __b) {
__builtin_ia32_vpcomuq(__a, __b, 8); // expected-error {{argument should be a value from 0 to 7}}
}
+
+__mmask16 test__builtin_ia32_cmpps512_mask_rounding(__m512 __a, __m512 __b, __mmask16 __u) {
+ __builtin_ia32_cmpps512_mask(__a, __b, 0, __u, 0); // expected-error {{invalid rounding argument}}
+}
diff --git a/test/Sema/builtins-x86_64.c b/test/Sema/builtins-x86_64.c
new file mode 100644
index 000000000000..46227bae2493
--- /dev/null
+++ b/test/Sema/builtins-x86_64.c
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fsyntax-only -fno-spell-checking -verify %s
+
+typedef int v4si __attribute__((vector_size(16)));
+typedef float v4f __attribute__((vector_size(16)));
+typedef double v2d __attribute__((vector_size(16)));
+typedef long long v2ll __attribute__((vector_size(16)));
+typedef long long v4ll __attribute__((vector_size(32)));
+typedef long long v8ll __attribute__((vector_size(64)));
+void call_x86_64_builtins(void) {
+ unsigned long long *ullp;
+ void *vp;
+ v4f vec4floats;
+ v2d vec2doubles;
+ v2ll vec2longlongs;
+ v4ll vec4longlongs;
+ v8ll vec8longlongs;
+ (void)__builtin_ia32_readeflags_u64(); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_writeeflags_u64(4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvtss2si64(vec4floats); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvttss2si64(vec4floats); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvtsd2si64(vec2doubles); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvttsd2si64(vec2doubles); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_crc32di(4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_rdfsbase64(); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_rdgsbase64(); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_wrfsbase64(4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_wrgsbase64(4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_fxrstor64(vp); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_fxsave64(vp); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_xsave64(vp, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_xrstor64(vp, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_xsaveopt64(vp, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_xrstors64(vp, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_xsavec64(vp, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_xsaves64(vp, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_addcarryx_u64(4, 4, 4, ullp); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_addcarry_u64(4, 4, 4, ullp); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_subborrow_u64(4, 4, 4, ullp); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_rdseed64_step(ullp); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_bextr_u64(4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_bzhi_di(4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_pdep_di(4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_pext_di(4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_bextri_u64(4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_pbroadcastq512_gpr_mask(4, vec8longlongs, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_pbroadcastq128_gpr_mask(4, vec2longlongs, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_pbroadcastq256_gpr_mask(4, vec4longlongs, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvtsd2si64(vec2doubles, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvtsd2usi64(vec2doubles, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvtss2si64(vec4floats, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvtss2usi64(vec4floats, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvttsd2si64(vec2doubles, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvttsd2usi64(vec2doubles, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvttss2si64(vec4floats, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_vcvttss2usi64(vec4floats, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvtsi2sd64(vec2doubles, 4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvtsi2ss64(vec4floats, 4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvtusi2sd64(vec2doubles, 4, 4); // expected-error{{use of unknown builtin}}
+ (void)__builtin_ia32_cvtusi2ss64(vec4floats, 4, 4); // expected-error{{use of unknown builtin}}
+}
diff --git a/test/Sema/builtins.cl b/test/Sema/builtins.cl
index 8cde8f3d10ff..7cde5e1a9e4d 100644
--- a/test/Sema/builtins.cl
+++ b/test/Sema/builtins.cl
@@ -1,8 +1,11 @@
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
-// expected-no-diagnostics
kernel void test(global float *out, global float *in, global int* in2) {
out[0] = __builtin_nanf("");
__builtin_memcpy(out, in, 32);
out[0] = __builtin_frexpf(in[0], in2);
}
+
+void pr28651() {
+ __builtin_alloca(value); // expected-error{{use of undeclared identifier}}
+}
diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c
index c5c0c17143fa..217dbeda8a7b 100644
--- a/test/Sema/compound-literal.c
+++ b/test/Sema/compound-literal.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -pedantic %s
// REQUIRES: LP64
struct foo { int a, b; };
@@ -36,3 +36,9 @@ void IncompleteFunc(unsigned x) {
// PR6080
int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1];
+
+// rdar://28949016 - Constant restriction should not apply to compound literals in blocks
+int (^block)(int) = ^(int i) {
+ int *array = (int[]) {i, i + 2, i + 4};
+ return array[i];
+};
diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c
index 203e7373897c..bf8221089d8c 100644
--- a/test/Sema/constant-conversion.c
+++ b/test/Sema/constant-conversion.c
@@ -11,7 +11,7 @@ void test_6792488(void) {
void test_7809123(void) {
struct { int i5 : 5; } a;
- a.i5 = 36; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 36 to 4}}
+ a.i5 = 36; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 36 to 4}}
}
void test() {
@@ -31,11 +31,11 @@ void test3() {
int bar : 2;
};
- struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}}
- struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}}
- struct A c[] = {{10, 0}}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
- struct A d = (struct A) { 10, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
- struct A e = { .foo = 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
+ struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to -2}}
+ struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to -2}}
+ struct A c[] = {{10, 0}}; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to 2}}
+ struct A d = (struct A) { 10, 0 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to 2}}
+ struct A e = { .foo = 10 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to 2}}
}
void test4() {
@@ -43,7 +43,7 @@ void test4() {
char c : 2;
} a;
- a.c = 0x101; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 257 to 1}}
+ a.c = 0x101; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 257 to 1}}
}
void test5() {
@@ -52,7 +52,7 @@ void test5() {
} a;
// Don't warn about this implicit conversion to bool, or at least
- // don't warn about it just because it's a bitfield.
+ // don't warn about it just because it's a bit-field.
a.b = 100;
}
@@ -69,8 +69,9 @@ void test7() {
unsigned int reserved:28;
} f;
- f.twoBits1 = ~1; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -2 to 2}}
- f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -3 to 1}}
+ f.twoBits1 = ~0; // no-warning
+ f.twoBits1 = ~1; // no-warning
+ f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bit-field changes value from -3 to 1}}
f.twoBits1 &= ~1; // no-warning
f.twoBits2 &= ~2; // no-warning
}
@@ -78,7 +79,7 @@ void test7() {
void test8() {
enum E { A, B, C };
struct { enum E x : 1; } f;
- f.x = C; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 2 to 0}}
+ f.x = C; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 2 to 0}}
}
void test9() {
@@ -114,6 +115,8 @@ void test9() {
char array_init[] = { 255, 127, 128, 129, 0 };
}
+#define A 1
+
void test10() {
struct S {
unsigned a : 4;
@@ -121,7 +124,10 @@ void test10() {
s.a = -1;
s.a = 15;
s.a = -8;
+ s.a = ~0;
+ s.a = ~0U;
+ s.a = ~(1<<A);
- s.a = -9; // expected-warning{{implicit truncation from 'int' to bitfield changes value from -9 to 7}}
- s.a = 16; // expected-warning{{implicit truncation from 'int' to bitfield changes value from 16 to 0}}
+ s.a = -9; // expected-warning{{implicit truncation from 'int' to bit-field changes value from -9 to 7}}
+ s.a = 16; // expected-warning{{implicit truncation from 'int' to bit-field changes value from 16 to 0}}
}
diff --git a/test/Sema/decl-in-prototype.c b/test/Sema/decl-in-prototype.c
index 3b8a3b860371..64caea6a38a8 100644
--- a/test/Sema/decl-in-prototype.c
+++ b/test/Sema/decl-in-prototype.c
@@ -1,13 +1,19 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+#define SA(n, c) int arr##n[(c) ? 1 : -1] = {}
+
const int AA = 5;
int f1(enum {AA,BB} E) { // expected-warning {{will not be visible outside of this function}}
- return BB;
+ SA(1, AA == 0);
+ SA(2, BB == 1);
+ return BB;
}
int f2(enum {AA=7,BB} E) { // expected-warning {{will not be visible outside of this function}}
- return AA;
+ SA(1, AA == 7);
+ SA(2, BB == 8);
+ return AA;
}
struct a {
@@ -38,3 +44,52 @@ enum e19018 qq; //expected-error{{tentative definition has type 'enum e19018' th
// Only warn once, even if we create two declarations.
void f(struct q *, struct __attribute__((aligned(4))) q *); // expected-warning {{will not be visible outside}}
+
+// This enum inside the function pointer parameter shouldn't leak into the
+// function.
+enum { BB = 0 };
+void enum_in_fun_in_fun(void (*fp)(enum { AA, BB } e)) { // expected-warning {{will not be visible}}
+ SA(1, AA == 5);
+ SA(2, BB == 0);
+}
+
+void f7() {
+ extern void ext(struct S { enum E7 { a, b } o; } p); // expected-warning 2 {{will not be visible}}
+ ext(a); // expected-error {{use of undeclared identifier}}
+}
+
+int f8(struct S { enum E8 { a, b } o; } p) { // expected-warning 2 {{will not be visible}}
+ struct S o;
+ enum E8 x;
+ return a + b;
+}
+// expected-note@+1 {{forward declaration}}
+struct S o; // expected-error {{'struct S' that is never completed}}
+// expected-note@+1 {{forward declaration}}
+enum E8 x = a + b; // expected-error 2 {{undeclared identifier}} expected-error {{incomplete type 'enum E8'}}
+
+int f9(struct { enum e { a = 1 } b; } c) { // expected-warning {{will not be visible}}
+ return a;
+}
+
+int f10(
+ struct S { // expected-warning {{will not be visible}}
+ enum E10 { a, b, c } f; // expected-warning {{will not be visible}}
+ } e) {
+ return a == b;
+}
+
+int f11(
+ struct S { // expected-warning {{will not be visible}}
+ enum E11 { // expected-warning {{will not be visible}}
+ a, b, c
+ } // expected-warning {{expected ';' at end of declaration list}}
+ } // expected-error {{expected member name or ';'}}
+ e);
+
+void f12() {
+ extern int ext12(
+ struct S12 { } e // expected-warning {{will not be visible}}
+ );
+ struct S12 o; // expected-error {{incomplete type}} expected-note {{forward declaration}}
+}
diff --git a/test/Sema/dllimport.c b/test/Sema/dllimport.c
index 0728cf14a8e3..a7fb00e3f773 100644
--- a/test/Sema/dllimport.c
+++ b/test/Sema/dllimport.c
@@ -210,6 +210,10 @@ __declspec(dllimport) void redecl6();
void redecl7();
__declspec(dllimport) inline void redecl7() {}
+// PR31069: Don't crash trying to merge attributes for redeclaration of invalid decl.
+void __declspec(dllimport) redecl8(unknowntype X); // expected-error{{unknown type name 'unknowntype'}}
+void redecl8(unknowntype X) { } // expected-error{{unknown type name 'unknowntype'}}
+
// External linkage is required.
__declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}
diff --git a/test/Sema/ext_vector_components.c b/test/Sema/ext_vector_components.c
index 7d3d52aa9546..3cdeb215f876 100644
--- a/test/Sema/ext_vector_components.c
+++ b/test/Sema/ext_vector_components.c
@@ -39,6 +39,33 @@ static void test() {
vec4.x = vec16.sF;
vec4p->yz = vec4p->xy;
+
+ vec2.a; // expected-error {{vector component access exceeds type 'float2'}}
+ vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+ vec4.rgba; // expected-warning {{expression result unused}}
+ vec4.rgbz; // expected-error {{illegal vector component name 'z'}}
+ vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
+ vec4.xyzr; // expected-error {{illegal vector component name 'r'}}
+ vec4.s01b; // expected-error {{vector component access exceeds type 'float4'}}
+
+ vec3 = vec4.rgb; // legal, shorten
+ f = vec2.r; // legal, shorten
+ f = vec4.rg.r; // legal, shorten
+ vec4_2.rgba = vec4.xyzw; // legal, no intermingling
+
+ vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec2.x = f;
+ vec2.rr = vec2_2.rg; // expected-error {{vector is not assignable (contains duplicate components)}}
+ vec2.gr = vec2_2.rg;
+ vec2.gr.g = vec2_2.r;
+ vec4 = (float4){ 1,2,3,4 };
+ vec4.rg.b; // expected-error {{vector component access exceeds type 'float2'}}
+ vec4.r = vec16.sf;
+ vec4.g = vec16.sF;
+
+ vec4p->gb = vec4p->rg;
}
float2 lo(float3 x) { return x.lo; }
diff --git a/test/Sema/format-strings-enum.c b/test/Sema/format-strings-enum.c
index e79f8598ab47..ba077a887e01 100644
--- a/test/Sema/format-strings-enum.c
+++ b/test/Sema/format-strings-enum.c
@@ -11,6 +11,7 @@
#endif
EXTERN_C int printf(const char *,...);
+EXTERN_C int scanf(const char *, ...);
typedef enum { Constant = 0 } TestEnum;
// Note that in C, the type of 'Constant' is 'int'. In C++ it is 'TestEnum'.
@@ -34,3 +35,18 @@ void testLong(LongEnum input) {
printf("%lu", input);
printf("%lu", LongConstant);
}
+
+#ifndef __cplusplus
+// GNU C allows forward declaring enums.
+extern enum forward_declared *fwd;
+
+void forward_enum() {
+ printf("%u", fwd); // expected-warning{{format specifies type 'unsigned int' but the argument has type 'enum forward_declared *}}
+ printf("%p", fwd);
+
+ scanf("%c", fwd); // expected-warning{{format specifies type 'char *' but the argument has type 'enum forward_declared *}}
+ scanf("%u", fwd);
+ scanf("%lu", fwd); // expected-warning{{format specifies type 'unsigned long *' but the argument has type 'enum forward_declared *}}
+ scanf("%p", fwd); // expected-warning{{format specifies type 'void **' but the argument has type 'enum forward_declared *}}
+}
+#endif
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c
index 5559710c6035..54651226adc5 100644
--- a/test/Sema/format-strings.c
+++ b/test/Sema/format-strings.c
@@ -156,10 +156,10 @@ void check_writeback_specifier()
void check_invalid_specifier(FILE* fp, char *buf)
{
- printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion specifier 'b'}}
+ printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion specifier 'b'}} expected-warning {{data argument not used by format string}}
fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}}
sprintf(buf,"%%%%%ld%d%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
- snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} expected-warning {{invalid conversion specifier ';'}}
+ snprintf(buf, 2, "%%%%%ld%;%d", 1, 2, 3); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} expected-warning {{invalid conversion specifier ';'}} expected-warning {{data argument not used by format string}}
}
void check_null_char_string(char* b)
@@ -251,7 +251,7 @@ void test10(int x, float f, int i, long long lli) {
printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}}
printf("%d%d\n", x); // expected-warning{{more '%' conversions than data arguments}}
printf("%d\n", x, x); // expected-warning{{data argument not used by format string}}
- printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 'W'}}
+ printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 'W'}} expected-warning {{data argument not used by format string}}
printf("%"); // expected-warning{{incomplete format specifier}}
printf("%.d", x); // no-warning
printf("%.", x); // expected-warning{{incomplete format specifier}}
@@ -270,7 +270,7 @@ void test10(int x, float f, int i, long long lli) {
printf("%.0Lf", (long double) 1.0); // no-warning
printf("%c\n", "x"); // expected-warning{{format specifies type 'int' but the argument has type 'char *'}}
printf("%c\n", 1.23); // expected-warning{{format specifies type 'int' but the argument has type 'double'}}
- printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid conversion specifier '!'}}
+ printf("Format %d, is %! %f", 1, 4.4); // expected-warning{{invalid conversion specifier '!'}}
}
typedef unsigned char uint8_t;
@@ -652,3 +652,43 @@ void test_format_security_pos(char* string) {
// expected-note@-1{{treat the string as an argument to avoid this}}
}
#pragma GCC diagnostic warning "-Wformat-nonliteral"
+
+void test_char_pointer_arithmetic(int b) {
+ const char s1[] = "string";
+ const char s2[] = "%s string";
+
+ printf(s1 - 1); // expected-warning {{format string is not a string literal (potentially insecure)}}
+ // expected-note@-1{{treat the string as an argument to avoid this}}
+
+ printf(s1 + 2); // no-warning
+ printf(s2 + 2); // no-warning
+
+ const char s3[] = "%s string";
+ printf((s3 + 2) - 2); // expected-warning{{more '%' conversions than data arguments}}
+ // expected-note@-2{{format string is defined here}}
+ printf(2 + s2); // no-warning
+ printf(6 + s2 - 2); // no-warning
+ printf(2 + (b ? s1 : s2)); // no-warning
+
+ const char s5[] = "string %s";
+ printf(2 + (b ? s2 : s5)); // expected-warning{{more '%' conversions than data arguments}}
+ // expected-note@-2{{format string is defined here}}
+ printf(2 + (b ? s2 : s5), ""); // no-warning
+ printf(2 + (b ? s1 : s2 - 2), ""); // no-warning
+
+ const char s6[] = "%s string";
+ printf(2 + (b ? s1 : s6 - 2)); // expected-warning{{more '%' conversions than data arguments}}
+ // expected-note@-2{{format string is defined here}}
+ printf(1 ? s2 + 2 : s2); // no-warning
+ printf(0 ? s2 : s2 + 2); // no-warning
+ printf(2 + s2 + 5 * 3 - 16, ""); // expected-warning{{data argument not used}}
+
+ const char s7[] = "%s string %s %s";
+ printf(s7 + 3, ""); // expected-warning{{more '%' conversions than data arguments}}
+ // expected-note@-2{{format string is defined here}}
+}
+
+void PR30481() {
+ // This caused crashes due to invalid casts.
+ printf(1 > 0); // expected-warning{{format string is not a string literal}} expected-warning{{incompatible integer to pointer conversion}} expected-note@format-strings.c:*{{passing argument to parameter here}} expected-note{{to avoid this}}
+}
diff --git a/test/Sema/generic-selection.c b/test/Sema/generic-selection.c
index 5c02005d0fa8..982995830573 100644
--- a/test/Sema/generic-selection.c
+++ b/test/Sema/generic-selection.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c1x -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
void g(void);
@@ -36,3 +36,11 @@ void foo(int n) {
// expression is not evaluated.
(void)_Generic(*(int *)0, int: 1);
}
+
+int __attribute__((overloadable)) test (int);
+double __attribute__((overloadable)) test (double);
+char testc(char);
+
+void PR30201(void) {
+ _Generic(4, char:testc, default:test)(4);
+}
diff --git a/test/Sema/implicit-intel-builtin-decl.c b/test/Sema/implicit-intel-builtin-decl.c
new file mode 100644
index 000000000000..e588a4b8866e
--- /dev/null
+++ b/test/Sema/implicit-intel-builtin-decl.c
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -target-feature +sse2 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -target-feature +sse2 -fsyntax-only -verify %s -x c++
+
+void f() {
+ (void)_mm_getcsr(); // expected-warning{{implicitly declaring library function '_mm_getcsr'}} \
+ // expected-note{{include the header <xmmintrin.h> or explicitly provide a declaration for '_mm_getcsr'}}
+ _mm_setcsr(1); // expected-warning{{implicitly declaring library function '_mm_setcsr'}} \
+ // expected-note{{include the header <xmmintrin.h> or explicitly provide a declaration for '_mm_setcsr'}}
+ _mm_sfence(); // expected-warning{{implicitly declaring library function '_mm_sfence'}} \
+ // expected-note{{include the header <xmmintrin.h> or explicitly provide a declaration for '_mm_sfence'}}
+
+ _mm_clflush((void*)0); // expected-warning{{implicitly declaring library function '_mm_clflush'}} \
+ // expected-note{{include the header <emmintrin.h> or explicitly provide a declaration for '_mm_clflush'}}
+ _mm_lfence(); // expected-warning{{implicitly declaring library function '_mm_lfence'}} \
+ // expected-note{{include the header <emmintrin.h> or explicitly provide a declaration for '_mm_lfence'}}
+ _mm_mfence(); // expected-warning{{implicitly declaring library function '_mm_mfence'}} \
+ // expected-note{{include the header <emmintrin.h> or explicitly provide a declaration for '_mm_mfence'}}
+ _mm_pause(); // expected-warning{{implicitly declaring library function '_mm_pause'}} \
+ // expected-note{{include the header <emmintrin.h> or explicitly provide a declaration for '_mm_pause'}}
+}
+
+unsigned int _mm_getcsr();
+void _mm_setcsr(unsigned int);
+void _mm_sfence();
+
+void _mm_clflush(void const *);
+void _mm_lfence();
+void _mm_mfence();
+void _mm_pause();
+
+void g() {
+ (void)_mm_getcsr();
+ _mm_setcsr(1);
+ _mm_sfence();
+
+ _mm_clflush((void*)0);
+ _mm_lfence();
+ _mm_mfence();
+ _mm_pause();
+}
diff --git a/test/Sema/implicit-ms-builtin-decl.c b/test/Sema/implicit-ms-builtin-decl.c
new file mode 100644
index 000000000000..9a3e410c47d8
--- /dev/null
+++ b/test/Sema/implicit-ms-builtin-decl.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s -fms-extensions
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fsyntax-only -verify %s -fms-extensions
+
+void f() {
+ (void)_byteswap_ushort(42); // expected-warning{{implicitly declaring library function '_byteswap_ushort'}} \
+ // expected-note{{include the header <stdlib.h> or explicitly provide a declaration for '_byteswap_ushort'}}
+ (void)_byteswap_uint64(42LL); // expected-warning{{implicitly declaring library function '_byteswap_uint64'}} \
+ // expected-note{{include the header <stdlib.h> or explicitly provide a declaration for '_byteswap_uint64'}}
+}
+
+void _byteswap_ulong(); // expected-warning{{incompatible redeclaration of library function '_byteswap_ulong'}} \
+// expected-note{{'_byteswap_ulong' is a builtin}}
+
+unsigned short _byteswap_ushort(unsigned short);
+unsigned long long _byteswap_uint64(unsigned long long);
+
+void g() {
+ (void)_byteswap_ushort(42);
+ (void)_byteswap_uint64(42LL);
+}
+
+#if defined(__x86_64__)
+void h() {
+ (void)__mulh(21, 2); // expected-warning{{implicitly declaring library function '__mulh'}} \
+ // expected-note{{include the header <intrin.h> or explicitly provide a declaration for '__mulh'}}
+ (void)__umulh(21, 2); // expected-warning{{implicitly declaring library function '__umulh'}} \
+ // expected-note{{include the header <intrin.h> or explicitly provide a declaration for '__umulh'}}
+}
+
+long long __mulh(long long, long long);
+unsigned long long __umulh(unsigned long long, unsigned long long);
+
+void i() {
+ (void)__mulh(21, 2);
+ (void)__umulh(21, 2);
+}
+#endif
+
+#if defined(i386)
+void h() {
+ (void)__mulh(21LL, 2LL); // expected-warning{{implicit declaration of function '__mulh' is invalid}}
+ (void)__umulh(21ULL, 2ULL); // expected-warning{{implicit declaration of function '__umulh' is invalid}}
+}
+#endif
diff --git a/test/Sema/incompatible-function-pointer-types.c b/test/Sema/incompatible-function-pointer-types.c
new file mode 100644
index 000000000000..f0f594f8db84
--- /dev/null
+++ b/test/Sema/incompatible-function-pointer-types.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only %s -Wincompatible-pointer-types -verify
+// RUN: %clang_cc1 -fsyntax-only %s -Wincompatible-function-pointer-types -verify
+
+// This test ensures that the subgroup of -Wincompatible-pointer-types warnings
+// that concern function pointers can be promoted (or not promoted) to an error
+// *separately* from the other -Wincompatible-pointer-type warnings.
+typedef int (*MyFnTyA)(int *, char *);
+
+int bar(char *a, int *b) { return 0; }
+int foo(MyFnTyA x) { return 0; } // expected-note {{passing argument to parameter 'x' here}}
+
+void baz() {
+ foo(&bar); // expected-warning {{incompatible function pointer types passing 'int (*)(char *, int *)' to parameter of type 'MyFnTyA' (aka 'int (*)(int *, char *)')}}
+}
diff --git a/test/Sema/initialize-noreturn.c b/test/Sema/initialize-noreturn.c
index 55578628716b..21ff29585ff9 100644
--- a/test/Sema/initialize-noreturn.c
+++ b/test/Sema/initialize-noreturn.c
@@ -4,13 +4,24 @@
typedef void (*Fn_noret)(void) __attribute__((noreturn));
typedef void (*Fn_ret)(void);
+typedef void (*Fn_noret_noproto)() __attribute__((noreturn));
+typedef void (*Fn_ret_noproto)();
+
void foo(void);
void foo_noret(void) __attribute__((noreturn));
+void foo_noproto();
+void foo_noret_noproto() __attribute__((noreturn));
+
void test() {
- Fn_noret fn2 = &foo; // expected-warning {{incompatible pointer types initializing 'Fn_noret'}}
+ Fn_noret fn2 = &foo; // expected-warning {{incompatible function pointer types initializing 'Fn_noret'}}
Fn_noret fn3 = &foo_noret;
Fn_ret fn4 = &foo_noret;
Fn_ret fn5 = &foo;
+
+ Fn_noret_noproto fn6 = &foo_noproto; // expected-warning {{incompatible function pointer types initializing 'Fn_noret_noproto'}}
+ Fn_noret_noproto fn7 = &foo_noret_noproto;
+ Fn_ret_noproto fn8 = &foo_noret_noproto;
+ Fn_ret_noproto fn9 = &foo_noproto;
}
diff --git a/test/Sema/no-warn-unused-const-variables.c b/test/Sema/no-warn-unused-const-variables.c
new file mode 100644
index 000000000000..73cfd8ea71b5
--- /dev/null
+++ b/test/Sema/no-warn-unused-const-variables.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c-header -ffreestanding -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-const-variable -x c++-header -ffreestanding -verify %s
+// expected-no-diagnostics
+static const int unused[] = { 2, 3, 5, 7, 11, 13 };
diff --git a/test/Sema/nullability.c b/test/Sema/nullability.c
index 71e12734d1d2..a0247e5af8b3 100644
--- a/test/Sema/nullability.c
+++ b/test/Sema/nullability.c
@@ -128,3 +128,122 @@ void nullable_to_nonnull(_Nullable int *ptr) {
accepts_nonnull_1(ptr); // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
}
+
+// Check nullability of conditional expressions.
+void conditional_expr(int c) {
+ int * _Nonnull p;
+ int * _Nonnull nonnullP;
+ int * _Nullable nullableP;
+ int * _Null_unspecified unspecifiedP;
+ int *noneP;
+
+ p = c ? nonnullP : nonnullP;
+ p = c ? nonnullP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? nonnullP : unspecifiedP;
+ p = c ? nonnullP : noneP;
+ p = c ? nullableP : nonnullP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? nullableP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? nullableP : unspecifiedP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? nullableP : noneP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? unspecifiedP : nonnullP;
+ p = c ? unspecifiedP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? unspecifiedP : unspecifiedP;
+ p = c ? unspecifiedP : noneP;
+ p = c ? noneP : nonnullP;
+ p = c ? noneP : nullableP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? noneP : unspecifiedP;
+ p = c ? noneP : noneP;
+
+ // Check that we don't remove all sugar when creating a new QualType for the
+ // conditional expression.
+ typedef int *IntP;
+ typedef IntP _Nonnull NonnullIntP0;
+ typedef NonnullIntP0 _Nonnull NonnullIntP1;
+ typedef IntP _Nullable NullableIntP0;
+ typedef NullableIntP0 _Nullable NullableIntP1;
+ NonnullIntP1 nonnullP2;
+ NullableIntP1 nullableP2;
+
+ p = c ? nonnullP2 : nonnullP2;
+ p = c ? nonnullP2 : nullableP2; // expected-warning{{implicit conversion from nullable pointer 'IntP _Nullable' (aka 'int *') to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? nullableP2 : nonnullP2; // expected-warning{{implicit conversion from nullable pointer 'NullableIntP1' (aka 'int *') to non-nullable pointer type 'int * _Nonnull'}}
+ p = c ? nullableP2 : nullableP2; // expected-warning{{implicit conversion from nullable pointer 'NullableIntP1' (aka 'int *') to non-nullable pointer type 'int * _Nonnull'}}
+}
+
+// Check nullability of binary conditional expressions.
+void binary_conditional_expr() {
+ int * _Nonnull p;
+ int * _Nonnull nonnullP;
+ int * _Nullable nullableP;
+ int * _Null_unspecified unspecifiedP;
+ int *noneP;
+
+ p = nonnullP ?: nonnullP;
+ p = nonnullP ?: nullableP;
+ p = nonnullP ?: unspecifiedP;
+ p = nonnullP ?: noneP;
+ p = nullableP ?: nonnullP;
+ p = nullableP ?: nullableP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = nullableP ?: unspecifiedP;
+ p = nullableP ?: noneP;
+ p = unspecifiedP ?: nonnullP;
+ p = unspecifiedP ?: nullableP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = unspecifiedP ?: unspecifiedP;
+ p = unspecifiedP ?: noneP;
+ p = noneP ?: nonnullP;
+ p = noneP ?: nullableP; // expected-warning{{implicit conversion from nullable pointer 'int * _Nullable' to non-nullable pointer type 'int * _Nonnull'}}
+ p = noneP ?: unspecifiedP;
+ p = noneP ?: noneP;
+}
+
+extern int GLOBAL_LENGTH;
+
+// Nullability can appear on arrays when the arrays are in parameter lists.
+void arrays(int ints[_Nonnull],
+ void *ptrs[_Nullable],
+ void **nestedPtrs[_Nullable],
+ void * _Null_unspecified * _Nonnull nestedPtrs2[_Nullable],
+ int fixedSize[_Nonnull 2],
+ int staticSize[_Nonnull static 2],
+ int staticSize2[static _Nonnull 2],
+ int starSize[_Nonnull *],
+ int vla[_Nonnull GLOBAL_LENGTH],
+ void ** _Nullable reference);
+void testDecayedType() {
+ int produceAnErrorMessage = arrays; // expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'void (int * _Nonnull, void ** _Nullable, void *** _Nullable, void * _Null_unspecified * _Nonnull * _Nullable, int * _Nonnull, int * _Nonnull, int * _Nonnull, int * _Nonnull, int * _Nonnull, void ** _Nullable)'}}
+}
+
+int notInFunction[_Nullable 3]; // expected-error {{nullability specifier '_Nullable' cannot be applied to non-pointer type 'int [3]'}}
+
+void nestedArrays(int x[5][_Nonnull 1]) {} // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [1]'}}
+void nestedArrays2(int x[5][_Nonnull 1][2]) {} // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [1][2]'}}
+void nestedArraysOK(int x[_Nonnull 5][1]) {} // ok
+
+void nullabilityOnBase(_Nonnull int x[1], // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int'}}
+ int _Nonnull y[1]); // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int'}}
+
+typedef int INTS[4];
+typedef int BAD_INTS[_Nonnull 4]; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [4]'}}
+
+void typedefTest(INTS _Nonnull x,
+ _Nonnull INTS xx,
+ INTS _Nonnull y[2], // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}}
+ INTS z[_Nonnull 2]);
+
+INTS _Nonnull x; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}}
+_Nonnull INTS x; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}}
+
+void arraysInBlocks() {
+ typedef int INTS[4];
+ void (^simple)(int [_Nonnull 2]) = ^(int x[_Nonnull 2]) {};
+ simple(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
+ void (^nested)(void *_Nullable x[_Nonnull 2]) = ^(void *_Nullable x[_Nonnull 2]) {};
+ nested(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
+ void (^nestedBad)(int x[2][_Nonnull 2]) = // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [2]'}}
+ ^(int x[2][_Nonnull 2]) {}; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int [2]'}}
+
+ void (^withTypedef)(INTS _Nonnull) = ^(INTS _Nonnull x) {};
+ withTypedef(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
+ void (^withTypedefBad)(INTS _Nonnull [2]) = // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}}
+ ^(INTS _Nonnull x[2]) {}; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int [4]')}}
+}
diff --git a/test/Sema/overloadable.c b/test/Sema/overloadable.c
index 5d95a317fa38..f5e17d211910 100644
--- a/test/Sema/overloadable.c
+++ b/test/Sema/overloadable.c
@@ -23,7 +23,7 @@ float *accept_funcptr(int (*)(int, double)) __attribute__((overloadable)); // \
void test_funcptr(int (*f1)(int, double),
int (*f2)(int, float)) {
float *fp = accept_funcptr(f1);
- accept_funcptr(f2); // expected-error{{no matching function for call to 'accept_funcptr'}}
+ accept_funcptr(f2); // expected-error{{call to 'accept_funcptr' is ambiguous}}
}
struct X { int x; float y; };
@@ -109,7 +109,7 @@ void fn_type_conversions() {
void (*ambiguous)(int *) = &foo; // expected-error{{initializing 'void (*)(int *)' with an expression of incompatible type '<overloaded function type>'}} expected-note@105{{candidate function}} expected-note@106{{candidate function}}
void *vp_ambiguous = &foo; // expected-error{{initializing 'void *' with an expression of incompatible type '<overloaded function type>'}} expected-note@105{{candidate function}} expected-note@106{{candidate function}}
- void (*specific1)(int *) = (void (*)(void *))&foo; // expected-warning{{incompatible pointer types initializing 'void (*)(int *)' with an expression of type 'void (*)(void *)'}}
+ void (*specific1)(int *) = (void (*)(void *))&foo; // expected-warning{{incompatible function pointer types initializing 'void (*)(int *)' with an expression of type 'void (*)(void *)'}}
void *specific2 = (void (*)(void *))&foo;
void disabled(void *c) __attribute__((overloadable, enable_if(0, "")));
@@ -122,3 +122,32 @@ void fn_type_conversions() {
void *specific_disabled = &disabled;
}
+
+void incompatible_pointer_type_conversions() {
+ char charbuf[1];
+ unsigned char ucharbuf[1];
+ int intbuf[1];
+
+ void foo(char *c) __attribute__((overloadable));
+ void foo(short *c) __attribute__((overloadable));
+ foo(charbuf);
+ foo(ucharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@131{{candidate function}} expected-note@132{{candidate function}}
+ foo(intbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@131{{candidate function}} expected-note@132{{candidate function}}
+
+ void bar(unsigned char *c) __attribute__((overloadable));
+ void bar(signed char *c) __attribute__((overloadable));
+ bar(charbuf); // expected-error{{call to 'bar' is ambiguous}} expected-note@137{{candidate function}} expected-note@138{{candidate function}}
+ bar(ucharbuf);
+ bar(intbuf); // expected-error{{call to 'bar' is ambiguous}} expected-note@137{{candidate function}} expected-note@138{{candidate function}}
+}
+
+void dropping_qualifiers_is_incompatible() {
+ const char ccharbuf[1];
+ volatile char vcharbuf[1];
+
+ void foo(char *c) __attribute__((overloadable));
+ void foo(const volatile unsigned char *c) __attribute__((overloadable));
+
+ foo(ccharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@148{{candidate function}} expected-note@149{{candidate function}}
+ foo(vcharbuf); // expected-error{{call to 'foo' is ambiguous}} expected-note@148{{candidate function}} expected-note@149{{candidate function}}
+}
diff --git a/test/Sema/pass-object-size.c b/test/Sema/pass-object-size.c
index ddfbbd5fc4e1..0745105df831 100644
--- a/test/Sema/pass-object-size.c
+++ b/test/Sema/pass-object-size.c
@@ -52,5 +52,5 @@ void FunctionPtrs() {
int P;
(&NotOverloaded)(&P); //expected-error{{cannot take address of function 'NotOverloaded' because parameter 1 has pass_object_size attribute}}
- (&IsOverloaded)(&P); //expected-error{{no matching function}} expected-note@35{{candidate address cannot be taken because parameter 1 has pass_object_size attribute}} expected-note@36{{candidate function not viable: no known conversion from 'int *' to 'char *' for 1st argument}}
+ (&IsOverloaded)(&P); //expected-warning{{incompatible pointer types passing 'int *' to parameter of type 'char *'}} expected-note@36{{passing argument to parameter 'p' here}}
}
diff --git a/test/Sema/pr30372.c b/test/Sema/pr30372.c
new file mode 100644
index 000000000000..e10fa2c84130
--- /dev/null
+++ b/test/Sema/pr30372.c
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 %s -triple i386-pc-windows-msvc18.0.0 -disable-free -fms-volatile -fms-extensions -fms-compatibility -fms-compatibility-version=18 -std=c++11 -x c++
+
+// Check that the parser catching an 'error' from forward declaration of "location" does not lexer out it's subsequent declation.
+
+void foo() {
+ __asm {
+ jl location
+ location:
+ ret
+ }
+}
diff --git a/test/Sema/shift.c b/test/Sema/shift.c
index 07c5fe5280ed..47744fb049fd 100644
--- a/test/Sema/shift.c
+++ b/test/Sema/shift.c
@@ -67,3 +67,14 @@ void test_shift_too_much(char x) {
(void) (x >> 80); // no-warning
(void) (x >> 80); // expected-warning {{shift count >= width of type}}
}
+
+typedef unsigned vec16 __attribute__((vector_size(16)));
+typedef unsigned vec8 __attribute__((vector_size(8)));
+
+void vect_shift_1(vec16 *x) { *x = *x << 4; }
+
+void vect_shift_2(vec16 *x, vec16 y) { *x = *x << y; }
+
+void vect_shift_3(vec16 *x, vec8 y) {
+ *x = *x << y; // expected-error {{vector operands do not have the same number of elements}}
+}
diff --git a/test/Sema/transparent-union.c b/test/Sema/transparent-union.c
index 8ef70bb1c7e3..a1a67dfd26fc 100644
--- a/test/Sema/transparent-union.c
+++ b/test/Sema/transparent-union.c
@@ -89,3 +89,12 @@ union pr15134v2 {
unsigned int u3;
} __attribute__((aligned(8)));
} __attribute__((transparent_union));
+
+union pr30520v { void b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'void'}}
+
+union pr30520a { int b[]; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'int []'}}
+
+// expected-note@+1 2 {{forward declaration of 'struct stb'}}
+union pr30520s { struct stb b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'struct stb'}}
+
+union pr30520s2 { int *v; struct stb b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'struct stb'}}
diff --git a/test/Sema/varargs.c b/test/Sema/varargs.c
index 457d84c212f7..25a5c72c42e3 100644
--- a/test/Sema/varargs.c
+++ b/test/Sema/varargs.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s -triple x86_64-pc-win32
void f1(int a)
{
@@ -94,3 +95,20 @@ void f12(register int i, ...) { // expected-note {{parameter of type 'int' is d
__builtin_va_start(ap, i); // expected-warning {{passing a parameter declared with the 'register' keyword to 'va_start' has undefined behavior}}
__builtin_va_end(ap);
}
+
+enum __attribute__((packed)) E1 {
+ one1
+};
+
+void f13(enum E1 e, ...) {
+ __builtin_va_list va;
+ __builtin_va_start(va, e);
+#ifndef MS
+ // In Microsoft compatibility mode, all enum types are int, but in
+ // non-ms-compatibility mode, this enumeration type will undergo default
+ // argument promotions.
+ // expected-note@-7 {{parameter of type 'enum E1' is declared here}}
+ // expected-warning@-6 {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
+#endif
+ __builtin_va_end(va);
+}
diff --git a/test/Sema/vecshift.c b/test/Sema/vecshift.c
new file mode 100644
index 000000000000..7b6a30ad60dd
--- /dev/null
+++ b/test/Sema/vecshift.c
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -fsyntax-only -DERR -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-error-vec-elem-size -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DEXT -DERR -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DEXT -Wno-error-vec-elem-size -verify %s
+
+#ifdef EXT
+typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
+typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
+typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8;
+typedef __attribute__((__ext_vector_type__(4))) char vector_char4;
+typedef __attribute__((__ext_vector_type__(4))) short vector_short4;
+typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+#else
+typedef __attribute__((vector_size(8))) char vector_char8;
+typedef __attribute__((vector_size(16))) short vector_short8;
+typedef __attribute__((vector_size(32))) int vector_int8;
+typedef __attribute__((vector_size(8))) unsigned char vector_uchar8;
+typedef __attribute__((vector_size(16))) unsigned short vector_ushort8;
+typedef __attribute__((vector_size(32))) unsigned int vector_uint8;
+typedef __attribute__((vector_size(4))) char vector_char4;
+typedef __attribute__((vector_size(4))) short vector_short4;
+typedef __attribute__((vector_size(16))) int vector_int4;
+typedef __attribute__((vector_size(4))) unsigned char vector_uchar4;
+typedef __attribute__((vector_size(8))) unsigned short vector_ushort4;
+typedef __attribute__((vector_size(16))) unsigned int vector_uint4;
+#endif
+
+char c;
+short s;
+int i;
+unsigned char uc;
+unsigned short us;
+unsigned int ui;
+vector_char8 vc8;
+vector_short8 vs8;
+vector_int8 vi8;
+vector_uchar8 vuc8;
+vector_ushort8 vus8;
+vector_uint8 vui8;
+vector_char4 vc4;
+vector_short4 vs4;
+vector_int4 vi4;
+vector_uchar4 vuc4;
+vector_ushort4 vus4;
+vector_uint4 vui4;
+
+void foo() {
+ vc8 = 1 << vc8;
+ vuc8 = 1 << vuc8;
+ vi8 = 1 << vi8;
+ vui8 = 1 << vui8;
+ vs8 = 1 << vs8;
+ vus8 = 1 << vus8;
+
+ vc8 = c << vc8;
+ vuc8 = i << vuc8;
+ vi8 = uc << vi8;
+ vui8 = us << vui8;
+ vs8 = ui << vs8;
+ vus8 = 1 << vus8;
+
+ vc8 = vc8 << vc8;
+#ifdef ERR
+ vi8 = vi8 << vuc8; // expected-error {{vector operands do not have the same elements sizes}}
+ vuc8 = vuc8 << vi8; // expected-error {{vector operands do not have the same elements sizes}}
+ vus8 = vus8 << vui8; // expected-error {{vector operands do not have the same elements sizes}}
+ vui8 = vui8 << vs8; // expected-error {{vector operands do not have the same elements sizes}}
+#else
+ vi8 = vi8 << vuc8; // expected-warning {{vector operands do not have the same elements sizes}}
+ vuc8 = vuc8 << vi8; // expected-warning {{vector operands do not have the same elements sizes}}
+ vus8 = vus8 << vui8; // expected-warning {{vector operands do not have the same elements sizes}}
+ vui8 = vui8 << vs8; // expected-warning {{vector operands do not have the same elements sizes}}
+#endif
+
+ vc8 <<= vc8;
+#ifdef ERR
+ vi8 <<= vuc8; // expected-error {{vector operands do not have the same elements sizes}}
+ vuc8 <<= vi8; // expected-error {{vector operands do not have the same elements sizes}}
+ vus8 <<= vui8; // expected-error {{vector operands do not have the same elements sizes}}
+ vui8 <<= vs8; // expected-error {{vector operands do not have the same elements sizes}}
+#else
+ vi8 <<= vuc8; // expected-warning {{vector operands do not have the same elements sizes}}
+ vuc8 <<= vi8; // expected-warning {{vector operands do not have the same elements sizes}}
+ vus8 <<= vui8; // expected-warning {{vector operands do not have the same elements sizes}}
+ vui8 <<= vs8; // expected-warning {{vector operands do not have the same elements sizes}}
+#endif
+
+ c <<= vc8; // expected-error {{assigning to 'char' from incompatible type}}
+ i <<= vuc8; // expected-error {{assigning to 'int' from incompatible type}}
+ uc <<= vi8; // expected-error {{assigning to 'unsigned char' from incompatible type}}
+ us <<= vui8; // expected-error {{assigning to 'unsigned short' from incompatible type}}
+ ui <<= vs8; // expected-error {{assigning to 'unsigned int' from incompatible type}}
+}
diff --git a/test/Sema/vector-cast.c b/test/Sema/vector-cast.c
index c0382892b699..ea4acfac6a0b 100644
--- a/test/Sema/vector-cast.c
+++ b/test/Sema/vector-cast.c
@@ -53,14 +53,13 @@ void f4() {
float2 f2;
double d, a, b, c;
float64x2_t v = {0.0, 1.0};
- f2 += d;
+ // FIXME: These diagnostics are inaccurate: should complain that 'double' to vector 'float2' involves truncation
+ f2 += d; // expected-error {{cannot convert between vector values of different size ('float2' (vector of 2 'float' values) and 'double')}}
+ d += f2; // expected-error {{cannot convert between vector values of different size}}
a = 3.0 + vget_low_f64(v);
b = vget_low_f64(v) + 3.0;
c = vget_low_f64(v);
- // LAX conversions within compound assignments are not supported.
- // FIXME: This diagnostic is inaccurate.
- d += f2; // expected-error {{cannot convert between vector values of different size}}
- c -= vget_low_f64(v); // expected-error {{cannot convert between vector values of different size}}
+ c -= vget_low_f64(v);
// LAX conversions between scalar and vector types require same size and one element sized vectors.
d = f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
d = d + f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
diff --git a/test/Sema/vfprintf-invalid-redecl.c b/test/Sema/vfprintf-invalid-redecl.c
index cbf47a69a9a1..f06b1b6d2147 100644
--- a/test/Sema/vfprintf-invalid-redecl.c
+++ b/test/Sema/vfprintf-invalid-redecl.c
@@ -3,4 +3,4 @@
// The following declaration is not compatible with vfprintf(), but make
// sure this isn't an error: autoconf expects this to build.
-char vfprintf(); // expected-warning {{incompatible redeclaration of library function 'vfprintf'}} expected-note {{'vfprintf' is a builtin}}
+char vfprintf(); // expected-warning {{declaration of built-in function 'vfprintf'}}
diff --git a/test/Sema/vfprintf-valid-redecl.c b/test/Sema/vfprintf-valid-redecl.c
index 8ed18786ab7e..eb5c4d330718 100644
--- a/test/Sema/vfprintf-valid-redecl.c
+++ b/test/Sema/vfprintf-valid-redecl.c
@@ -1,16 +1,18 @@
// RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify
// RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify -DPREDECLARE
-// expected-no-diagnostics
#ifdef PREDECLARE
// PR16344
// Clang has defined 'vfprint' in builtin list. If the following line occurs before any other
// `vfprintf' in this file, and we getPreviousDecl()->getTypeSourceInfo() on it, then we will
// get a null pointer since the one in builtin list doesn't has valid TypeSourceInfo.
-int vfprintf(void) { return 0; }
+int vfprintf(void) { return 0; } // expected-warning {{requires inclusion of the header <stdio.h>}}
#endif
// PR4290
// The following declaration is compatible with vfprintf, so we shouldn't
-// warn.
+// reject.
int vfprintf();
+#ifndef PREDECLARE
+// expected-warning@-2 {{requires inclusion of the header <stdio.h>}}
+#endif
diff --git a/test/Sema/warn-cast-align.c b/test/Sema/warn-cast-align.c
index 9d64699bb5b4..e8f85bc14d8d 100644
--- a/test/Sema/warn-cast-align.c
+++ b/test/Sema/warn-cast-align.c
@@ -39,3 +39,23 @@ void test2(char *P) {
void test3(char *P) {
struct B *b = (struct B*) P;
}
+
+// Do not issue a warning. The aligned attribute changes the alignment of the
+// variables and fields.
+char __attribute__((aligned(4))) a[16];
+
+struct S0 {
+ char a[16];
+};
+
+struct S {
+ char __attribute__((aligned(4))) a[16];
+ struct S0 __attribute__((aligned(4))) s0;
+};
+
+void test4() {
+ struct S s;
+ int *i = (int *)s.a;
+ i = (int *)&s.s0;
+ i = (int *)a;
+}
diff --git a/test/Sema/warn-documentation-unknown-command.cpp b/test/Sema/warn-documentation-unknown-command.cpp
index 3674a9c68010..4328c9682f21 100644
--- a/test/Sema/warn-documentation-unknown-command.cpp
+++ b/test/Sema/warn-documentation-unknown-command.cpp
@@ -9,3 +9,7 @@ int test_unknown_comand_1;
/// \retur aaa
int test_unknown_comand_2();
+// RUN: c-index-test -test-load-source all -Wdocumentation-unknown-command %s > /dev/null 2> %t.err
+// RUN: FileCheck < %t.err -check-prefix=CHECK-RANGE %s
+// CHECK-RANGE: warn-documentation-unknown-command.cpp:5:9:{5:9-5:17}: warning: unknown command tag name
+// CHECK-RANGE: warn-documentation-unknown-command.cpp:9:5:{9:5-9:11}: warning: unknown command tag name 'retur'; did you mean 'return'?
diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp
index 5d866359aa75..34d8f5fd2da2 100644
--- a/test/Sema/warn-documentation.cpp
+++ b/test/Sema/warn-documentation.cpp
@@ -368,6 +368,101 @@ typedef unsigned int test_not_function_like_typedef3;
/// \param aaa Meow.
typedef foo::not_a_function_wrapper<1> test_not_function_like_typedef4;
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using1 = int (int aaa, int ccc);
+
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using2 = int (*)(int aaa, int ccc);
+
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using3 = int (* const)(int aaa, int ccc);
+
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using4 = int (C::*)(int aaa, int ccc);
+
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using5 = foo::function_wrapper<int (int aaa, int ccc)>;
+
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using6 = foo::function_wrapper<int (int aaa, int ccc)> *;
+
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using7 = foo::function_wrapper<int (int aaa, int ccc)> &;
+
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \returns aaa.
+using test_function_like_using8 = foo::function_wrapper<int (int aaa, int ccc)> &&;
+
+// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using9 = int(T aaa, int ccc);
+
+// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using10 = int (*)(T aaa, int ccc);
+
+// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using11 = foo::function_wrapper<int (T aaa, int ccc)>;
+
+// expected-warning@+4 {{template parameter 'U' not found in the template declaration}} expected-note@+4 {{did you mean 'T'?}}
+// expected-warning@+2 {{parameter 'bbb' not found in the function declaration}} expected-note@+2 {{did you mean 'ccc'?}}
+/// \param aaa Meow.
+/// \param bbb Bbb.
+/// \tparam U Uuu.
+template<typename T>
+using test_function_like_using12 = foo::function_wrapper<int (T aaa, int ccc)> *;
+
+using test_not_function_like_using1 = int (*)(int aaa);
+
+// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
+/// \param aaa Meow.
+using test_not_function_like_using2 = test_not_function_like_using1;
+
+// Check that the diagnostic uses the same command marker as the comment.
+// expected-warning@+1 {{'@param' command used in a comment that is not attached to a function declaration}}
+/// @param aaa Meow.
+using test_not_function_like_using3 = unsigned int;
+
+// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
+/// \param aaa Meow.
+using test_not_function_like_using4 = foo::not_a_function_wrapper<1>;
+
/// \param aaa Aaa
/// \param ... Vararg
int test_vararg_param1(int aaa, ...);
diff --git a/test/Sema/warn-main-returns-bool-literal.cpp b/test/Sema/warn-main-returns-bool-literal.cpp
new file mode 100644
index 000000000000..188f161dd324
--- /dev/null
+++ b/test/Sema/warn-main-returns-bool-literal.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wmain -verify %s
+
+// expected-note@+1 {{previous definition is here}}
+int main() {
+ return 0;
+} // no-warning
+
+// expected-error@+1 {{redefinition of 'main'}}
+int main() {
+ return 1.0;
+} // no-warning
+
+int main() {
+ bool b = true;
+ return b; // no-warning
+}
+
+int main() {
+ return true; // expected-warning {{bool literal returned from 'main'}}
+}
diff --git a/test/Sema/warn-strict-prototypes.c b/test/Sema/warn-strict-prototypes.c
new file mode 100644
index 000000000000..496579c1f60e
--- /dev/null
+++ b/test/Sema/warn-strict-prototypes.c
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+// function declaration with unspecified params
+void foo1(); // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:"void"
+// function declaration with 0 params
+void foo2(void);
+
+// function definition with 0 params(for both cases),
+// valid according to 6.7.5.3/14
+void foo1() {}
+void foo2(void) {}
+
+// function type typedef unspecified params
+typedef void foo3(); // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
+
+// global fp unspecified params
+void (*foo4)(); // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"void"
+
+// struct member fp unspecified params
+struct { void (*foo5)(); } s; // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:23-[[@LINE-1]]:23}:"void"
+
+// param fp unspecified params
+void bar2(void (*foo6)()) { // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:24-[[@LINE-1]]:24}:"void"
+ // local fp unspecified params
+ void (*foo7)() = 0; // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:16-[[@LINE-1]]:16}:"void"
+ // array fp unspecified params
+ void (*foo8[2])() = {0}; // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:19-[[@LINE-1]]:19}:"void"
+}
+
+// function type cast using using an anonymous function declaration
+void bar3(void) {
+ // casting function w/out prototype to unspecified params function type
+ (void)(void(*)()) foo1; // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:18-[[@LINE-1]]:18}:"void"
+ // .. specified params
+ (void)(void(*)(void)) foo1;
+}
+
+// K&R function definition not preceded by full prototype
+int foo9(a, b) // expected-warning {{old-style function definition is not preceded by a prototype}}
+ int a, b;
+{
+ return a + b;
+}
+
+// Function declaration with no types
+void foo10(); // expected-warning {{this function declaration is not a prototype}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:12-[[@LINE-1]]:12}:"void"
+// K&R function definition with incomplete param list declared
+void foo10(p, p2) void *p; {} // expected-warning {{old-style function definition is not preceded by a prototype}}
+
+// K&R function definition with previous prototype declared is not diagnosed.
+void foo11(int p, int p2);
+void foo11(p, p2) int p; int p2; {}
diff --git a/test/Sema/warn-strict-prototypes.m b/test/Sema/warn-strict-prototypes.m
new file mode 100644
index 000000000000..cbb01a1f7b21
--- /dev/null
+++ b/test/Sema/warn-strict-prototypes.m
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -Wstrict-prototypes -verify -fblocks %s
+
+@interface Foo
+
+@property (nonatomic, copy) void (^noProtoBlock)(); // expected-warning {{this function declaration is not a prototype}}
+@property (nonatomic, copy) void (^block)(void); // no warning
+
+- doStuff:(void (^)()) completionHandler; // expected-warning {{this function declaration is not a prototype}}
+- doOtherStuff:(void (^)(void)) completionHandler; // no warning
+
+@end
+
+void foo() {
+ void (^block)() = // expected-warning {{this function declaration is not a prototype}}
+ ^void(int arg) { // no warning
+ };
+ void (^block2)(void) = // no warning
+ ^void() { // expected-warning {{this function declaration is not a prototype}}
+ };
+}