From 233615d74c2a33dfe73a63477a5715656f808115 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 26 Oct 2018 12:06:35 -0400
Subject: [PATCH 30/83] FIXME: fixups

---
 gcc/c-family/c-common.c              |  3 +++
 gcc/c-family/c-warn.c                | 27 +++++++++++++++------------
 gcc/cp/decl2.c                       |  3 +++
 gcc/cp/mangle.c                      |  5 +++++
 gcc/cp/parser.c                      |  2 +-
 gcc/objc/objc-act.c                  |  4 ++++
 gcc/testsuite/c-c++-common/pr51712.c |  2 +-
 gcc/tree.c                           |  3 +++
 8 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 5c337a4..b428180 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -1735,8 +1735,10 @@ warning_candidate_p (tree x)
   if (TREE_CODE (x) == STRING_CST)
     return false;
 
+#if 0
   if (location_wrapper_p (x))
     return false;
+#endif
 
   return true;
 }
@@ -7877,6 +7879,7 @@ convert_vector_to_array_for_subscript (location_t loc,
 
       ret = !lvalue_p (*vecp);
 
+      index = fold_for_warn (index);
       if (TREE_CODE (index) == INTEGER_CST)
         if (!tree_fits_uhwi_p (index)
 	    || maybe_ge (tree_to_uhwi (index), TYPE_VECTOR_SUBPARTS (type)))
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 1da26b2..65e2f99 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -208,19 +208,22 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
   if (!truth_value_p (code_left)
       && INTEGRAL_TYPE_P (TREE_TYPE (op_left))
       && !CONSTANT_CLASS_P (op_left)
-      && !TREE_NO_WARNING (op_left)
-      && TREE_CODE (op_right) == INTEGER_CST
-      && !integer_zerop (op_right)
-      && !integer_onep (op_right))
+      && !TREE_NO_WARNING (op_left))
     {
-      if (or_op)
-	warning_at (location, OPT_Wlogical_op, "logical %<or%>"
-		    " applied to non-boolean constant");
-      else
-	warning_at (location, OPT_Wlogical_op, "logical %<and%>"
-		    " applied to non-boolean constant");
-      TREE_NO_WARNING (op_left) = true;
-      return;
+      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))
+	{
+	  if (or_op)
+	    warning_at (location, OPT_Wlogical_op, "logical %<or%>"
+			" applied to non-boolean constant");
+	  else
+	    warning_at (location, OPT_Wlogical_op, "logical %<and%>"
+			" applied to non-boolean constant");
+	  TREE_NO_WARNING (op_left) = true;
+	  return;
+	}
     }
 
   /* We do not warn for constants because they are typical of macro
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index a5ad0ee..a0dd9a3 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -1058,6 +1058,9 @@ grokbitfield (const cp_declarator *declarator,
       return NULL_TREE;
     }
 
+  if (width)
+    STRIP_ANY_LOCATION_WRAPPER (width);
+
   if (width && TYPE_WARN_IF_NOT_ALIGN (TREE_TYPE (value)))
     {
       error ("cannot declare bit-field %qD with %<warn_if_not_aligned%> type",
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 59a3111..f8d09c3 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -2316,6 +2316,11 @@ write_type (tree type)
 		{
 		  tree expr = DECLTYPE_TYPE_EXPR (type);
 		  tree etype = NULL_TREE;
+#if 0
+		  /* FIXME: I'm not convinced this is the right fix
+		     for g++.dg/abi/mangle49.C.  */
+		  STRIP_ANY_LOCATION_WRAPPER (expr);
+#endif
 		  switch (TREE_CODE (expr))
 		    {
 		    case VAR_DECL:
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 04a5180..503bfb7 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -9337,7 +9337,7 @@ cp_parser_binary_expression (cp_parser* parser, bool cast_p,
 		      || (TREE_CODE (TREE_TYPE (TREE_OPERAND (current.lhs, 0)))
 			  != BOOLEAN_TYPE))))
 	  /* Avoid warning for !!b == y where b is boolean.  */
-	  && (!DECL_P (current.lhs)
+	  && (!DECL_P (tree_strip_any_location_wrapper (current.lhs))
 	      || TREE_TYPE (current.lhs) == NULL_TREE
 	      || TREE_CODE (TREE_TYPE (current.lhs)) != BOOLEAN_TYPE))
 	warn_logical_not_parentheses (current.loc, current.tree_type,
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index d086930..e5237d6 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -1455,6 +1455,8 @@ objc_maybe_build_component_ref (tree object, tree property_ident)
 		 || TREE_CODE (t) == COMPONENT_REF)
 	    t = TREE_OPERAND (t, 0);
 
+	  STRIP_ANY_LOCATION_WRAPPER (t);
+
 	  if (t == UOBJC_SUPER_decl)
 	    interface_type = lookup_interface (CLASS_SUPER_NAME (implementation_template));
 	  else if (t == self_decl)
@@ -5339,6 +5341,8 @@ objc_finish_message_expr (tree receiver, tree sel_name, tree method_params,
   tree retval, class_tree;
   int self, super, have_cast;
 
+  STRIP_ANY_LOCATION_WRAPPER (receiver);
+
   /* We have used the receiver, so mark it as read.  */
   mark_exp_read (receiver);
 
diff --git a/gcc/testsuite/c-c++-common/pr51712.c b/gcc/testsuite/c-c++-common/pr51712.c
index 69e316d..1ff36c4 100644
--- a/gcc/testsuite/c-c++-common/pr51712.c
+++ b/gcc/testsuite/c-c++-common/pr51712.c
@@ -15,5 +15,5 @@ int valid(enum test_enum arg)
 
 int valid2(unsigned int arg2)
 {
-  return arg2 >= FOO && arg2 <= BAR; /* { dg-bogus "comparison of unsigned expression" "" { xfail *-*-* } } */
+  return arg2 >= FOO && arg2 <= BAR; /* { dg-bogus "comparison of unsigned expression" "" { xfail c } } */
 }
diff --git a/gcc/tree.c b/gcc/tree.c
index b646fbd..2a60b51 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -6761,6 +6761,9 @@ tree_int_cst_equal (const_tree t1, const_tree t2)
   if (t1 == 0 || t2 == 0)
     return 0;
 
+  STRIP_ANY_LOCATION_WRAPPER (t1);
+  STRIP_ANY_LOCATION_WRAPPER (t2);
+
   if (TREE_CODE (t1) == INTEGER_CST
       && TREE_CODE (t2) == INTEGER_CST
       && wi::to_widest (t1) == wi::to_widest (t2))
-- 
1.8.5.3

