diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2010-02-19 21:12:09 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2010-02-19 21:12:09 +0000 |
commit | 58076e217c5cbc9f578ea687a67ca49053d06674 (patch) | |
tree | a8b8399751e464e4ec4287a9c9a0996327cc76f4 /gcc | |
parent | b42186f16474032ac2fa82027d3b7bf31e94daef (diff) | |
download | gcc-58076e217c5cbc9f578ea687a67ca49053d06674.zip gcc-58076e217c5cbc9f578ea687a67ca49053d06674.tar.gz gcc-58076e217c5cbc9f578ea687a67ca49053d06674.tar.bz2 |
re PR c++/41779 (Wconversion cannot see throught real*integer promotions)
2010-02-19 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR 41779
* c-common.c (conversion_warning): Remove widening conversions
before checking the conversion of integers to reals.
testsuite/
* c-c++-common/pr41779.c: New.
From-SVN: r156911
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-common.c | 17 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr41779.c | 31 |
4 files changed, 53 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e724239..f4a916b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-02-19 Manuel López-Ibáñez <manu@gcc.gnu.org> + + PR 41779 + * c-common.c (conversion_warning): Remove widening conversions + before checking the conversion of integers to reals. + 2010-02-19 Mike Stump <mikestump@comcast.net> PR objc/43061 diff --git a/gcc/c-common.c b/gcc/c-common.c index f9bdf38..1039e24 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2192,12 +2192,17 @@ conversion_warning (tree type, tree expr) else if (TREE_CODE (expr_type) == INTEGER_TYPE && TREE_CODE (type) == REAL_TYPE) { - tree type_low_bound = TYPE_MIN_VALUE (expr_type); - tree type_high_bound = TYPE_MAX_VALUE (expr_type); - REAL_VALUE_TYPE real_low_bound - = real_value_from_int_cst (0, type_low_bound); - REAL_VALUE_TYPE real_high_bound - = real_value_from_int_cst (0, type_high_bound); + tree type_low_bound, type_high_bound; + REAL_VALUE_TYPE real_low_bound, real_high_bound; + + /* Don't warn about char y = 0xff; float x = (int) y; */ + expr = get_unwidened (expr, 0); + expr_type = TREE_TYPE (expr); + + type_low_bound = TYPE_MIN_VALUE (expr_type); + type_high_bound = TYPE_MAX_VALUE (expr_type); + real_low_bound = real_value_from_int_cst (0, type_low_bound); + real_high_bound = real_value_from_int_cst (0, type_high_bound); if (!exact_real_truncate (TYPE_MODE (type), &real_low_bound) || !exact_real_truncate (TYPE_MODE (type), &real_high_bound)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 14b2ea4..f5863dc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-02-19 Manuel López-Ibáñez <manu@gcc.gnu.org> + + PR 41779 + * c-c++-common/pr41779.c: New. + 2010-02-19 Jakub Jelinek <jakub@redhat.com> PR debug/43084 diff --git a/gcc/testsuite/c-c++-common/pr41779.c b/gcc/testsuite/c-c++-common/pr41779.c new file mode 100644 index 0000000..f7153d9 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr41779.c @@ -0,0 +1,31 @@ +/* PR41779: Wconversion cannot see throught real*integer promotions. */ +/* { dg-do compile } */ +/* { dg-skip-if "doubles are floats" { "avr-*-*" } { "*" } { "" } } */ +/* { dg-options "-std=c99 -Wconversion" { target c } } */ +/* { dg-options "-Wconversion" { target c++ } } */ +/* { dg-require-effective-target large_double } */ + +float f(float x, unsigned short y) +{ + return x * y; +} + +float f(float x, short y) +{ + return x * y; +} + +float f(float x, char y) +{ + return x * y; +} + +float f(float x, unsigned char y) +{ + return x * y; +} + +float f(float x, int y) +{ + return x * y; /* { dg-warning "conversion" } */ +} |