aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@gcc.gnu.org>2008-09-23 14:55:14 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2008-09-23 14:55:14 +0000
commitba47d38d4c5d229c686e479fceb9ee9eb23442ff (patch)
tree21c7a88d82936ace208bcdd02d4ba68c691c6cf7 /gcc/c-common.c
parentf0ac18b79931a074b5bc88e0b64ea8ef84e40941 (diff)
downloadgcc-ba47d38d4c5d229c686e479fceb9ee9eb23442ff.zip
gcc-ba47d38d4c5d229c686e479fceb9ee9eb23442ff.tar.gz
gcc-ba47d38d4c5d229c686e479fceb9ee9eb23442ff.tar.bz2
c-tree.h: Add argument to c_objc_common_truthvalue_conversion, parser_build_binary_op.
* c-tree.h: Add argument to c_objc_common_truthvalue_conversion, parser_build_binary_op. * c-decl.c (build_enumerator): Pass location to build_binary_op. * c-typeck.c (build_array_ref): Same. (parser_build_unary_op): New location argument. (pointer_diff): Pass location to build_binary_op, c_objc_common_truthvalue_conversion. (build_modify_expr): Same. (build_unary_op): New location argument. (build_binary_op): New location argument. (c_objc_common_truthvalue_conversion): Pass location to c_*common_truthvalue_conversion. * c-convert.c (convert): Same. * c-common.c (binary_op_error): New location argument. (pointer_int_sum): Pass location to build_binary_op. (c_common_truthvalue_conversion): New location argument. (warn_for_sign_compare): Same. * c-common.h: Add location argument to c_common_truthvalue_conversion, binary_op_error, build_binary_op, warn_for_sign_compare. * c-parser.c (c_parser_condition): Pass location to c_*common_truthvalue_conversion. (c_parser_conditional_expression): Save condition's location and pass it on down. (c_parser_binary_expression): Same, but for the binary operator's location. (c_parser_omp_for_loop): Pass location to c_objc_common_truthvalue_conversion. objc/ * objc-act.c (next_sjlj_build_enter_and_setjmp): Call c_common_truthvalue_conversion with location. (next_sjlj_build_catch_list): Same. (next_sjlj_build_try_catch_finally): Same. testsuite/ * gcc.dg/Walways-true-1.c: Test column numbers. * gcc.dg/c90-const-expr-5.c: Same. * gcc.dg/compare4.c: Same. * gcc.dg/Werror-1.c: Same. cp/ * typeck.c (build_array_ref): Pass location to cp_build_binary_op. (get_member_function_from_ptrfunc): Same. (build_x_binary_op): Same. (build_binary_op): Same. (cp_build_binary_op): New location argument. (pointer_diff): Pass location to cp_build_binary_op. (cp_truthvalue_conversion): Pass location to build_binary_op. (convert_ptrmem): Pass location to cp_build_binary_op. (cp_build_modify_expr): Same. (build_ptrmemfunc): Same. * init.c (expand_cleanup_for_base): Pass location to c_common_truthvalue_conversion. (build_new_1): Pass location to cp_build_binary_op. (build_vec_delete_1): Pass location to *build_binary_op, c_common_truthvalue_conversion. (build_vec_init): Same. (build_delete): Same. * decl.c (compute_array_index_type): Same. * call.c (build_new_op): Same. * rtti.c (build_dynamic_cast_1): Same. * cp-tree.h: Add argument to cp_build_binary_op. * semantics.c (handle_omp_for_class_iterator): Pass location to *build_binary_op, c_common_truthvalue_conversion. * decl2.c (get_guard_cond): Same. From-SVN: r140598
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c101
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");
}
}