Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Dec 2013 02:39:11 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r259584 - in stable/10/contrib/gcc: . cp
Message-ID:  <201312190239.rBJ2dBnN092307@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pfg
Date: Thu Dec 19 02:39:11 2013
New Revision: 259584
URL: http://svnweb.freebsd.org/changeset/base/259584

Log:
  MFC	r258731:
  
  gcc: Make use of TREE_OVERFLOW_P.
  
  While it was brought in r258179 only to fix a build issue,
  bringing the rest of the change has the advantage of fixing
  GCC/19978.
  
  Obtained from:	gcc 4.3 (rev. 120505; GPLv2)

Modified:
  stable/10/contrib/gcc/ChangeLog.gcc43
  stable/10/contrib/gcc/c-common.c
  stable/10/contrib/gcc/c-typeck.c
  stable/10/contrib/gcc/cp/ChangeLog.gcc43
  stable/10/contrib/gcc/cp/semantics.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/contrib/gcc/ChangeLog.gcc43
==============================================================================
--- stable/10/contrib/gcc/ChangeLog.gcc43	Thu Dec 19 02:32:07 2013	(r259583)
+++ stable/10/contrib/gcc/ChangeLog.gcc43	Thu Dec 19 02:39:11 2013	(r259584)
@@ -348,6 +348,16 @@
 
 	* config.gcc: Support core2 processor.
 
+2007-01-05  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+	PR c/19978
+	* tree.h (TREE_OVERFLOW_P): New.
+	* c-typeck.c (parser_build_unary_op): Warn only if result
+	overflowed and operands did not.
+	(parser_build_binary_op): Likewise.
+	(convert_for_assignment): Remove redundant overflow_warning.
+	* c-common.c (overflow_warning): Don't check or set TREE_OVERFLOW.
+
 2006-12-13  Ian Lance Taylor  <iant@google.com> (r119855)
 
 	PR c++/19564

Modified: stable/10/contrib/gcc/c-common.c
==============================================================================
--- stable/10/contrib/gcc/c-common.c	Thu Dec 19 02:32:07 2013	(r259583)
+++ stable/10/contrib/gcc/c-common.c	Thu Dec 19 02:39:11 2013	(r259584)
@@ -916,39 +916,45 @@ constant_expression_warning (tree value)
     pedwarn ("overflow in constant expression");
 }
 
