On Sat, Aug 29, 2015 at 2:57 PM, Chen Gang <xili_gchen_5...@hotmail.com> wrote: > > It is about bug63510: current input_location isn't precise for reporting > warning. The correct location is gimple location of current statement.
Looks ok to me. Ok if bootstrapped and tested. Thanks, Richard. > ChangeLog: > > 2015-08-29 Chen Gang <gang.chen.5...@gmail.com> > > * fold-const.c (fold_overflow_warning): Call warning_at instead > of call warning. > * tree-ssa-sccvn.c (sccvn_dom_walker::before_dom_children): Call > fold_binary_loc instead of call fold_binary. > --- > gcc/fold-const.c | 91 > ++++++++++++++++++++++++++++++++-------------------- > gcc/tree-ssa-sccvn.c | 2 +- > 2 files changed, 58 insertions(+), 35 deletions(-) > > diff --git a/gcc/fold-const.c b/gcc/fold-const.c > index 1e01726..f22f070 100644 > --- a/gcc/fold-const.c > +++ b/gcc/fold-const.c > @@ -299,7 +299,8 @@ fold_deferring_overflow_warnings_p (void) > overflow is undefined. */ > > static void > -fold_overflow_warning (const char* gmsgid, enum warn_strict_overflow_code wc) > +fold_overflow_warning (location_t loc, const char* gmsgid, > + enum warn_strict_overflow_code wc) > { > if (fold_deferring_overflow_warnings> 0) > { > @@ -311,7 +312,8 @@ fold_overflow_warning (const char* gmsgid, enum > warn_strict_overflow_code wc) > } > } > else if (issue_strict_overflow_warning (wc)) > - warning (OPT_Wstrict_overflow, gmsgid); > + warning_at (loc == UNKNOWN_LOCATION ? input_location : loc, > + OPT_Wstrict_overflow, gmsgid); > } > > /* Return true if the built-in mathematical function specified by CODE > @@ -679,7 +681,7 @@ fold_negate_expr (location_t loc, tree t) > if (INTEGRAL_TYPE_P (type) > && (TREE_CODE (tem) != INTEGER_CST > || integer_onep (tem))) > - fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MISC); > + fold_overflow_warning (loc, warnmsg, > WARN_STRICT_OVERFLOW_MISC); > return fold_build2_loc (loc, TREE_CODE (t), type, > TREE_OPERAND (t, 0), negate_expr (tem)); > } > @@ -5143,7 +5145,7 @@ fold_range_test (location_t loc, enum tree_code code, > tree type, > in_p, low, high)))) > { > if (strict_overflow_p) > - fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); > + fold_overflow_warning (loc, warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); > return or_op ? invert_truthvalue_loc (loc, tem) : tem; > } > > @@ -5177,7 +5179,7 @@ fold_range_test (location_t loc, enum tree_code code, > tree type, > low1, high1)))) > { > if (strict_overflow_p) > - fold_overflow_warning (warnmsg, > + fold_overflow_warning (loc, warnmsg, > WARN_STRICT_OVERFLOW_COMPARISON); > return build2_loc (loc, code == TRUTH_ANDIF_EXPR > ? TRUTH_AND_EXPR : TRUTH_OR_EXPR, > @@ -8177,7 +8179,7 @@ maybe_canonicalize_comparison (location_t loc, enum > tree_code code, tree type, > if (t) > { > if (strict_overflow_p) > - fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); > + fold_overflow_warning (loc, warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); > return t; > } > > @@ -8188,7 +8190,7 @@ maybe_canonicalize_comparison (location_t loc, enum > tree_code code, tree type, > t = maybe_canonicalize_comparison_1 (loc, code, type, arg1, arg0, > &strict_overflow_p); > if (t && strict_overflow_p) > - fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); > + fold_overflow_warning (loc, warnmsg, WARN_STRICT_OVERFLOW_MAGNITUDE); > return t; > } > > @@ -8337,9 +8339,10 @@ fold_comparison (location_t loc, enum tree_code code, > tree type, > else > { > if (!equality_code) > - fold_overflow_warning ("assuming signed overflow does not occur " > - "when changing X +- C1 cmp C2 to " > - "X cmp C2 -+ C1", > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur " > + "when changing X +- C1 cmp C2 to " > + "X cmp C2 -+ C1"), > WARN_STRICT_OVERFLOW_COMPARISON); > return fold_build2_loc (loc, code, type, variable, new_const); > } > @@ -8452,7 +8455,8 @@ fold_comparison (location_t loc, enum tree_code code, > tree type, > && bitpos0 != bitpos1 > && (pointer_may_wrap_p (base0, offset0, bitpos0) > || pointer_may_wrap_p (base1, offset1, bitpos1))) > - fold_overflow_warning (("assuming pointer wraparound does not > " > + fold_overflow_warning (loc, > + ("assuming pointer wraparound does not > " > "occur when comparing P +- C1 with " > "P +- C2"), > WARN_STRICT_OVERFLOW_CONDITIONAL); > @@ -8503,7 +8507,8 @@ fold_comparison (location_t loc, enum tree_code code, > tree type, > if (!equality_code > && (pointer_may_wrap_p (base0, offset0, bitpos0) > || pointer_may_wrap_p (base1, offset1, bitpos1))) > - fold_overflow_warning (("assuming pointer wraparound does not > " > + fold_overflow_warning (loc, > + ("assuming pointer wraparound does not > " > "occur when comparing P +- C1 with " > "P +- C2"), > WARN_STRICT_OVERFLOW_COMPARISON); > @@ -8561,7 +8566,7 @@ fold_comparison (location_t loc, enum tree_code code, > tree type, > && tree_int_cst_compare (const2, cst) == tree_int_cst_sgn (const2) > && tree_int_cst_sgn (cst) == tree_int_cst_sgn (const2)) > { > - fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); > + fold_overflow_warning (loc, warnmsg, > WARN_STRICT_OVERFLOW_COMPARISON); > return fold_build2_loc (loc, code, type, > variable1, > fold_build2_loc (loc, TREE_CODE (arg1), > @@ -8576,7 +8581,7 @@ fold_comparison (location_t loc, enum tree_code code, > tree type, > && tree_int_cst_compare (const1, cst) == tree_int_cst_sgn (const1) > && tree_int_cst_sgn (cst) == tree_int_cst_sgn (const1)) > { > - fold_overflow_warning (warnmsg, WARN_STRICT_OVERFLOW_COMPARISON); > + fold_overflow_warning (loc, warnmsg, > WARN_STRICT_OVERFLOW_COMPARISON); > return fold_build2_loc (loc, code, type, > fold_build2_loc (loc, TREE_CODE (arg0), > TREE_TYPE (arg0), > @@ -9019,14 +9024,15 @@ tree_expr_nonzero_warnv_p (tree t, bool > *strict_overflow_p) > Handle warnings about undefined signed overflow. */ > > static bool > -tree_expr_nonzero_p (tree t) > +tree_expr_nonzero_p (location_t loc, tree t) > { > bool ret, strict_overflow_p; > > strict_overflow_p = false; > ret = tree_expr_nonzero_warnv_p (t, &strict_overflow_p); > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not occur when " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur when " > "determining that expression is always " > "non-zero"), > WARN_STRICT_OVERFLOW_MISC); > @@ -9866,7 +9872,8 @@ fold_binary_loc (location_t loc, > &strict_overflow_p))) > { > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not " > "occur when simplifying " > "multiplication"), > WARN_STRICT_OVERFLOW_MISC); > @@ -10474,7 +10481,8 @@ fold_binary_loc (location_t loc, > wi::exact_log2 (sval)); > > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not " > "occur when simplifying A / (B << > N)"), > WARN_STRICT_OVERFLOW_MISC); > > @@ -10500,7 +10508,8 @@ fold_binary_loc (location_t loc, > && negate_expr_p (arg1)) > { > if (INTEGRAL_TYPE_P (type)) > - fold_overflow_warning (("assuming signed overflow does not occur " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur " > "when distributing negation across " > "division"), > WARN_STRICT_OVERFLOW_MISC); > @@ -10515,7 +10524,8 @@ fold_binary_loc (location_t loc, > && negate_expr_p (arg0)) > { > if (INTEGRAL_TYPE_P (type)) > - fold_overflow_warning (("assuming signed overflow does not occur " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur " > "when distributing negation across " > "division"), > WARN_STRICT_OVERFLOW_MISC); > @@ -10544,7 +10554,8 @@ fold_binary_loc (location_t loc, > &strict_overflow_p))) > { > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not occur " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur " > "when simplifying division"), > WARN_STRICT_OVERFLOW_MISC); > return fold_convert_loc (loc, type, tem); > @@ -10562,7 +10573,8 @@ fold_binary_loc (location_t loc, > &strict_overflow_p))) > { > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not occur " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur " > "when simplifying modulus"), > WARN_STRICT_OVERFLOW_MISC); > return fold_convert_loc (loc, type, tem); > @@ -11091,7 +11103,7 @@ fold_binary_loc (location_t loc, > } > > if (integer_zerop (arg1) > - && tree_expr_nonzero_p (arg0)) > + && tree_expr_nonzero_p (loc, arg0)) > { > tree res = constant_boolean_node (code==NE_EXPR, type); > return omit_one_operand_loc (loc, type, res, arg0); > @@ -11291,7 +11303,8 @@ fold_binary_loc (location_t loc, > { > if (TREE_CODE (arg01) == INTEGER_CST > && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does not " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not " > "occur when assuming that (X - c)> X " > "is always false"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11305,7 +11318,8 @@ fold_binary_loc (location_t loc, > { > if (TREE_CODE (arg01) == INTEGER_CST > && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does not " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not " > "occur when assuming that " > "(X + c) < X is always false"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11320,7 +11334,8 @@ fold_binary_loc (location_t loc, > { > if (TREE_CODE (arg01) == INTEGER_CST > && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does not " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not " > "occur when assuming that " > "(X - c) <= X is always true"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11335,7 +11350,8 @@ fold_binary_loc (location_t loc, > { > if (TREE_CODE (arg01) == INTEGER_CST > && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does not " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not " > "occur when assuming that " > "(X + c)>= X is always true"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11350,7 +11366,8 @@ fold_binary_loc (location_t loc, > || (code0 == MINUS_EXPR && is_positive < 0))) > { > if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does " > + fold_overflow_warning (loc, > + ("assuming signed overflow does " > "not occur when assuming that " > "(X + c)> X is always true"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11362,7 +11379,8 @@ fold_binary_loc (location_t loc, > || (code0 == PLUS_EXPR && is_positive < 0))) > { > if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does " > + fold_overflow_warning (loc, > + ("assuming signed overflow does " > "not occur when assuming that " > "(X - c) < X is always true"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11375,7 +11393,8 @@ fold_binary_loc (location_t loc, > || (code0 == MINUS_EXPR && is_positive < 0))) > { > if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does " > + fold_overflow_warning (loc, > + ("assuming signed overflow does " > "not occur when assuming that " > "(X + c) <= X is always false"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11387,7 +11406,8 @@ fold_binary_loc (location_t loc, > || (code0 == PLUS_EXPR && is_positive < 0))) > { > if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg1))) > - fold_overflow_warning (("assuming signed overflow does " > + fold_overflow_warning (loc, > + ("assuming signed overflow does " > "not occur when assuming that " > "(X - c)>= X is always false"), > WARN_STRICT_OVERFLOW_ALL); > @@ -11423,7 +11443,8 @@ fold_binary_loc (location_t loc, > && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p)) > { > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not occur " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur " > "when simplifying comparison of " > "absolute value and zero"), > WARN_STRICT_OVERFLOW_CONDITIONAL); > @@ -11439,7 +11460,8 @@ fold_binary_loc (location_t loc, > && tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p)) > { > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not occur " > + fold_overflow_warning (loc, > + ("assuming signed overflow does not occur " > "when simplifying comparison of " > "absolute value and zero"), > WARN_STRICT_OVERFLOW_CONDITIONAL); > @@ -13455,7 +13477,8 @@ tree_expr_nonnegative_p (tree t) > strict_overflow_p = false; > ret = tree_expr_nonnegative_warnv_p (t, &strict_overflow_p); > if (strict_overflow_p) > - fold_overflow_warning (("assuming signed overflow does not occur when " > + fold_overflow_warning (input_location, > + ("assuming signed overflow does not occur when " > "determining that expression is always " > "non-negative"), > WARN_STRICT_OVERFLOW_MISC); > diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c > index aea6acc..71e5779 100644 > --- a/gcc/tree-ssa-sccvn.c > +++ b/gcc/tree-ssa-sccvn.c > @@ -4587,7 +4587,7 @@ sccvn_dom_walker::before_dom_children (basic_block bb) > lhs = vn_get_expr_for (lhs); > if (TREE_CODE (rhs) == SSA_NAME) > rhs = vn_get_expr_for (rhs); > - val = fold_binary (gimple_cond_code (stmt), > + val = fold_binary_loc (gimple_location (stmt), gimple_cond_code > (stmt), > boolean_type_node, lhs, rhs); > /* If that didn't simplify to a constant see if we have recorded > temporary expressions from taken edges. */ > -- > 1.9.3 > >