From d74720def960b1fa599e6199b9109295983a5cb2 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 23 Oct 2018 11:47:27 -0400
Subject: [PATCH 17/35] FIXME: more fixups

---
 gcc/c-family/c-common.c                                  |  9 +++++++++
 gcc/cp/parser.c                                          |  4 ++++
 gcc/cp/tree.c                                            |  9 +++++++++
 gcc/cp/typeck.c                                          | 16 ++++++++++------
 gcc/fold-const.c                                         |  3 +++
 .../g++.dg/wrappers/NOT_FOR_UPSTREAM/Wparentheses.C      | 10 ++++++++++
 6 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/wrappers/NOT_FOR_UPSTREAM/Wparentheses.C

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 0a9ebdd..48a8673 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3230,6 +3230,7 @@ decl_with_nonnull_addr_p (const_tree expr)
 tree
 c_common_truthvalue_conversion (location_t location, tree expr)
 {
+  STRIP_ANY_LOCATION_WRAPPER (expr);
   switch (TREE_CODE (expr))
     {
     case EQ_EXPR:   case NE_EXPR:   case UNEQ_EXPR: case LTGT_EXPR:
@@ -3449,6 +3450,14 @@ c_common_truthvalue_conversion (location_t location, tree expr)
 	}
       break;
 
+    case CONST_DECL:
+      {
+	tree folded_expr = fold_for_warn (expr);
+	if (folded_expr != expr)
+	  return c_common_truthvalue_conversion (location, folded_expr);
+      }
+      break;
+
     default:
       break;
     }
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index e3472da..2a168df 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -35264,6 +35264,10 @@ cp_parser_omp_for_loop (cp_parser *parser, enum tree_code code, tree clauses,
 	}
       loc = cp_lexer_consume_token (parser->lexer)->location;
 
+      /* Don't create location wrapper nodes within an OpenMP "for"
+	 statement.  */
+      auto_suppress_location_wrappers sentinel;
+
       matching_parens parens;
       if (!parens.require_open (parser))
 	return NULL;
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index bbef7d3..b77de7b 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -371,6 +371,7 @@ bitfield_p (const_tree ref)
 tree
 cp_stabilize_reference (tree ref)
 {
+  STRIP_ANY_LOCATION_WRAPPER (ref);
   switch (TREE_CODE (ref))
     {
     case NON_DEPENDENT_EXPR:
@@ -5554,6 +5555,14 @@ test_lvalue_kind ()
   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_parm));
   tree rvalue_ref_of_wrapped_parm = move (wrapped_parm);
   ASSERT_EQ (clk_rvalueref, lvalue_kind (rvalue_ref_of_wrapped_parm));
+
+  /* Verify lvalue_p.  */
+  ASSERT_FALSE (lvalue_p (int_cst));
+  ASSERT_FALSE (lvalue_p (wrapped_int_cst));
+  ASSERT_TRUE (lvalue_p (parm));
+  ASSERT_TRUE (lvalue_p (wrapped_parm));
+  ASSERT_FALSE (lvalue_p (rvalue_ref_of_parm));
+  ASSERT_FALSE (lvalue_p (rvalue_ref_of_wrapped_parm));
 }
 
 /* Run all of the selftests within this file.  */
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 2351b9b..f0a5c02 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4823,13 +4823,17 @@ cp_build_binary_op (location_t location,
 	  && (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1)))
 	warning (OPT_Wfloat_equal,
 		 "comparing floating point with == or != is unsafe");
-      if ((complain & tf_warning)
-	  && ((TREE_CODE (orig_op0) == STRING_CST
+      if (complain & tf_warning)
+	{
+	  tree stripped_orig_op0 = tree_strip_any_location_wrapper (orig_op0);
+	  tree stripped_orig_op1 = tree_strip_any_location_wrapper (orig_op1);
+	  if ((TREE_CODE (stripped_orig_op0) == STRING_CST
 	       && !integer_zerop (cp_fully_fold (op1)))
-	      || (TREE_CODE (orig_op1) == STRING_CST
-		  && !integer_zerop (cp_fully_fold (op0)))))
-	warning (OPT_Waddress, "comparison with string literal results "
-			       "in unspecified behavior");
+	      || (TREE_CODE (stripped_orig_op1) == STRING_CST
+		  && !integer_zerop (cp_fully_fold (op0))))
+	    warning (OPT_Waddress, "comparison with string literal results "
+		     "in unspecified behavior");
+	}
 
       build_type = boolean_type_node;
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 5399288..b982608 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2938,6 +2938,9 @@ combine_comparisons (location_t loc,
 int
 operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
 {
+  STRIP_ANY_LOCATION_WRAPPER (arg0);
+  STRIP_ANY_LOCATION_WRAPPER (arg1);
+
   /* When checking, verify at the outermost operand_equal_p call that
      if operand_equal_p returns non-zero then ARG0 and ARG1 has the same
      hash value.  */
diff --git a/gcc/testsuite/g++.dg/wrappers/NOT_FOR_UPSTREAM/Wparentheses.C b/gcc/testsuite/g++.dg/wrappers/NOT_FOR_UPSTREAM/Wparentheses.C
new file mode 100644
index 0000000..c6157dd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/wrappers/NOT_FOR_UPSTREAM/Wparentheses.C
@@ -0,0 +1,10 @@
+// { dg-options "-Wparentheses" }
+
+extern char read_skip_spaces ();
+
+void test ()
+{
+  char c;
+  while ((c = read_skip_spaces ()) && c != ']')
+    ;
+}
-- 
1.8.5.3

