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)
MFC after:	1 week
This commit is contained in:
Pedro F. Giffuni 2013-11-29 05:00:07 +00:00
parent 41166e501a
commit 9a252f0990
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=258731
5 changed files with 59 additions and 32 deletions

View file

@ -340,6 +340,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

View file

@ -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))
if (skip_evaluation) return;
switch (TREE_CODE (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");
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;
}
}

View file

@ -2616,7 +2616,10 @@ parser_build_unary_op (enum tree_code code, struct c_expr arg)
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 code, struct c_expr arg1,
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 rhs, enum impl_conv errtype,
}
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
{
overflow_warning (rhs);
return rhs;
}
return rhs;
if (coder == VOID_TYPE)
{

View file

@ -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.

View file

@ -2012,7 +2012,9 @@ finish_unary_op_expr (enum tree_code code, tree expr)
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;
}