From 5c5b22838958187f83bf60d0394cc06942796646 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 25 Apr 2002 19:15:52 -0700 Subject: [PATCH] re PR c/2098 (compare with unsigned variable - no error reporting) PR c/2098 * c-common.c (shorten_compare): Simplfy conditions leading to the generation of a warning. * gcc.dg/compare6.c: New. From-SVN: r52778 --- gcc/ChangeLog | 6 ++++++ gcc/c-common.c | 13 +------------ gcc/testsuite/gcc.dg/compare6.c | 13 +++++++++++++ 3 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/compare6.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 76182b9a144..2813ca25792 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2002-04-25 Richard Henderson + + PR c/2098 + * c-common.c (shorten_compare): Simplfy conditions leading to + the generation of a warning. + 2002-04-25 Richard Henderson PR c/2035 diff --git a/gcc/c-common.c b/gcc/c-common.c index 03966a87c25..f9337df907f 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1999,19 +1999,8 @@ shorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr) type = c_common_unsigned_type (type); } - if (!max_gt && !unsignedp0 && TREE_CODE (primop0) != INTEGER_CST) + if (TREE_CODE (primop0) != INTEGER_CST) { - /* This is the case of (char)x >?< 0x80, which people used to use - expecting old C compilers to change the 0x80 into -0x80. */ - if (val == boolean_false_node) - warning ("comparison is always false due to limited range of data type"); - if (val == boolean_true_node) - warning ("comparison is always true due to limited range of data type"); - } - - if (!min_lt && unsignedp0 && TREE_CODE (primop0) != INTEGER_CST) - { - /* This is the case of (unsigned char)x >?< -1 or < 0. */ if (val == boolean_false_node) warning ("comparison is always false due to limited range of data type"); if (val == boolean_true_node) diff --git a/gcc/testsuite/gcc.dg/compare6.c b/gcc/testsuite/gcc.dg/compare6.c new file mode 100644 index 00000000000..fbeb6a0aedd --- /dev/null +++ b/gcc/testsuite/gcc.dg/compare6.c @@ -0,0 +1,13 @@ +/* PR c/2098 */ +/* Test for a warning on comparison on out-of-range data. */ +/* { dg-do compile { xfail c4x-*-* } } */ +/* { dg-options "-Wall" } */ + +signed char sc; +unsigned char uc; + +void foo() +{ + if (sc == 10000) return; /* { dg-warning "always false" "signed" } */ + if (uc == 10000) return; /* { dg-warning "always false" "unsigned" } */ +} -- 2.30.2