diff options
author | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 056abd2059c65a3e908193aeae16fad98017437c (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /test/Sema/outof-range-constant-compare.c | |
parent | cc73504950eb7b5dff2dded9bedd67bc36d64641 (diff) | |
download | FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.zip FreeBSD-src-056abd2059c65a3e908193aeae16fad98017437c.tar.gz |
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
http://llvm.org/svn/llvm-project/cfe/branches/release_32@168974
Diffstat (limited to 'test/Sema/outof-range-constant-compare.c')
-rw-r--r-- | test/Sema/outof-range-constant-compare.c | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/test/Sema/outof-range-constant-compare.c b/test/Sema/outof-range-constant-compare.c new file mode 100644 index 0000000..4b1637c --- /dev/null +++ b/test/Sema/outof-range-constant-compare.c @@ -0,0 +1,149 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s +// rdar://12202422 + +int value(void); + +int main() +{ + int a = value(); + if (a == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} + return 0; + + if (0x1234567812345678L == a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (0x1234567812345678L != a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (0x1234567812345678L < a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (0x1234567812345678L <= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (0x1234567812345678L > a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (0x1234567812345678L >= a) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a == 0x1234567812345678LL) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a == -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a < -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a > -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a <= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a >= -0x1234567812345678L) // expected-warning {{comparison of constant -1311768465173141112 with expression of type 'int' is always true}} + return 0; + + + if (a == 0x12345678L) // no warning + return 1; + + short s = value(); + if (s == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (s != 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (s < 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (s <= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (s > 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (s >= 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} + return 0; + + if (0x1234567812345678L == s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (0x1234567812345678L != s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (0x1234567812345678L < s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (0x1234567812345678L <= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (0x1234567812345678L > s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (0x1234567812345678L >= s) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'short' is always true}} + return 0; + long l = value(); + if (l == 0x1234567812345678L) + return 0; + if (l != 0x1234567812345678L) + return 0; + if (l < 0x1234567812345678L) + return 0; + if (l <= 0x1234567812345678L) + return 0; + if (l > 0x1234567812345678L) + return 0; + if (l >= 0x1234567812345678L) + return 0; + + if (0x1234567812345678L == l) + return 0; + if (0x1234567812345678L != l) + return 0; + if (0x1234567812345678L < l) + return 0; + if (0x1234567812345678L <= l) + return 0; + if (0x1234567812345678L > l) + return 0; + if (0x1234567812345678L >= l) + return 0; + + unsigned un = 0; + if (un == 0x0000000000000000L) + return 0; + if (un != 0x0000000000000000L) + return 0; + if (un < 0x0000000000000000L) + return 0; + if (un <= 0x0000000000000000L) + return 0; + if (un > 0x0000000000000000L) + return 0; + if (un >= 0x0000000000000000L) + return 0; + + if (0x0000000000000000L == un) + return 0; + if (0x0000000000000000L != un) + return 0; + if (0x0000000000000000L < un) + return 0; + if (0x0000000000000000L <= un) + return 0; + if (0x0000000000000000L > un) + return 0; + if (0x0000000000000000L >= un) + return 0; + float fl = 0; + if (fl == 0x0000000000000000L) // no warning + return 0; + + float dl = 0; + if (dl == 0x0000000000000000L) // no warning + return 0; + + enum E { + yes, + no, + maybe + }; + enum E e; + + if (e == 0x1234567812345678L) // expected-warning {{comparison of constant 1311768465173141112 with expression of type 'enum E' is always false}} + return 0; + + return 1; +} |