summaryrefslogtreecommitdiffstats
path: root/test/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/MicrosoftExtensions.c8
-rw-r--r--test/Sema/arm-neon-types.c9
-rw-r--r--test/Sema/asm.c8
-rw-r--r--test/Sema/attr-unknown.c2
-rw-r--r--test/Sema/builtins-arm.c5
-rw-r--r--test/Sema/carbon.c2
-rw-r--r--test/Sema/exprs.c18
-rw-r--r--test/Sema/illegal-types.c2
-rw-r--r--test/Sema/parentheses.c24
-rw-r--r--test/Sema/parentheses.cpp31
-rw-r--r--test/Sema/stdcall-fastcall.c3
-rw-r--r--test/Sema/uninit-variables.c13
-rw-r--r--test/Sema/x86-builtin-palignr.c3
13 files changed, 121 insertions, 7 deletions
diff --git a/test/Sema/MicrosoftExtensions.c b/test/Sema/MicrosoftExtensions.c
index cb9fee9..7438f7f5 100644
--- a/test/Sema/MicrosoftExtensions.c
+++ b/test/Sema/MicrosoftExtensions.c
@@ -79,3 +79,11 @@ struct X0 {
enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
SomeValue = 0x100000000
};
+
+
+void pointer_to_integral_type_conv(char* ptr) {
+ char ch = (char)ptr;
+ short sh = (short)ptr;
+ ch = (char)ptr;
+ sh = (short)ptr;
+}
diff --git a/test/Sema/arm-neon-types.c b/test/Sema/arm-neon-types.c
index 152d4c9..1e8c9bf 100644
--- a/test/Sema/arm-neon-types.c
+++ b/test/Sema/arm-neon-types.c
@@ -9,5 +9,12 @@ int32x2_t test(int32x2_t x) {
// ...but should warn when the types really do not match.
float32x2_t test2(uint32x2_t x) {
- return vcvt_n_f32_s32(x, 0); // expected-warning {{incompatible vector types}}
+ return vcvt_n_f32_s32(x, 9); // expected-warning {{incompatible vector types}}
+}
+
+// Check immediate range for vcvt_n intrinsics is 1 to 32. Radar 9558930.
+float32x2_t test3(uint32x2_t x) {
+ // FIXME: The "incompatible result type" error is due to pr10112 and should be
+ // removed when that is fixed.
+ return vcvt_n_f32_u32(x, 0); // expected-error {{argument should be a value from 1 to 32}} expected-error {{incompatible result type}}
}
diff --git a/test/Sema/asm.c b/test/Sema/asm.c
index 7f0f396..d8161c8 100644
--- a/test/Sema/asm.c
+++ b/test/Sema/asm.c
@@ -105,3 +105,11 @@ void test10(void){
register int r asm ("cx");
register int rr asm ("rr_asm"); // expected-error{{unknown register name 'rr_asm' in asm}}
}
+
+// This is just an assert because of the boolean conversion.
+// Feel free to change the assembly to something sensible if it causes a problem.
+// rdar://problem/9414925
+void test11(void) {
+ _Bool b;
+ asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L));
+}
diff --git a/test/Sema/attr-unknown.c b/test/Sema/attr-unknown.c
index bec2e29..d1a831d 100644
--- a/test/Sema/attr-unknown.c
+++ b/test/Sema/attr-unknown.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunknown-attributes %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wattributes %s
int x __attribute__((foobar)); // expected-warning {{unknown attribute 'foobar' ignored}}
void z() __attribute__((bogusattr)); // expected-warning {{unknown attribute 'bogusattr' ignored}}
diff --git a/test/Sema/builtins-arm.c b/test/Sema/builtins-arm.c
index 4dd31e7..4077240 100644
--- a/test/Sema/builtins-arm.c
+++ b/test/Sema/builtins-arm.c
@@ -9,3 +9,8 @@ void __clear_cache(char*, char*);
void __clear_cache(void*, void*);
#endif
+// va_list on ARM is void*.
+void test2() {
+ __builtin_va_list ptr = "x";
+ *ptr = '0'; // expected-error {{incomplete type 'void' is not assignable}}
+}
diff --git a/test/Sema/carbon.c b/test/Sema/carbon.c
index f0affd2..045d72c 100644
--- a/test/Sema/carbon.c
+++ b/test/Sema/carbon.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -target-cpu pentium4 %s -print-stats
+// RUN: %clang -fsyntax-only %s -print-stats
#ifdef __APPLE__
#include <Carbon/Carbon.h>
#endif
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
index e4eeaec..9ce1481 100644
--- a/test/Sema/exprs.c
+++ b/test/Sema/exprs.c
@@ -189,6 +189,24 @@ int test20(int x) {
// no warning, this is an idiom for "true" in old C style.
return x && (signed char)1;
+
+ return x || 0;
+ return x || 1;
+ return x || -1; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || 5; // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x && 0;
+ return x && 1;
+ return x && -1; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && 5; // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x || (0);
+ return x || (1);
+ return x || (-1); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x || (5); // expected-warning {{use of logical || with constant operand; switch to bitwise | or remove constant}}
+ return x && (0);
+ return x && (1);
+ return x && (-1); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+ return x && (5); // expected-warning {{use of logical && with constant operand; switch to bitwise & or remove constant}}
+
}
struct Test21; // expected-note 2 {{forward declaration}}
diff --git a/test/Sema/illegal-types.c b/test/Sema/illegal-types.c
index 3c59df8..819b38a 100644
--- a/test/Sema/illegal-types.c
+++ b/test/Sema/illegal-types.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -x c++ -std=c++98 %s
void a (void []()); // expected-error{{'type name' declared as array of functions}}
void b (void p[]()); // expected-error{{'p' declared as array of functions}}
diff --git a/test/Sema/parentheses.c b/test/Sema/parentheses.c
index a25ded6..fa3c3c2 100644
--- a/test/Sema/parentheses.c
+++ b/test/Sema/parentheses.c
@@ -39,6 +39,28 @@ void bitwise_rel(unsigned i) {
(void)(0 || i && i); // no warning.
}
+_Bool someConditionFunc();
+
+void conditional_op(int x, int y, _Bool b) {
+ (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: has lower precedence than +}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the + expression to silence this warning}}
+
+ (void)(x - b ? 1 : 2); // expected-warning {{?: has lower precedence than -}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the - expression to silence this warning}}
+
+ (void)(x * (x == y) ? 1 : 2); // expected-warning {{?: has lower precedence than *}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the * expression to silence this warning}}
+
+ (void)(x / !x ? 1 : 2); // expected-warning {{?: has lower precedence than /}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the / expression to silence this warning}}
+
+
+ (void)(x % 2 ? 1 : 2); // no warning
+}
+
// RUN: %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s
// CHECK: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]
-
diff --git a/test/Sema/parentheses.cpp b/test/Sema/parentheses.cpp
new file mode 100644
index 0000000..a25f2a0
--- /dev/null
+++ b/test/Sema/parentheses.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
+// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror -
+
+bool someConditionFunc();
+
+void conditional_op(int x, int y, bool b) {
+ (void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: has lower precedence than +}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the + expression to silence this warning}}
+
+ (void)(x - b ? 1 : 2); // expected-warning {{?: has lower precedence than -}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the - expression to silence this warning}}
+
+ (void)(x * (x == y) ? 1 : 2); // expected-warning {{?: has lower precedence than *}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the * expression to silence this warning}}
+}
+
+class Stream {
+public:
+ operator int();
+ Stream &operator<<(int);
+ Stream &operator<<(const char*);
+};
+
+void f(Stream& s, bool b) {
+ (void)(s << b ? "foo" : "bar"); // expected-warning {{?: has lower precedence than <<}} \
+ // expected-note {{place parentheses around the ?: expression to evaluate it first}} \
+ // expected-note {{place parentheses around the << expression to silence this warning}}
+}
diff --git a/test/Sema/stdcall-fastcall.c b/test/Sema/stdcall-fastcall.c
index 4531eb2..eeacf94 100644
--- a/test/Sema/stdcall-fastcall.c
+++ b/test/Sema/stdcall-fastcall.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-pc-linux-gnu %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-apple-darwin10 %s
// CC qualifier can be applied only to functions
int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies to function types; type here is 'int'}}
diff --git a/test/Sema/uninit-variables.c b/test/Sema/uninit-variables.c
index 60cae80..b70a295 100644
--- a/test/Sema/uninit-variables.c
+++ b/test/Sema/uninit-variables.c
@@ -339,3 +339,16 @@ int test51(void)
return a; // no-warning
}
+// FIXME: This is a false positive, but it tests logical operations in switch statements.
+int test52(int a, int b) {
+ int x; // expected-note {{variable 'x' is declared here}} expected-note {{add initialization to silence this warning}}
+ switch (a || b) { // expected-warning {{switch condition has boolean value}}
+ case 0:
+ x = 1;
+ break;
+ case 1:
+ x = 2;
+ break;
+ }
+ return x; // expected-warning {{variable 'x' may be uninitialized when used here}}
+}
diff --git a/test/Sema/x86-builtin-palignr.c b/test/Sema/x86-builtin-palignr.c
index 2344306..83719a3 100644
--- a/test/Sema/x86-builtin-palignr.c
+++ b/test/Sema/x86-builtin-palignr.c
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify %s
+// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify -triple x86_64-pc-linux-gnu %s
+// RUN: %clang_cc1 -ffreestanding -fsyntax-only -target-feature +ssse3 -verify -triple i686-apple-darwin10 %s
#include <tmmintrin.h>
OpenPOWER on IntegriCloud