From e3de81de601e568dc7e7262026558f9a77ecdd60 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 13 Nov 2017 14:46:35 -0500
Subject: [PATCH 27/46] c-family: handle location wrappers

gcc/c-family/ChangeLog:
	* c-attribs.c (handle_tm_wrap_attribute): Handle location
	wrappers.
	* c-common.c (c_common_truthvalue_conversion): Likewise.
	(check_user_alignment): Likewise.
	(get_nonnull_operand): Likewise.
	(fold_offsetof_1): Likewise.
	(convert_vector_to_array_for_subscript): Likewise.
	* c-format.c (get_constant): Likewise.
	* c-warn.c (warn_logical_operator): Likewise.
	(find_array_ref_with_const_idx_r): Likewise.
	(warn_array_subscript_with_type_char): Likewise.
---
 gcc/c-family/c-attribs.c |  1 +
 gcc/c-family/c-common.c  |  9 +++++++++
 gcc/c-family/c-format.c  |  2 ++
 gcc/c-family/c-warn.c    | 25 +++++++++++++++++--------
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index bb75cba..e757628 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -2762,6 +2762,7 @@ handle_tm_wrap_attribute (tree *node, tree name, tree args,
   else
     {
       tree wrap_decl = TREE_VALUE (args);
+      STRIP_ANY_LOCATION_WRAPPER_SAFE (wrap_decl);
       if (error_operand_p (wrap_decl))
 	;
       else if (TREE_CODE (wrap_decl) != IDENTIFIER_NODE
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 5a26424..59a4d93 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -3228,6 +3228,8 @@ 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:
@@ -5079,6 +5081,9 @@ check_user_alignment (const_tree align, bool allow_zero)
 
   if (error_operand_p (align))
     return -1;
+
+  STRIP_ANY_LOCATION_WRAPPER (align);
+
   if (TREE_CODE (align) != INTEGER_CST
       || !INTEGRAL_TYPE_P (TREE_TYPE (align)))
     {
@@ -5356,6 +5361,8 @@ check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num)
 bool
 get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp)
 {
+  STRIP_ANY_LOCATION_WRAPPER (arg_num_expr);
+
   /* Verify the arg number is a small constant.  */
   if (tree_fits_uhwi_p (arg_num_expr))
     {
@@ -6155,6 +6162,7 @@ fold_offsetof_1 (tree expr, enum tree_code ctx)
 	return base;
 
       t = TREE_OPERAND (expr, 1);
+      STRIP_ANY_LOCATION_WRAPPER (t);
 
       /* Check if the offset goes beyond the upper bound of the array.  */
       if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
@@ -7600,6 +7608,7 @@ convert_vector_to_array_for_subscript (location_t loc,
 
       ret = !lvalue_p (*vecp);
 
+      STRIP_ANY_LOCATION_WRAPPER (index);
       if (TREE_CODE (index) == INTEGER_CST)
         if (!tree_fits_uhwi_p (index)
             || tree_to_uhwi (index) >= TYPE_VECTOR_SUBPARTS (type))
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 6b436ec..cdcd03a 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -263,6 +263,8 @@ check_format_string (tree fntype, unsigned HOST_WIDE_INT format_num,
 static bool
 get_constant (tree expr, unsigned HOST_WIDE_INT *value, int validated_p)
 {
+  STRIP_ANY_LOCATION_WRAPPER (expr);
+
   if (!tree_fits_uhwi_p (expr))
     {
       gcc_assert (!validated_p);
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 0086435..c7bc478 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -246,6 +246,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
   lhs = make_range (op_left, &in0_p, &low0, &high0, &strict_overflow_p);
   if (!lhs)
     return;
+  STRIP_ANY_LOCATION_WRAPPER (lhs);
 
   /* If this is an OR operation, invert both sides; now, the result
      should be always false to get a warning.  */
@@ -261,6 +262,7 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
   rhs = make_range (op_right, &in1_p, &low1, &high1, &strict_overflow_p);
   if (!rhs)
     return;
+  STRIP_ANY_LOCATION_WRAPPER (rhs);
 
   /* If this is an OR operation, invert both sides; now, the result
      should be always false to get a warning.  */
@@ -313,10 +315,14 @@ find_array_ref_with_const_idx_r (tree *expr_p, int *, void *)
 {
   tree expr = *expr_p;
 
-  if ((TREE_CODE (expr) == ARRAY_REF
-       || TREE_CODE (expr) == ARRAY_RANGE_REF)
-      && TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST)
-    return integer_type_node;
+  if (TREE_CODE (expr) == ARRAY_REF
+      || TREE_CODE (expr) == ARRAY_RANGE_REF)
+    {
+      tree index = TREE_OPERAND (expr, 1);
+      STRIP_ANY_LOCATION_WRAPPER (index);
+      if (TREE_CODE (index) == INTEGER_CST)
+	return integer_type_node;
+    }
 
   return NULL_TREE;
 }
@@ -1643,10 +1649,13 @@ invalid_indirection_error (location_t loc, tree type, ref_operator errstring)
 void
 warn_array_subscript_with_type_char (location_t loc, tree index)
 {
-  if (TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node
-      && TREE_CODE (index) != INTEGER_CST)
-    warning_at (loc, OPT_Wchar_subscripts,
-		"array subscript has type %<char%>");
+  if (TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
+    {
+      STRIP_ANY_LOCATION_WRAPPER (index);
+      if (TREE_CODE (index) != INTEGER_CST)
+	warning_at (loc, OPT_Wchar_subscripts,
+		    "array subscript has type %<char%>");
+    }
 }
 
 /* Implement -Wparentheses for the unexpected C precedence rules, to
-- 
1.8.5.3

