re PR other/30465 (Duplicated overflow warning)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Sun, 4 Mar 2007 23:29:41 +0000 (23:29 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Sun, 4 Mar 2007 23:29:41 +0000 (23:29 +0000)
2007-03-04  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

PR other/30465
* c-common.c (convert_and_check): Don't give warnings for
conversion if 'expr' already overflowed.

testsuite/
* gcc.dg/multiple-overflow-warn-3.c: New.
* g++.dg/warn/multiple-overflow-warn-3.C: New.

From-SVN: r122534

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/multiple-overflow-warn-3.c [new file with mode: 0644]

index 2646f347f16469c9892601b367e6277c6559a8af..47b83c869a3530d5cd358bc3e8d55026835f8844 100644 (file)
@@ -1,3 +1,9 @@
+2007-03-04  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR other/30465
+       * c-common.c (convert_and_check): Don't give warnings for
+       conversion if 'expr' already overflowed.
+       
 2007-03-04  Roger Sayle  <roger@eyesopen.com>
 
        PR middle-end/30744
index 6ea3800be8db98cdc6848cf2146c873440f1516d..523ef464be565f20fbf8dec5f5d745930073effd 100644 (file)
@@ -1250,10 +1250,9 @@ convert_and_check (tree type, tree expr)
   
   result = convert (type, expr);
 
-  if (skip_evaluation)
+  if (skip_evaluation || TREE_OVERFLOW_P (expr))
     return result;
 
-
   if (TREE_CODE (expr) == INTEGER_CST
       && (TREE_CODE (type) == INTEGER_TYPE
           || TREE_CODE (type) == ENUMERAL_TYPE)
@@ -1274,21 +1273,19 @@ convert_and_check (tree type, tree expr)
           else if (warn_conversion)
             conversion_warning (type, expr);
         }
-      else
-        {
-          if (!int_fits_type_p (expr, c_common_unsigned_type (type)))
-            warning (OPT_Woverflow,
-                     "overflow in implicit constant conversion");
-          /* No warning for converting 0x80000000 to int.  */
-          else if (pedantic
-                   && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE
-                       || TYPE_PRECISION (TREE_TYPE (expr))
-                       != TYPE_PRECISION (type)))
-            warning (OPT_Woverflow,
-                     "overflow in implicit constant conversion");
-          else if (warn_conversion)
-            conversion_warning (type, expr);
-        }
+      else if (!int_fits_type_p (expr, c_common_unsigned_type (type))) 
+       warning (OPT_Woverflow,
+                "overflow in implicit constant conversion");
+      /* No warning for converting 0x80000000 to int.  */
+      else if (pedantic
+              && (TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE
+                  || TYPE_PRECISION (TREE_TYPE (expr))
+                  != TYPE_PRECISION (type)))
+       warning (OPT_Woverflow,
+                "overflow in implicit constant conversion");
+
+      else if (warn_conversion)
+       conversion_warning (type, expr);
     }
   else if (TREE_CODE (result) == INTEGER_CST && TREE_OVERFLOW (result)) 
     warning (OPT_Woverflow,
index 258f2f2cfa0c5d31c50604ef9c73e7656985d430..84c2d21496510c625e5ccf02f0d26db45f79c32c 100644 (file)
@@ -1,3 +1,9 @@
+2007-03-04  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR other/30465
+       * gcc.dg/multiple-overflow-warn-3.c: New.
+       * g++.dg/warn/multiple-overflow-warn-3.C: New.
+       
 2007-03-04  Simon Martin  <simartin@users.sourceforge.net>
 
        PR c++/30895
diff --git a/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C b/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C
new file mode 100644 (file)
index 0000000..491f7af
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR 30465 : Test for duplicated warnings in a conversion.  */
+/* { dg-do compile } */
+/* { dg-options "-Woverflow" } */
+
+wchar_t
+g (void)
+{
+  wchar_t wc = ((wchar_t)1 << 31) - 1; /* { dg-bogus "overflow .* overflow" } */
+  /* { dg-warning "overflow" "" { target *-*-* } 8 } */
+  return wc;
+}
+
diff --git a/gcc/testsuite/gcc.dg/multiple-overflow-warn-3.c b/gcc/testsuite/gcc.dg/multiple-overflow-warn-3.c
new file mode 100644 (file)
index 0000000..afb4e51
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR 30465 : Test for duplicated warnings in a conversion.  */
+/* { dg-do compile } */
+/* { dg-options "-Woverflow" } */
+
+short int
+g (void)
+{
+  short int wc = ((short int)1 << 31) - 1; /* { dg-bogus "overflow .* overflow" } */
+  /* { dg-warning "overflow" "" { target *-*-* } 8 } */
+  return wc;
+}
+