Commit c4438114 by Jason Merrill Committed by Jason Merrill

Handle location wrappers better in warn_logical_operator.

When we introduced location wrappers, we added fold_for_warn to warnings
that are interested in a constant value, or wrapper-stripping to warnings
that are interested in literal constants.  This particular warning is
looking for a literal constant, but was wrongly changed to use
fold_for_warn; this patch makes it strip instead.

	* c-warn.c (warn_logical_operator): Strip location wrappers.  Don't
	fold_for_warn in "|| mask" warning.

From-SVN: r275743
parent 27e0979b
2019-09-15 Jason Merrill <jason@redhat.com>
* c-warn.c (warn_logical_operator): Strip location wrappers. Don't
fold_for_warn in "|| mask" warning.
2019-09-10 Martin Liska <mliska@suse.cz> 2019-09-10 Martin Liska <mliska@suse.cz>
* c.opt: Use newly added WarnRemoved. * c.opt: Use newly added WarnRemoved.
......
...@@ -208,18 +208,19 @@ warn_logical_operator (location_t location, enum tree_code code, tree type, ...@@ -208,18 +208,19 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
programmer. That is, an expression such as op && MASK programmer. That is, an expression such as op && MASK
where op should not be any boolean expression, nor a where op should not be any boolean expression, nor a
constant, and mask seems to be a non-boolean integer constant. */ constant, and mask seems to be a non-boolean integer constant. */
STRIP_ANY_LOCATION_WRAPPER (op_right);
if (TREE_CODE (op_right) == CONST_DECL) if (TREE_CODE (op_right) == CONST_DECL)
/* An enumerator counts as a constant. */ /* An enumerator counts as a constant. */
op_right = DECL_INITIAL (op_right); op_right = DECL_INITIAL (op_right);
tree stripped_op_left = tree_strip_any_location_wrapper (op_left);
if (!truth_value_p (code_left) if (!truth_value_p (code_left)
&& INTEGRAL_TYPE_P (TREE_TYPE (op_left)) && INTEGRAL_TYPE_P (TREE_TYPE (op_left))
&& !CONSTANT_CLASS_P (op_left) && !CONSTANT_CLASS_P (stripped_op_left)
&& !TREE_NO_WARNING (op_left)) && TREE_CODE (stripped_op_left) != CONST_DECL
{ && !TREE_NO_WARNING (op_left)
tree folded_op_right = fold_for_warn (op_right); && TREE_CODE (op_right) == INTEGER_CST
if (TREE_CODE (folded_op_right) == INTEGER_CST && !integer_zerop (op_right)
&& !integer_zerop (folded_op_right) && !integer_onep (op_right))
&& !integer_onep (folded_op_right))
{ {
bool warned; bool warned;
if (or_op) if (or_op)
...@@ -234,7 +235,6 @@ warn_logical_operator (location_t location, enum tree_code code, tree type, ...@@ -234,7 +235,6 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
TREE_NO_WARNING (op_left) = true; TREE_NO_WARNING (op_left) = true;
return; return;
} }
}
/* We do not warn for constants because they are typical of macro /* We do not warn for constants because they are typical of macro
expansions that test for features. */ expansions that test for features. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment