public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR30465 duplicated overflow warning
@ 2007-01-17 17:16 Manuel López-Ibáñez
  0 siblings, 0 replies; only message in thread
From: Manuel López-Ibáñez @ 2007-01-17 17:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1019 bytes --]

:ADDPATCH c/c++:

The current rationale for overflow warnings is that we don't emit a
warning for the result of an operator is any of their operands has
TREE_OVERFLOW set, since we assume that an overflow warning has
already been given. This has been implemented for unary and binary
operators, however, it hasn't been followed for the conversion
operator. Hence, PR 30465.

If the expression to be converted has TREE_OVERFLOW set, we don't care
about giving any other warnings for an overflow in conversion since
the expression has already overflowed and a warning should have been
given already for this expression.

Bootstrapped and regression tested with --enable-languages=all on
i686-pc-linux-gnu.

OK for mainline?

2007-01-18  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/

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

[-- Attachment #2: multiple-overflow.diff --]
[-- Type: text/plain, Size: 3364 bytes --]

Index: gcc/testsuite/gcc.dg/multiple-overflow-warn-3.c
===================================================================
--- gcc/testsuite/gcc.dg/multiple-overflow-warn-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/multiple-overflow-warn-3.c	(revision 0)
@@ -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-warning "integer overflow in expression" } */
+  /* { dg-bogus "overflow in implicit constant conversion" "" { target *-*-* } 8 } */
+  return wc;
+}
+
Index: gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C
===================================================================
--- gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C	(revision 0)
@@ -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-warning "integer overflow in expression" } */
+  /* { dg-bogus "overflow in implicit constant conversion" "" { target *-*-* } 8 } */
+  return wc;
+}
+
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c	(revision 120783)
+++ gcc/c-common.c	(working copy)
@@ -1245,10 +1245,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)
@@ -1269,23 +1268,21 @@ 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)) 
+  else if (TREE_CODE (result) == INTEGER_CST && TREE_OVERFLOW (result))
     warning (OPT_Woverflow,
              "overflow in implicit constant conversion");
   else if (warn_conversion)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-01-17 17:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-17 17:16 PR30465 duplicated overflow warning Manuel López-Ibáñez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).