diff options
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 101 |
1 files changed, 65 insertions, 36 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index a810bea..09027ba 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2849,10 +2849,12 @@ min_precision (tree value, int unsignedp) } /* Print an error message for invalid operands to arith operation - CODE with TYPE0 for operand 0, and TYPE1 for operand 1. */ + CODE with TYPE0 for operand 0, and TYPE1 for operand 1. + LOCATION is the location of the message. */ void -binary_op_error (enum tree_code code, tree type0, tree type1) +binary_op_error (location_t location, enum tree_code code, + tree type0, tree type1) { const char *opname; @@ -2903,8 +2905,9 @@ binary_op_error (enum tree_code code, tree type0, tree type1) default: gcc_unreachable (); } - error ("invalid operands to binary %s (have %qT and %qT)", opname, - type0, type1); + error_at (location, + "invalid operands to binary %s (have %qT and %qT)", opname, + type0, type1); } /* Subroutine of build_binary_op, used for comparison operations. @@ -3320,7 +3323,8 @@ pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop) /* Convert both subexpression types to the type of intop, because weird cases involving pointer arithmetic can result in a sum or difference with different type args. */ - ptrop = build_binary_op (subcode, ptrop, + ptrop = build_binary_op (EXPR_LOCATION (TREE_OPERAND (intop, 1)), + subcode, ptrop, convert (int_type, TREE_OPERAND (intop, 1)), 1); intop = convert (int_type, TREE_OPERAND (intop, 0)); } @@ -3336,7 +3340,8 @@ pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop) Do this multiplication as signed, then convert to the appropriate type for the pointer operation. */ intop = convert (sizetype, - build_binary_op (MULT_EXPR, intop, + build_binary_op (EXPR_LOCATION (intop), + MULT_EXPR, intop, convert (TREE_TYPE (intop), size_exp), 1)); /* Create the sum or difference. */ @@ -3367,6 +3372,8 @@ decl_with_nonnull_addr_p (const_tree expr) have been validated to be of suitable type; otherwise, a bad diagnostic may result. + The EXPR is located at LOCATION. + This preparation consists of taking the ordinary representation of an expression expr and producing a valid tree boolean expression describing whether expr is nonzero. We could @@ -3376,7 +3383,7 @@ decl_with_nonnull_addr_p (const_tree expr) The resulting type should always be `truthvalue_type_node'. */ tree -c_common_truthvalue_conversion (tree expr) +c_common_truthvalue_conversion (location_t location, tree expr) { switch (TREE_CODE (expr)) { @@ -3397,14 +3404,17 @@ c_common_truthvalue_conversion (tree expr) if (TREE_TYPE (expr) == truthvalue_type_node) return expr; return build2 (TREE_CODE (expr), truthvalue_type_node, - c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)), - c_common_truthvalue_conversion (TREE_OPERAND (expr, 1))); + c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 0)), + c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 1))); case TRUTH_NOT_EXPR: if (TREE_TYPE (expr) == truthvalue_type_node) return expr; return build1 (TREE_CODE (expr), truthvalue_type_node, - c_common_truthvalue_conversion (TREE_OPERAND (expr, 0))); + c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 0))); case ERROR_MARK: return expr; @@ -3434,9 +3444,10 @@ c_common_truthvalue_conversion (tree expr) if (decl_with_nonnull_addr_p (inner)) { /* Common Ada/Pascal programmer's mistake. */ - warning (OPT_Waddress, - "the address of %qD will always evaluate as %<true%>", - inner); + warning_at (location, + OPT_Waddress, + "the address of %qD will always evaluate as %<true%>", + inner); return truthvalue_true_node; } @@ -3456,17 +3467,20 @@ c_common_truthvalue_conversion (tree expr) } case COMPLEX_EXPR: - return build_binary_op ((TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) + return build_binary_op (EXPR_LOCATION (expr), + (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1)) ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), - c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)), - c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)), + c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 0)), + c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 1)), 0); case NEGATE_EXPR: case ABS_EXPR: case FLOAT_EXPR: /* These don't change whether an object is nonzero or zero. */ - return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)); + return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0)); case LROTATE_EXPR: case RROTATE_EXPR: @@ -3475,16 +3489,20 @@ c_common_truthvalue_conversion (tree expr) if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr, 1))) return build2 (COMPOUND_EXPR, truthvalue_type_node, TREE_OPERAND (expr, 1), - c_common_truthvalue_conversion (TREE_OPERAND (expr, 0))); + c_common_truthvalue_conversion + (location, TREE_OPERAND (expr, 0))); else - return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)); + return c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 0)); case COND_EXPR: /* Distribute the conversion into the arms of a COND_EXPR. */ return fold_build3 (COND_EXPR, truthvalue_type_node, TREE_OPERAND (expr, 0), - c_common_truthvalue_conversion (TREE_OPERAND (expr, 1)), - c_common_truthvalue_conversion (TREE_OPERAND (expr, 2))); + c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 1)), + c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 2))); CASE_CONVERT: /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE, @@ -3495,7 +3513,8 @@ c_common_truthvalue_conversion (tree expr) /* If this is widening the argument, we can ignore it. */ if (TYPE_PRECISION (TREE_TYPE (expr)) >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr, 0)))) - return c_common_truthvalue_conversion (TREE_OPERAND (expr, 0)); + return c_common_truthvalue_conversion (location, + TREE_OPERAND (expr, 0)); break; case MODIFY_EXPR: @@ -3516,10 +3535,13 @@ c_common_truthvalue_conversion (tree expr) { tree t = save_expr (expr); return (build_binary_op - ((TREE_SIDE_EFFECTS (expr) + (EXPR_LOCATION (expr), + (TREE_SIDE_EFFECTS (expr) ? TRUTH_OR_EXPR : TRUTH_ORIF_EXPR), - c_common_truthvalue_conversion (build_unary_op (REALPART_EXPR, t, 0)), - c_common_truthvalue_conversion (build_unary_op (IMAGPART_EXPR, t, 0)), + c_common_truthvalue_conversion (location, + build_unary_op (REALPART_EXPR, t, 0)), + c_common_truthvalue_conversion (location, + build_unary_op (IMAGPART_EXPR, t, 0)), 0)); } @@ -3528,10 +3550,12 @@ c_common_truthvalue_conversion (tree expr) tree fixed_zero_node = build_fixed (TREE_TYPE (expr), FCONST0 (TYPE_MODE (TREE_TYPE (expr)))); - return build_binary_op (NE_EXPR, expr, fixed_zero_node, 1); + return build_binary_op (EXPR_LOCATION (expr), + NE_EXPR, expr, fixed_zero_node, 1); } - return build_binary_op (NE_EXPR, expr, integer_zero_node, 1); + return build_binary_op (EXPR_LOCATION (expr), + NE_EXPR, expr, integer_zero_node, 1); } static void def_builtin_1 (enum built_in_function fncode, @@ -8198,13 +8222,16 @@ warn_for_div_by_zero (tree divisor) between signed and unsigned quantities that may fail. Do the checking based on the original operand trees ORIG_OP0 and ORIG_OP1, so that casts will be considered, but default promotions won't - be. + be. + + LOCATION is the location of the comparison operator. The arguments of this function map directly to local variables of build_binary_op. */ void -warn_for_sign_compare (tree orig_op0, tree orig_op1, +warn_for_sign_compare (location_t location, + tree orig_op0, tree orig_op1, tree op0, tree op1, tree result_type, enum tree_code resultcode) { @@ -8219,8 +8246,9 @@ warn_for_sign_compare (tree orig_op0, tree orig_op1, && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0)) != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1))) { - warning (OPT_Wsign_compare, "comparison between types %qT and %qT", - TREE_TYPE (orig_op0), TREE_TYPE (orig_op1)); + warning_at (location, + OPT_Wsign_compare, "comparison between types %qT and %qT", + TREE_TYPE (orig_op0), TREE_TYPE (orig_op1)); } /* Do not warn if the comparison is being done in a signed type, @@ -8266,8 +8294,9 @@ warn_for_sign_compare (tree orig_op0, tree orig_op1, c_common_signed_type (result_type))) /* OK */; else - warning (OPT_Wsign_compare, - "comparison between signed and unsigned integer expressions"); + warning_at (location, + OPT_Wsign_compare, + "comparison between signed and unsigned integer expressions"); } /* Warn if two unsigned values are being compared in a size larger @@ -8320,8 +8349,8 @@ warn_for_sign_compare (tree orig_op0, tree orig_op1, warning (OPT_Wsign_compare, "promoted ~unsigned is always non-zero"); else - warning (OPT_Wsign_compare, - "comparison of promoted ~unsigned with constant"); + warning_at (location, OPT_Wsign_compare, + "comparison of promoted ~unsigned with constant"); } } } @@ -8330,7 +8359,7 @@ warn_for_sign_compare (tree orig_op0, tree orig_op1, < TYPE_PRECISION (result_type)) && (TYPE_PRECISION (TREE_TYPE (op1)) < TYPE_PRECISION (result_type))) - warning (OPT_Wsign_compare, + warning_at (location, OPT_Wsign_compare, "comparison of promoted ~unsigned with unsigned"); } } |