re PR middle-end/7651 (Define -Wextra strictly in terms of other warning flags)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Sun, 20 May 2007 20:29:55 +0000 (20:29 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Sun, 20 May 2007 20:29:55 +0000 (20:29 +0000)
2007-05-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

PR middle-end/7651
PR c++/11856
PR c/12963
PR c/23587
PR other/29694
* c.opt (Wtype-limits): New.
* doc/invoke.texi (Wtype-limits): Document it.
(Wextra): Enabled by -Wextra.
* c-opts.c (c_common_post_options): Enabled by -Wextra.
* c-common.c (shorten_compare): Warn with Wtype-limits.

testsuite/
* gcc.dg/compare6.c: Replace Wall with Wtype-limits.
* gcc.dg/Wtype-limits.c: New.
* gcc.dg/Wtype-limits-Wextra.c: New.
* gcc.dg/Wtype-limits-no.c: New.
* g++.dg/warn/Wtype-limits.C: New.
* g++.dg/warn/Wtype-limits-Wextra.C: New.
* g++.dg/warn/Wtype-limits-no.C: New.

From-SVN: r124875

13 files changed:
gcc/ChangeLog
gcc/c-common.c
gcc/c-opts.c
gcc/c.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wtype-limits-no.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wtype-limits.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wtype-limits-Wextra.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wtype-limits-no.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wtype-limits.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/compare6.c

index d3d061f..41311d9 100644 (file)
@@ -1,3 +1,16 @@
+2007-05-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+       
+       PR middle-end/7651
+       PR c++/11856
+       PR c/12963
+       PR c/23587
+       PR other/29694
+       * c.opt (Wtype-limits): New.
+       * doc/invoke.texi (Wtype-limits): Document it.
+       (Wextra): Enabled by -Wextra.
+       * c-opts.c (c_common_post_options): Enabled by -Wextra.
+       * c-common.c (shorten_compare): Warn with Wtype-limits.
+
 2006-05-20  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/tmmintrin.h (_mm_alignr_epi32): Implement as always
index 1026499..3814bfd 100644 (file)
@@ -2517,9 +2517,9 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
       if (TREE_CODE (primop0) != INTEGER_CST)
        {
          if (val == truthvalue_false_node)
-           warning (0, "comparison is always false due to limited range of data type");
+           warning (OPT_Wtype_limits, "comparison is always false due to limited range of data type");
          if (val == truthvalue_true_node)
-           warning (0, "comparison is always true due to limited range of data type");
+           warning (OPT_Wtype_limits, "comparison is always true due to limited range of data type");
        }
 
       if (val != 0)
@@ -2589,24 +2589,26 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
          switch (code)
            {
            case GE_EXPR:
-             /* All unsigned values are >= 0, so we warn if extra warnings
-                are requested.  However, if OP0 is a constant that is
-                >= 0, the signedness of the comparison isn't an issue,
-                so suppress the warning.  */
-             if (extra_warnings && !in_system_header
+             /* All unsigned values are >= 0, so we warn.  However,
+                if OP0 is a constant that is >= 0, the signedness of
+                the comparison isn't an issue, so suppress the
+                warning.  */
+             if (warn_type_limits && !in_system_header
                  && !(TREE_CODE (primop0) == INTEGER_CST
                       && !TREE_OVERFLOW (convert (c_common_signed_type (type),
                                                   primop0))))
-               warning (0, "comparison of unsigned expression >= 0 is always true");
+               warning (OPT_Wtype_limits, 
+                        "comparison of unsigned expression >= 0 is always true");
              value = truthvalue_true_node;
              break;
 
            case LT_EXPR:
-             if (extra_warnings && !in_system_header
+             if (warn_type_limits && !in_system_header
                  && !(TREE_CODE (primop0) == INTEGER_CST
                       && !TREE_OVERFLOW (convert (c_common_signed_type (type),
                                                   primop0))))
-               warning (0, "comparison of unsigned expression < 0 is always false");
+               warning (OPT_Wtype_limits, 
+                        "comparison of unsigned expression < 0 is always false");
              value = truthvalue_false_node;
              break;
 
index 550059f..b11e671 100644 (file)
@@ -1059,10 +1059,13 @@ c_common_post_options (const char **pfilename)
   if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
     flag_exceptions = 1;
 
-  /* -Wextra implies -Wclobbered, -Wempty-body, -Wsign-compare, 
+  /* -Wextra implies -Wtype-limits, -Wclobbered, 
+     -Wempty-body, -Wsign-compare, 
      -Wmissing-field-initializers, -Wmissing-parameter-type
      -Wold-style-declaration, and -Woverride-init, 
      but not if explicitly overridden.  */
+  if (warn_type_limits == -1)
+    warn_type_limits = extra_warnings;
   if (warn_clobbered == -1)
     warn_clobbered = extra_warnings;
   if (warn_empty_body == -1)
index 0ef7693..63e2bda 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -124,6 +124,10 @@ Wall
 C ObjC C++ ObjC++ Warning
 Enable most warning messages
 
+Wtype-limits
+C ObjC C++ ObjC++ Var(warn_type_limits) Init(-1) Warning
+Warn if a comparison is always true or always false due to the limited range of the data type
+
 Wassign-intercept
 ObjC ObjC++ Var(warn_assign_intercept) Warning
 Warn whenever an Objective-C assignment is being intercepted by the garbage collector
index 7be8167..d8260ba 100644 (file)
@@ -224,7 +224,7 @@ Objective-C and Objective-C++ Dialects}.
 @item Warning Options
 @xref{Warning Options,,Options to Request or Suppress Warnings}.
 @gccoptlist{-fsyntax-only  -pedantic  -pedantic-errors @gol
--w  -Wextra  -Wall  -Waddress  -Waggregate-return -Warray-bounds @gol
+-w  -Wextra  -Wall  -Waddress  -Waggregate-return  -Warray-bounds @gol
 -Wno-attributes -Wc++-compat -Wc++0x-compat -Wcast-align  -Wcast-qual  @gol
 -Wchar-subscripts -Wclobbered  -Wcomment @gol
 -Wconversion  -Wcoverage-mismatch  -Wno-deprecated-declarations @gol
@@ -251,7 +251,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wstrict-aliasing -Wstrict-aliasing=n @gol
 -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
 -Wswitch  -Wswitch-default  -Wswitch-enum @gol
--Wsystem-headers  -Wtrigraphs  -Wundef  -Wuninitialized @gol
+-Wsystem-headers  -Wtrigraphs  -Wtype-limits  -Wundef  -Wuninitialized @gol
 -Wunknown-pragmas  -Wno-pragmas -Wunreachable-code @gol
 -Wunused  -Wunused-function  -Wunused-label  -Wunused-parameter @gol
 -Wunused-value  -Wunused-variable @gol
@@ -3134,7 +3134,11 @@ messages for these events:
 
 @itemize @bullet
 @item
-An unsigned value is compared against zero with @samp{<} or @samp{>=}.
+Warn if a comparison is always true or always false due to the limited
+range of the data type, but do not warn for constant expressions.  For
+example, warn if an unsigned variable is compared against zero with
+@samp{<} or @samp{>=}.  This warning can be independently controlled
+by @option{-Wtype-limits}.
 
 @item @r{(C only)}
 Storage-class specifiers like @code{static} are not the first things
@@ -3376,6 +3380,15 @@ convenience in calculations with @code{void *} pointers and pointers
 to functions.  In C++, warn also when an arithmetic operation involves
 @code{NULL}.  This warning is also enabled by @option{-pedantic}.
 
+@item -Wtype-limits
+@opindex Wtype-limits
+@opindex Wno-type-limits
+Warn if a comparison is always true or always false due to the limited
+range of the data type, but do not warn for constant expressions.  For
+example, warn if an unsigned variable is compared against zero with
+@samp{<} or @samp{>=}.  This warning is also enabled by
+@option{-Wextra}.
+
 @item -Wbad-function-cast @r{(C only)}
 @opindex Wbad-function-cast
 Warn whenever a function call is cast to a non-matching type.
index 0b7b2c0..db0a0d5 100644 (file)
@@ -1,3 +1,18 @@
+2007-05-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR middle-end/7651
+       PR c++/11856
+       PR c/12963
+       PR c/23587
+       PR other/29694
+       * gcc.dg/compare6.c: Replace Wall with Wtype-limits.
+       * gcc.dg/Wtype-limits.c: New.
+       * gcc.dg/Wtype-limits-Wextra.c: New.
+       * gcc.dg/Wtype-limits-no.c: New.
+       * g++.dg/warn/Wtype-limits.C: New.
+       * g++.dg/warn/Wtype-limits-Wextra.C: New.
+       * g++.dg/warn/Wtype-limits-no.C: New.
+
 2006-05-20  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.target/i386/sse-vect-types.c: Revert 'Use "-msse"
diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C b/gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C
new file mode 100644 (file)
index 0000000..9cbdbe5
--- /dev/null
@@ -0,0 +1,84 @@
+/* Test that -Wtype-limits is enabled by -Wextra.  */
+/* { dg-do compile } */
+/* { dg-options "-Wextra" } */
+extern void assert (int);
+
+void a (unsigned char x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (x <= 255) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if (255 >= x) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 16 } */
+    return;
+  if (255 >= (unsigned char) 1)
+    return;
+
+}
+
+void b (unsigned short x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+}
+
+void c (unsigned int x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (1U >= 0) return;
+  if (1U < 0) return;
+  if (0 <= 1U) return;
+  if (0 > 1U) return;
+}
+
+void d (unsigned long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+void e (unsigned long long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+int test (int x) 
+{
+  if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 61 } */
+    return 1;
+  else 
+    return 0;
+}
+
+template <typename Int, Int D>
+void f(Int x) {
+  assert(0 <= x and x <= D); // { dg-warning "comparison is always true due to limited range of data type" }
+}
+
+int ff(void) {
+  f<unsigned char, 2>(5);
+  f<signed char, 2>(5);
+}
+
+template <typename Int, Int D>
+void g(void) {
+  assert(0 <= D);
+}
+int gg(void) {
+  g<unsigned char, 2>();
+}
+
diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits-no.C b/gcc/testsuite/g++.dg/warn/Wtype-limits-no.C
new file mode 100644 (file)
index 0000000..5040e26
--- /dev/null
@@ -0,0 +1,84 @@
+/* Test disabling -Wtype-limits.  */
+/* { dg-do compile } */
+/* { dg-options "-Wextra -Wno-type-limits" } */
+extern void assert (int);
+
+void a (unsigned char x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+  if (x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" } */
+    return;
+  if (255 >= x) /* { dg-bogus "comparison is always true due to limited range of data type" } */
+    return;
+  if ((int)x <= 255) 
+    return;
+  if (255 >= (unsigned char) 1)
+    return;
+
+}
+
+void b (unsigned short x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+}
+
+void c (unsigned int x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (1U >= 0) return;
+  if (1U < 0) return;
+  if (0 <= 1U) return;
+  if (0 > 1U) return;
+}
+
+void d (unsigned long x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+}
+
+void e (unsigned long long x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+}
+
+int test (int x) 
+{
+  if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" } */
+    return 1;
+  else 
+    return 0;
+}
+
+template <typename Int, Int D>
+void f(Int x) {
+  assert(0 <= x and x <= D); // { dg-bogus "comparison is always true due to limited range of data type" }
+}
+
+int ff(void) {
+  f<unsigned char, 2>(5);
+  f<signed char, 2>(5);
+}
+
+template <typename Int, Int D>
+void g(void) {
+  assert(0 <= D);
+}
+int gg(void) {
+  g<unsigned char, 2>();
+}
+
diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits.C b/gcc/testsuite/g++.dg/warn/Wtype-limits.C
new file mode 100644 (file)
index 0000000..814c2a8
--- /dev/null
@@ -0,0 +1,84 @@
+/* { dg-do compile } */
+/* { dg-options "-Wtype-limits" } */
+
+extern void assert (int);
+
+void a (unsigned char x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (x <= 255) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if (255 >= x) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 16 } */
+    return;
+  if (255 >= (unsigned char) 1)
+    return;
+
+}
+
+void b (unsigned short x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+}
+
+void c (unsigned int x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (1U >= 0) return;
+  if (1U < 0) return;
+  if (0 <= 1U) return;
+  if (0 > 1U) return;
+}
+
+void d (unsigned long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+void e (unsigned long long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+int test (int x) 
+{
+  if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 61 } */
+    return 1;
+  else 
+    return 0;
+}
+
+template <typename Int, Int D>
+void f(Int x) {
+  assert(0 <= x and x <= D); // { dg-warning "comparison is always true due to limited range of data type" }
+}
+
+int ff(void) {
+  f<unsigned char, 2>(5);
+  f<signed char, 2>(5);
+}
+
+template <typename Int, Int D>
+void g(void) {
+  assert(0 <= D);
+}
+int gg(void) {
+  g<unsigned char, 2>();
+}
+
diff --git a/gcc/testsuite/gcc.dg/Wtype-limits-Wextra.c b/gcc/testsuite/gcc.dg/Wtype-limits-Wextra.c
new file mode 100644 (file)
index 0000000..ae13e73
--- /dev/null
@@ -0,0 +1,66 @@
+/* Test that -Wtype-limits is enabled by -Wextra */
+/* { dg-do compile } */
+/* { dg-options "-Wextra" } */
+
+
+void a (unsigned char x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (x <= 255) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if (255 >= x) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 16 } */
+    return;
+  if (255 >= (unsigned char) 1)
+    return;
+
+}
+
+void b (unsigned short x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+}
+
+void c (unsigned int x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (1U >= 0) return;
+  if (1U < 0) return;
+  if (0 <= 1U) return;
+  if (0 > 1U) return;
+}
+
+void d (unsigned long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+void e (unsigned long long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+int test (int x) 
+{
+  if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 61 } */
+    return 1;
+  else 
+    return 0;
+}
+
diff --git a/gcc/testsuite/gcc.dg/Wtype-limits-no.c b/gcc/testsuite/gcc.dg/Wtype-limits-no.c
new file mode 100644 (file)
index 0000000..2af909a
--- /dev/null
@@ -0,0 +1,66 @@
+/* Test disabling -Wtype-limits */
+/* { dg-do compile } */
+/* { dg-options "-Wextra -Wno-type-limits" } */
+
+
+void a (unsigned char x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+  if (x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" } */
+    return;
+  if (255 >= x) /* { dg-bogus "comparison is always true due to limited range of data type" } */
+    return;
+  if ((int)x <= 255)
+    return;
+  if (255 >= (unsigned char) 1)
+    return;
+
+}
+
+void b (unsigned short x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-bogus "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */
+}
+
+void c (unsigned int x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (1U >= 0) return;
+  if (1U < 0) return;
+  if (0 <= 1U) return;
+  if (0 > 1U) return;
+}
+
+void d (unsigned long x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+}
+
+void e (unsigned long long x)
+{
+  if (x < 0)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */
+}
+
+int test (int x) 
+{
+  if ((long long)x <= 0x123456789ABCLL) 
+    return 1;
+  else 
+    return 0;
+}
+
diff --git a/gcc/testsuite/gcc.dg/Wtype-limits.c b/gcc/testsuite/gcc.dg/Wtype-limits.c
new file mode 100644 (file)
index 0000000..64e7da6
--- /dev/null
@@ -0,0 +1,66 @@
+/* { dg-do compile } */
+/* { dg-options "-Wtype-limits" } */
+
+
+
+void a (unsigned char x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (x <= 255) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if (255 >= x) /* { dg-warning "comparison is always true due to limited range of data type" } */
+    return;
+  if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 16 } */
+    return;
+  if (255 >= (unsigned char) 1)
+    return;
+
+}
+
+void b (unsigned short x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+  if (0 > x)  return;/* { dg-warning "comparison is always false due to limited range of data type" } */
+  if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */
+}
+
+void c (unsigned int x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (1U >= 0) return;
+  if (1U < 0) return;
+  if (0 <= 1U) return;
+  if (0 > 1U) return;
+}
+
+void d (unsigned long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+void e (unsigned long long x)
+{
+  if (x < 0)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+  if (0 > x)  return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */
+  if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */
+}
+
+int test (int x) 
+{
+  if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 61 } */
+    return 1;
+  else 
+    return 0;
+}
+
index fbeb6a0..72f5020 100644 (file)
@@ -1,7 +1,7 @@
 /* PR c/2098 */
 /* Test for a warning on comparison on out-of-range data.  */
 /* { dg-do compile { xfail c4x-*-* } } */
-/* { dg-options "-Wall" } */
+/* { dg-options "-Wtype-limits" } */
 
 signed char sc;
 unsigned char uc;