re PR c/2098 (compare with unsigned variable - no error reporting)
authorRichard Henderson <rth@redhat.com>
Fri, 26 Apr 2002 02:15:52 +0000 (19:15 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Fri, 26 Apr 2002 02:15:52 +0000 (19:15 -0700)
        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
gcc/c-common.c
gcc/testsuite/gcc.dg/compare6.c [new file with mode: 0644]

index 76182b9a144502b0d215aa7c06ef3bb67fb68f65..2813ca25792867929751143f98fd5e5468d69655 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-25  Richard Henderson  <rth@redhat.com>
+
+       PR c/2098
+       * c-common.c (shorten_compare): Simplfy conditions leading to
+       the generation of a warning.
+
 2002-04-25  Richard Henderson  <rth@redhat.com>
 
        PR c/2035
index 03966a87c25259e1e58506408386c5e1e989c128..f9337df907f298d5cbc198fcc1ece6d2f9ca0830 100644 (file)
@@ -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 (file)
index 0000000..fbeb6a0
--- /dev/null
@@ -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" } */
+}