diff options
author | pfg <pfg@FreeBSD.org> | 2013-11-29 05:00:07 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2013-11-29 05:00:07 +0000 |
commit | 63f3827317b31a63a94c299e699da69a2f2f4cd1 (patch) | |
tree | c33e092082060d26ec46bbeaf35839eef351f8ee /contrib/gcc | |
parent | 2ce888629fffc367fa06f9d12aff1820c724cfb5 (diff) | |
download | FreeBSD-src-63f3827317b31a63a94c299e699da69a2f2f4cd1.zip FreeBSD-src-63f3827317b31a63a94c299e699da69a2f2f4cd1.tar.gz |
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
Diffstat (limited to 'contrib/gcc')
-rw-r--r-- | contrib/gcc/ChangeLog.gcc43 | 10 | ||||
-rw-r--r-- | contrib/gcc/c-common.c | 56 | ||||
-rw-r--r-- | contrib/gcc/c-typeck.c | 15 | ||||
-rw-r--r-- | contrib/gcc/cp/ChangeLog.gcc43 | 6 | ||||
-rw-r--r-- | contrib/gcc/cp/semantics.c | 4 |
5 files changed, 59 insertions, 32 deletions
diff --git a/contrib/gcc/ChangeLog.gcc43 b/contrib/gcc/ChangeLog.gcc43 index a469234..43901d7 100644 --- a/contrib/gcc/ChangeLog.gcc43 +++ b/contrib/gcc/ChangeLog.gcc43 @@ -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 diff --git a/contrib/gcc/c-common.c b/contrib/gcc/c-common.c index 327dbcd..b650a48 100644 --- a/contrib/gcc/c-common.c +++ b/contrib/gcc/c-common.c @@ -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)) + if (skip_evaluation) return; + + switch (TREE_CODE (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; } } diff --git a/contrib/gcc/c-typeck.c b/contrib/gcc/c-typeck.c index 897c1e9..dd0fdc5 100644 --- a/contrib/gcc/c-typeck.c +++ b/contrib/gcc/c-typeck.c @@ -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) { diff --git a/contrib/gcc/cp/ChangeLog.gcc43 b/contrib/gcc/cp/ChangeLog.gcc43 index ed9c7b5..e232596 100644 --- a/contrib/gcc/cp/ChangeLog.gcc43 +++ b/contrib/gcc/cp/ChangeLog.gcc43 @@ -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. diff --git a/contrib/gcc/cp/semantics.c b/contrib/gcc/cp/semantics.c index ee16e75..547859b 100644 --- a/contrib/gcc/cp/semantics.c +++ b/contrib/gcc/cp/semantics.c @@ -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; } |