public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH 1/4] Handle location wrappers better in warn_logical_operator.
@ 2019-09-16  4:33 Jason Merrill
  2019-09-16  4:33 ` [C++ PATCH 4/4] PR c++/30277 - int-width bit-field promotion Jason Merrill
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Jason Merrill @ 2019-09-16  4:33 UTC (permalink / raw)
  To: gcc-patches

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.

Tested x86_64-pc-linux-gnu, applying to trunk.

	* c-warn.c (warn_logical_operator): Strip location wrappers.  Don't
	fold_for_warn in "|| mask" warning.
---
 gcc/c-family/c-warn.c  | 40 ++++++++++++++++++++--------------------
 gcc/c-family/ChangeLog |  5 +++++
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index d671b77a2b0..bee5449bcb1 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -208,32 +208,32 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
      programmer. That is, an expression such as op && MASK
      where op should not be any boolean expression, nor a
      constant, and mask seems to be a non-boolean integer constant.  */
+  STRIP_ANY_LOCATION_WRAPPER (op_right);
   if (TREE_CODE (op_right) == CONST_DECL)
     /* An enumerator counts as a constant.  */
     op_right = DECL_INITIAL (op_right);
+  tree stripped_op_left = tree_strip_any_location_wrapper (op_left);
   if (!truth_value_p (code_left)
       && INTEGRAL_TYPE_P (TREE_TYPE (op_left))
-      && !CONSTANT_CLASS_P (op_left)
-      && !TREE_NO_WARNING (op_left))
+      && !CONSTANT_CLASS_P (stripped_op_left)
+      && TREE_CODE (stripped_op_left) != CONST_DECL
+      && !TREE_NO_WARNING (op_left)
+      && TREE_CODE (op_right) == INTEGER_CST
+      && !integer_zerop (op_right)
+      && !integer_onep (op_right))
     {
-      tree folded_op_right = fold_for_warn (op_right);
-      if (TREE_CODE (folded_op_right) == INTEGER_CST
-	  && !integer_zerop (folded_op_right)
-	  && !integer_onep (folded_op_right))
-	{
-	  bool warned;
-	  if (or_op)
-	    warned
-	      = warning_at (location, OPT_Wlogical_op,
-			    "logical %<or%> applied to non-boolean constant");
-	  else
-	    warned
-	      = warning_at (location, OPT_Wlogical_op,
-			    "logical %<and%> applied to non-boolean constant");
-	  if (warned)
-	    TREE_NO_WARNING (op_left) = true;
-	  return;
-	}
+      bool warned;
+      if (or_op)
+	warned
+	  = warning_at (location, OPT_Wlogical_op,
+			"logical %<or%> applied to non-boolean constant");
+      else
+	warned
+	  = warning_at (location, OPT_Wlogical_op,
+			"logical %<and%> applied to non-boolean constant");
+      if (warned)
+	TREE_NO_WARNING (op_left) = true;
+      return;
     }
 
   /* We do not warn for constants because they are typical of macro
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 2b700c2c4bd..93bdf3e0798 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+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>
 
 	* c.opt: Use newly added WarnRemoved.

base-commit: ce026385ee57427978053620a038bffaac90819e
-- 
2.21.0

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-11-05 23:53 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16  4:33 [C++ PATCH 1/4] Handle location wrappers better in warn_logical_operator Jason Merrill
2019-09-16  4:33 ` [C++ PATCH 4/4] PR c++/30277 - int-width bit-field promotion Jason Merrill
2019-09-21  6:23   ` Jakub Jelinek
2019-09-21 21:51     ` Jason Merrill
2019-09-16  4:33 ` [C++ PATCH 2/4] Fix conversions for built-in operator overloading candidates Jason Merrill
2019-09-17 14:07   ` Andreas Schwab
2019-09-17 14:19     ` Iain Sandoe
2019-09-19  0:19   ` JiangNing OS
2019-09-19 19:43     ` Jason Merrill
2019-09-19 20:11       ` Jason Merrill
2019-09-19 20:28         ` Marek Polacek
2019-11-05 23:53       ` Jason Merrill
2019-09-16  4:33 ` [C++ PATCH 3/4] PR c++/82165 - enum bitfields and operator overloading Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).