aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-08-09 08:51:20 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-08-09 08:51:20 +0000
commita32c8316ff282ec3eb60e222e91fb19998c12f46 (patch)
tree5c9606b760b22332192173cec1c9c8ba76d9dcb4 /gcc/c
parentbc47a525cbd41692135f24607a52bd42e93400cb (diff)
downloadgcc-a32c8316ff282ec3eb60e222e91fb19998c12f46.zip
gcc-a32c8316ff282ec3eb60e222e91fb19998c12f46.tar.gz
gcc-a32c8316ff282ec3eb60e222e91fb19998c12f46.tar.bz2
re PR c/81417 (-Wsign-compare should print types being compared)
PR c/81417 * c-array-notation.c (fix_builtin_array_notation_fn): Update calls to build_conditional_expr. * c-parser.c (c_parser_conditional_expression): Create locations for EXP1 and EXP2 from their source ranges. Pass the locations down to build_conditional_expr. * c-tree.h (build_conditional_expr): Update declaration. * c-typeck.c (build_conditional_expr): Add location_t parameters. For -Wsign-compare, also print the types. * input.c (make_location): New overload. * input.h (make_location): Declare. * objc-next-runtime-abi-02.c (build_v2_build_objc_method_call): Update a call to build_conditional_expr. * Wsign-compare-1.c: New test. * gcc.dg/compare1.c: Adjust dg-bogus. * gcc.dg/compare2.c: Likewise. * gcc.dg/compare3.c: Likewise. * gcc.dg/compare7.c: Likewise. * gcc.dg/compare8.c: Likewise. * gcc.dg/compare9.c: Likewise. * gcc.dg/pr11492.c: Likewise. From-SVN: r250984
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog12
-rw-r--r--gcc/c/c-array-notation.c32
-rw-r--r--gcc/c/c-parser.c11
-rw-r--r--gcc/c/c-tree.h2
-rw-r--r--gcc/c/c-typeck.c18
5 files changed, 53 insertions, 22 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index d29f444..580cda0 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,15 @@
+2017-08-09 Marek Polacek <polacek@redhat.com>
+
+ PR c/81417
+ * c-array-notation.c (fix_builtin_array_notation_fn): Update calls to
+ build_conditional_expr.
+ * c-parser.c (c_parser_conditional_expression): Create locations for
+ EXP1 and EXP2 from their source ranges. Pass the locations down to
+ build_conditional_expr.
+ * c-tree.h (build_conditional_expr): Update declaration.
+ * c-typeck.c (build_conditional_expr): Add location_t parameters.
+ For -Wsign-compare, also print the types.
+
2017-08-08 Martin Liska <mliska@suse.cz>
* c-convert.c: Include header files.
diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c
index e430f5c..40f1cfda 100644
--- a/gcc/c/c-array-notation.c
+++ b/gcc/c/c-array-notation.c
@@ -355,8 +355,9 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
new_cond_expr = build2 (NE_EXPR, TREE_TYPE (func_parm), func_parm,
build_zero_cst (TREE_TYPE (func_parm)));
new_expr = build_conditional_expr
- (location, new_cond_expr, false, new_yes_expr,
- TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr));
+ (location, new_cond_expr, false,
+ new_yes_expr, TREE_TYPE (new_yes_expr), location,
+ new_no_expr, TREE_TYPE (new_no_expr), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE_ALL_NONZERO:
new_var_init = build_modify_expr
@@ -375,8 +376,9 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
new_cond_expr = build2 (EQ_EXPR, TREE_TYPE (func_parm), func_parm,
build_zero_cst (TREE_TYPE (func_parm)));
new_expr = build_conditional_expr
- (location, new_cond_expr, false, new_yes_expr,
- TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr));
+ (location, new_cond_expr, false,
+ new_yes_expr, TREE_TYPE (new_yes_expr), location,
+ new_no_expr, TREE_TYPE (new_no_expr), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_ZERO:
new_var_init = build_modify_expr
@@ -394,8 +396,9 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
new_cond_expr = build2 (EQ_EXPR, TREE_TYPE (func_parm), func_parm,
build_zero_cst (TREE_TYPE (func_parm)));
new_expr = build_conditional_expr
- (location, new_cond_expr, false, new_yes_expr,
- TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr));
+ (location, new_cond_expr, false,
+ new_yes_expr, TREE_TYPE (new_yes_expr), location,
+ new_no_expr, TREE_TYPE (new_no_expr), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE_ANY_NONZERO:
new_var_init = build_modify_expr
@@ -413,8 +416,9 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
new_cond_expr = build2 (NE_EXPR, TREE_TYPE (func_parm), func_parm,
build_zero_cst (TREE_TYPE (func_parm)));
new_expr = build_conditional_expr
- (location, new_cond_expr, false, new_yes_expr,
- TREE_TYPE (new_yes_expr), new_no_expr, TREE_TYPE (new_no_expr));
+ (location, new_cond_expr, false,
+ new_yes_expr, TREE_TYPE (new_yes_expr), location,
+ new_no_expr, TREE_TYPE (new_no_expr), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE_MAX:
if (TYPE_MIN_VALUE (new_var_type))
@@ -434,7 +438,8 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
new_expr = build_conditional_expr
(location,
build2 (LT_EXPR, TREE_TYPE (*new_var), *new_var, func_parm), false,
- new_yes_expr, TREE_TYPE (*new_var), new_no_expr, TREE_TYPE (*new_var));
+ new_yes_expr, TREE_TYPE (*new_var), location,
+ new_no_expr, TREE_TYPE (*new_var), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN:
if (TYPE_MAX_VALUE (new_var_type))
@@ -454,7 +459,8 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
new_expr = build_conditional_expr
(location,
build2 (GT_EXPR, TREE_TYPE (*new_var), *new_var, func_parm), false,
- new_yes_expr, TREE_TYPE (*new_var), new_no_expr, TREE_TYPE (*new_var));
+ new_yes_expr, TREE_TYPE (*new_var), location,
+ new_no_expr, TREE_TYPE (*new_var), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE_MAX_IND:
new_var_init = build_modify_expr
@@ -504,7 +510,8 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
build2 (LE_EXPR, TREE_TYPE (array_ind_value), array_ind_value,
func_parm),
false,
- new_yes_list, TREE_TYPE (*new_var), new_no_list, TREE_TYPE (*new_var));
+ new_yes_list, TREE_TYPE (*new_var), location,
+ new_no_list, TREE_TYPE (*new_var), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE_MIN_IND:
new_var_init = build_modify_expr
@@ -554,7 +561,8 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
build2 (GE_EXPR, TREE_TYPE (array_ind_value), array_ind_value,
func_parm),
false,
- new_yes_list, TREE_TYPE (*new_var), new_no_list, TREE_TYPE (*new_var));
+ new_yes_list, TREE_TYPE (*new_var), location,
+ new_no_list, TREE_TYPE (*new_var), location);
break;
case BUILT_IN_CILKPLUS_SEC_REDUCE:
new_var_init = build_modify_expr
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 606c07c..6d40a97 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -6511,7 +6511,7 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
tree omp_atomic_lhs)
{
struct c_expr cond, exp1, exp2, ret;
- location_t start, cond_loc, colon_loc, middle_loc;
+ location_t start, cond_loc, colon_loc;
gcc_assert (!after || c_dialect_objc ());
@@ -6530,7 +6530,7 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
{
tree eptype = NULL_TREE;
- middle_loc = c_parser_peek_token (parser)->location;
+ location_t middle_loc = c_parser_peek_token (parser)->location;
pedwarn (middle_loc, OPT_Wpedantic,
"ISO C forbids omitting the middle term of a ?: expression");
if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR)
@@ -6547,6 +6547,7 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
if (eptype)
exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
exp1.original_type = NULL;
+ exp1.src_range = cond.src_range;
cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
}
@@ -6578,10 +6579,12 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after,
exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true);
}
c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
+ location_t loc1 = make_location (exp1.get_start (), exp1.src_range);
+ location_t loc2 = make_location (exp2.get_start (), exp2.src_range);
ret.value = build_conditional_expr (colon_loc, cond.value,
cond.original_code == C_MAYBE_CONST_EXPR,
- exp1.value, exp1.original_type,
- exp2.value, exp2.original_type);
+ exp1.value, exp1.original_type, loc1,
+ exp2.value, exp2.original_type, loc2);
ret.original_code = ERROR_MARK;
if (exp1.value == error_mark_node || exp2.value == error_mark_node)
ret.original_type = NULL;
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index a8197eb..be2f272 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -644,7 +644,7 @@ extern struct c_expr parser_build_binary_op (location_t,
enum tree_code, struct c_expr,
struct c_expr);
extern tree build_conditional_expr (location_t, tree, bool, tree, tree,
- tree, tree);
+ location_t, tree, tree, location_t);
extern tree build_compound_expr (location_t, tree, tree);
extern tree c_cast_expr (location_t, struct c_type_name *, tree);
extern tree build_c_cast (location_t, tree, tree);
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 321c953..8033a81 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -4865,8 +4865,8 @@ ep_convert_and_check (location_t loc, tree type, tree expr,
tree
build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
- tree op1, tree op1_original_type, tree op2,
- tree op2_original_type)
+ tree op1, tree op1_original_type, location_t op1_loc,
+ tree op2, tree op2_original_type, location_t op2_loc)
{
tree type1;
tree type2;
@@ -5031,10 +5031,18 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
|| (unsigned_op1
&& tree_expr_nonnegative_warnv_p (op2, &ovf)))
/* OK */;
+ else if (unsigned_op2)
+ warning_at (op1_loc, OPT_Wsign_compare,
+ "operand of ?: changes signedness from "
+ "%qT to %qT due to unsignedness of other "
+ "operand", TREE_TYPE (orig_op1),
+ TREE_TYPE (orig_op2));
else
- warning_at (colon_loc, OPT_Wsign_compare,
- ("signed and unsigned type in "
- "conditional expression"));
+ warning_at (op2_loc, OPT_Wsign_compare,
+ "operand of ?: changes signedness from "
+ "%qT to %qT due to unsignedness of other "
+ "operand", TREE_TYPE (orig_op2),
+ TREE_TYPE (orig_op1));
}
if (!op1_maybe_const || TREE_CODE (op1) != INTEGER_CST)
op1 = c_wrap_maybe_const (op1, !op1_maybe_const);