From 091f23f1d6d4bcffd6641cda72a6831e08c02ea7 Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 9 Nov 2010 22:22:12 +0000 Subject: 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 --- test/Sema/constant-conversion.c | 9 +++++++++ test/Sema/conversion.c | 32 ++++++++++++++++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 test/Sema/constant-conversion.c (limited to 'test/Sema') 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) { // 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}} } // : assertion for compound operators with non-integral RHS -- cgit v1.2.3-18-g5258