-/* Print a warning if an expression had overflow in folding.
+/* Print a warning if an expression had overflow in folding and its
+   operands hadn't.
+
    Invoke this function on every expression that
    (1) appears in the source code, and
-   (2) might be a constant expression that overflowed, and
+   (2) is a constant expression that overflowed, and
    (3) is not already checked by convert_and_check;
-   however, do not invoke this function on operands of explicit casts.  */
+   however, do not invoke this function on operands of explicit casts
+   or when the expression is the result of an operator and any operand
+   already overflowed.  */
 
 void
 overflow_warning (tree value)
 {
-  if ((TREE_CODE (value) == INTEGER_CST
-       || (TREE_CODE (value) == COMPLEX_CST
-	   && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST))
-      && TREE_OVERFLOW (value))
-    {
-      TREE_OVERFLOW (value) = 0;
-      if (skip_evaluation == 0)
-	warning (OPT_Woverflow, "integer overflow in expression");
-    }
-  else if ((TREE_CODE (value) == REAL_CST
-	    || (TREE_CODE (value) == COMPLEX_CST
-		&& TREE_CODE (TREE_REALPART (value)) == REAL_CST))
-	   && TREE_OVERFLOW (value))
-    {
-      TREE_OVERFLOW (value) = 0;
-      if (skip_evaluation == 0)
-	warning (OPT_Woverflow, "floating point overflow in expression");
-    }
-  else if (TREE_CODE (value) == VECTOR_CST && TREE_OVERFLOW (value))
-    {
-      TREE_OVERFLOW (value) = 0;
-      if (skip_evaluation == 0)
-	warning (OPT_Woverflow, "vector overflow in expression");
+  if (skip_evaluation) return;
+
+  switch (TREE_CODE (value))
+    {
+    case INTEGER_CST:
+      warning (OPT_Woverflow, "integer overflow in expression");
+      break;
+      
+    case REAL_CST:
+      warning (OPT_Woverflow, "floating point overflow in expression");
+      break;
+      
+    case VECTOR_CST:
+      warning (OPT_Woverflow, "vector overflow in expression");
+      break;
+      
+    case COMPLEX_CST:
+      if (TREE_CODE (TREE_REALPART (value)) == INTEGER_CST)
+	warning (OPT_Woverflow, "complex integer overflow in expression");
+      else if (TREE_CODE (TREE_REALPART (value)) == REAL_CST)
+	warning (OPT_Woverflow, "complex floating point overflow in expression");
+      break;
+
+    default:
+      break;
     }
 }
 

Modified: stable/10/contrib/gcc/c-typeck.c
==============================================================================
--- stable/10/contrib/gcc/c-typeck.c	Thu Dec 19 02:32:07 2013	(r259583)
+++ stable/10/contrib/gcc/c-typeck.c	Thu Dec 19 02:39:11 2013	(r259584)
@@ -2616,7 +2616,10 @@ parser_build_unary_op (enum tree_code co
 
   result.original_code = ERROR_MARK;
   result.value = build_unary_op (code, arg.value, 0);
-  overflow_warning (result.value);
+  
+  if (TREE_OVERFLOW_P (result.value) && !TREE_OVERFLOW_P (arg.value))
+    overflow_warning (result.value);
+
   return result;
 }
 
@@ -2660,7 +2663,10 @@ parser_build_binary_op (enum tree_code c
     warning (OPT_Waddress, 
              "comparison with string literal results in unspecified behaviour");
 
-  overflow_warning (result.value);
+  if (TREE_OVERFLOW_P (result.value) 
+      && !TREE_OVERFLOW_P (arg1.value) 
+      && !TREE_OVERFLOW_P (arg2.value))
+    overflow_warning (result.value);
 
   return result;
 }
@@ -3847,10 +3853,7 @@ convert_for_assignment (tree type, tree 
     }
 
   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
-    {
-      overflow_warning (rhs);
-      return rhs;
-    }
+    return rhs;
 
   if (coder == VOID_TYPE)
     {

Modified: stable/10/contrib/gcc/cp/ChangeLog.gcc43
==============================================================================
--- stable/10/contrib/gcc/cp/ChangeLog.gcc43	Thu Dec 19 02:32:07 2013	(r259583)
+++ stable/10/contrib/gcc/cp/ChangeLog.gcc43	Thu Dec 19 02:39:11 2013	(r259584)
@@ -20,6 +20,12 @@
 	TREE_OVERFLOW_P is true for the result and not for any of the
 	operands.
 	
+2007-01-05  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+	PR c/19978
+	* semantics.c (finish_unary_op_expr): Warn only if result
+	overflowed and operands did not.
+
 2006-10-31  Geoffrey Keating  <geoffk@apple.com> (r118360)
 
 	* name-lookup.c (get_anonymous_namespace_name): New.

Modified: stable/10/contrib/gcc/cp/semantics.c
==============================================================================
--- stable/10/contrib/gcc/cp/semantics.c	Thu Dec 19 02:32:07 2013	(r259583)
+++ stable/10/contrib/gcc/cp/semantics.c	Thu Dec 19 02:39:11 2013	(r259584)
@@ -2012,7 +2012,9 @@ finish_unary_op_expr (enum tree_code cod
       result = copy_node (result);
       TREE_NEGATED_INT (result) = 1;
     }
-  overflow_warning (result);
+  if (TREE_OVERFLOW_P (result) && !TREE_OVERFLOW_P (expr))
+    overflow_warning (result);
+
   return result;
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312190239.rBJ2dBnN092307>