diff options
author | John McCall <rjmccall@apple.com> | 2010-11-09 22:22:12 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-11-09 22:22:12 +0000 |
commit | 091f23f1d6d4bcffd6641cda72a6831e08c02ea7 (patch) | |
tree | 68b3412e591456abb9639ef22cf2d705511b5db1 /test/Sema | |
parent | 73167ec561c1dc3f34cbca2287c83985cbf2bfdf (diff) |
Split out -Wconversion warnings about constant precision into their
own subcategory, -Wconstant-conversion, which is on by default.
Tweak the constant folder to give better results in the invalid
case of a negative shift amount.
Implements rdar://problem/6792488
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118636 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/constant-conversion.c | 9 | ||||
-rw-r--r-- | test/Sema/conversion.c | 32 |
2 files changed, 25 insertions, 16 deletions
diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c new file mode 100644 index 0000000000..cacd5968dc --- /dev/null +++ b/test/Sema/constant-conversion.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin %s + +// This file tests -Wconstant-conversion, a subcategory of -Wconversion +// which is on by default. + +// rdar://problem/6792488 +void test_6792488(void) { + int x = 0x3ff0000000000000U; // expected-warning {{implicit conversion from 'unsigned long' to 'int' changes value from 4607182418800017408 to 0}} +} diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c index 411ca32b5a..e78902332e 100644 --- a/test/Sema/conversion.c +++ b/test/Sema/conversion.c @@ -40,17 +40,17 @@ void test0(char c, short s, int i, long l, long long ll) { l = (long) 0; c = (char) BIG; - c = (short) BIG; // expected-warning {{implicit conversion loses integer precision}} - c = (int) BIG; // expected-warning {{implicit conversion loses integer precision}} - c = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + c = (short) BIG; // expected-warning {{implicit conversion from 'short' to 'char' changes value}} + c = (int) BIG; // expected-warning {{implicit conversion from 'int' to 'char' changes value}} + c = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'char' changes value}} s = (char) BIG; s = (short) BIG; - s = (int) BIG; // expected-warning {{implicit conversion loses integer precision}} - s = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + s = (int) BIG; // expected-warning {{implicit conversion from 'int' to 'short' changes value}} + s = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'short' changes value}} i = (char) BIG; i = (short) BIG; i = (int) BIG; - i = (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + i = (long) BIG; // expected-warning {{implicit conversion from 'long' to 'int' changes value}} l = (char) BIG; l = (short) BIG; l = (int) BIG; @@ -63,10 +63,10 @@ char test1(long long ll) { return (int) ll; // expected-warning {{implicit conversion loses integer precision}} return (short) ll; // expected-warning {{implicit conversion loses integer precision}} return (char) ll; - return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (int) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (short) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'char' changes value}} + return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'char' changes value}} + return (int) BIG; // expected-warning {{implicit conversion from 'int' to 'char' changes value}} + return (short) BIG; // expected-warning {{implicit conversion from 'short' to 'char' changes value}} return (char) BIG; } @@ -76,9 +76,9 @@ short test2(long long ll) { return (int) ll; // expected-warning {{implicit conversion loses integer precision}} return (short) ll; return (char) ll; - return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (int) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'short' changes value}} + return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'short' changes value}} + return (int) BIG; // expected-warning {{implicit conversion from 'int' to 'short' changes value}} return (short) BIG; return (char) BIG; } @@ -89,8 +89,8 @@ int test3(long long ll) { return (int) ll; return (short) ll; return (char) ll; - return (long long) BIG; // expected-warning {{implicit conversion loses integer precision}} - return (long) BIG; // expected-warning {{implicit conversion loses integer precision}} + return (long long) BIG; // expected-warning {{implicit conversion from 'long long' to 'int' changes value}} + return (long) BIG; // expected-warning {{implicit conversion from 'long' to 'int' changes value}} return (int) BIG; return (short) BIG; return (char) BIG; @@ -277,7 +277,7 @@ unsigned char test19(unsigned long u64) { // <rdar://problem/7631400> void test_7631400(void) { // This should show up despite the caret being inside a macro substitution - char s = LONG_MAX; // expected-warning {{implicit conversion loses integer precision: 'long' to 'char'}} + char s = LONG_MAX; // expected-warning {{implicit conversion from 'long' to 'char' changes value}} } // <rdar://problem/7676608>: assertion for compound operators with non-integral RHS |