summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-01-06 05:24:50 +0000
committerJohn McCall <rjmccall@apple.com>2010-01-06 05:24:50 +0000
commit70aa5391dda1cedd296a126d42a909b8a1ee84a8 (patch)
tree9227a20b6199ef20a285f9d8d1c6220f362d707d /clang/test
parentd01472beee3f003bff7d6e69547d06f5b69f8b08 (diff)
downloadbcm5719-llvm-70aa5391dda1cedd296a126d42a909b8a1ee84a8.tar.gz
bcm5719-llvm-70aa5391dda1cedd296a126d42a909b8a1ee84a8.zip
Significantly rework the calculation of effective integer-expression ranges
for -Wsign-compare and -Wconversion, and use that coordinated logic to drive both diagnostics. The new logic works more transparently with implicit conversions, conditional operators, etc., as well as bringing -Wconversion's ability to deal with pseudo-closed operations (e.g. arithmetic on shorts) to -Wsign-compare. Fixes PRs 5887, 5937, 5938, and 5939. llvm-svn: 92823
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Sema/compare.c33
-rw-r--r--clang/test/Sema/conversion.c26
2 files changed, 59 insertions, 0 deletions
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index bacd47e33ce..a22e7216168 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -233,3 +233,36 @@ int test1(int i) {
enum en { zero };
return i > zero;
}
+
+// PR5937
+int test2(int i32) {
+ struct foo {
+ unsigned int u8 : 8;
+ unsigned long long u31 : 31;
+ unsigned long long u32 : 32;
+ unsigned long long u63 : 63;
+ unsigned long long u64 : 64;
+ } *x;
+
+ if (x->u8 == i32) { // comparison in int32, exact
+ return 0;
+ } else if (x->u31 == i32) { // comparison in int32, exact
+ return 1;
+ } else if (x->u32 == i32) { // expected-warning {{comparison of integers of different signs}}
+ return 2;
+ } else if (x->u63 == i32) { // comparison in uint64, exact because ==
+ return 3;
+ } else if (x->u64 == i32) { // expected-warning {{comparison of integers of different signs}}
+ return 4;
+ } else {
+ return 5;
+ }
+}
+
+// PR5887
+void test3() {
+ unsigned short x, y;
+ unsigned int z;
+ if ((x > y ? x : y) > z)
+ (void) 0;
+}
diff --git a/clang/test/Sema/conversion.c b/clang/test/Sema/conversion.c
index 264e0430dac..44b1224b52a 100644
--- a/clang/test/Sema/conversion.c
+++ b/clang/test/Sema/conversion.c
@@ -235,3 +235,29 @@ extern void *test16_external;
void test16(void) {
int a = (unsigned long) &test16_external; // expected-warning {{implicit cast loses integer precision}}
}
+
+// PR 5938
+void test17() {
+ union {
+ unsigned long long a : 8;
+ unsigned long long b : 32;
+ unsigned long long c;
+ } U;
+
+ unsigned int x;
+ x = U.a;
+ x = U.b;
+ x = U.c; // expected-warning {{implicit cast loses integer precision}}
+}
+
+// PR 5939
+void test18() {
+ union {
+ unsigned long long a : 1;
+ unsigned long long b;
+ } U;
+
+ int x;
+ x = (U.a ? 0 : 1);
+ x = (U.b ? 0 : 1);
+}
OpenPOWER on IntegriCloud