From 462c31c007d8c9c8248f360485354a6ed244ee25 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 25 Aug 2017 16:47:51 -0400
Subject: [PATCH 44/46] start removing vec<location_t> workaround (see also the
 C++ patch to -Wformat, if it lands)

---
 gcc/c-family/c-common.c             | 15 ++++++--------
 gcc/c-family/c-common.h             |  5 ++---
 gcc/c/c-decl.c                      |  2 +-
 gcc/c/c-parser.c                    | 16 ++++-----------
 gcc/c/c-tree.h                      |  2 +-
 gcc/c/c-typeck.c                    | 39 +++++++++++++++++++------------------
 gcc/cp/call.c                       |  2 +-
 gcc/cp/typeck.c                     |  2 +-
 gcc/objc/objc-gnu-runtime-abi-01.c  |  6 +++---
 gcc/objc/objc-next-runtime-abi-01.c |  4 ++--
 gcc/objc/objc-next-runtime-abi-02.c |  8 ++++----
 11 files changed, 45 insertions(+), 56 deletions(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 24c995d..67b36ef 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5683,18 +5683,15 @@ builtin_function_validate_nargs (location_t loc, tree fndecl, int nargs,
 }
 
 /* Helper macro for check_builtin_function_arguments.  */
-#define ARG_LOCATION(N)					\
-  (arg_loc.is_empty ()					\
-   ? EXPR_LOC_OR_LOC (args[(N)], input_location)	\
-   : expansion_point_location (arg_loc[(N)]))
+#define ARG_LOCATION(N)				\
+   EXPR_LOC_OR_LOC (args[(N)], input_location)	\
 
 /* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
    Returns false if there was an error, otherwise true.  LOC is the
-   location of the function; ARG_LOC is a vector of locations of the
-   arguments.  */
+   location of the function.  */
 
 bool
-check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
+check_builtin_function_arguments (location_t loc,
 				  tree fndecl, int nargs, tree *args)
 {
   if (!DECL_BUILT_IN (fndecl)
@@ -6726,7 +6723,7 @@ add_atomic_size_parameter (unsigned n, location_t loc, tree function,
       v->quick_push (build_int_cst (size_type_node, n));
       for (z = 0; z < len; z++)
 	v->quick_push ((*params)[z]);
-      f = build_function_call_vec (loc, vNULL, function, v, NULL);
+      f = build_function_call_vec (loc, function, v, NULL);
       vec_free (v);
       return f;
     }
@@ -7171,7 +7168,7 @@ resolve_overloaded_builtin (location_t loc, tree function,
 	  return error_mark_node;
 
 	first_param = (*params)[0];
-	result = build_function_call_vec (loc, vNULL, new_function, params,
+	result = build_function_call_vec (loc, new_function, params,
 					  NULL);
 	if (result == error_mark_node)
 	  return result;
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 3fb767a..cce849f 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -807,8 +807,7 @@ extern void check_function_arguments_recurse (void (*)
 					       unsigned HOST_WIDE_INT),
 					      void *, tree,
 					      unsigned HOST_WIDE_INT);
-extern bool check_builtin_function_arguments (location_t, vec<location_t>,
-					      tree, int, tree *);
+extern bool check_builtin_function_arguments (location_t, tree, int, tree *);
 extern void check_function_format (tree, int, tree *);
 extern bool attribute_fallthrough_p (tree);
 extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
@@ -978,7 +977,7 @@ extern tree c_add_case_label (location_t, splay_tree, tree, tree, tree, tree,
 
 extern tree build_function_call (location_t, tree, tree);
 
-extern tree build_function_call_vec (location_t, vec<location_t>, tree,
+extern tree build_function_call_vec (location_t, tree,
 				     vec<tree, va_gc> *, vec<tree, va_gc> *);
 
 extern tree resolve_overloaded_builtin (location_t, tree, vec<tree, va_gc> *);
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index d95a2b6..fad4e11 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -5138,7 +5138,7 @@ finish_decl (tree decl, location_t init_loc, tree init,
 	  vec_alloc (v, 1);
 	  v->quick_push (cleanup);
 	  cleanup = c_build_function_call_vec (DECL_SOURCE_LOCATION (decl),
-					       vNULL, cleanup_decl, v, NULL);
+					       cleanup_decl, v, NULL);
 	  vec_free (v);
 
 	  /* Don't warn about decl unused; the cleanup uses it.  */
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 3d90e28..13d7dc0 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1439,7 +1439,7 @@ static struct c_expr c_parser_expression (c_parser *);
 static struct c_expr c_parser_expression_conv (c_parser *);
 static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool,
 					     vec<tree, va_gc> **, location_t *,
-					     tree *, vec<location_t> *,
+					     tree *,
 					     unsigned int * = NULL);
 static void c_parser_oacc_declare (c_parser *);
 static void c_parser_oacc_enter_exit_data (c_parser *, bool);
@@ -9230,7 +9230,6 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
   unsigned int i;
   vec<tree, va_gc> *exprlist;
   vec<tree, va_gc> *origtypes = NULL;
-  vec<location_t> arg_loc = vNULL;
   location_t start;
   location_t finish;
 
@@ -9292,7 +9291,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
 	  else
 	    exprlist = c_parser_expr_list (parser, true, false, &origtypes,
 					   sizeof_arg_loc, sizeof_arg,
-					   &arg_loc, &literal_zero_mask);
+					   &literal_zero_mask);
 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
 				     "expected %<)%>");
 	  orig_expr = expr;
@@ -9315,7 +9314,7 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
 	  start = expr.get_start ();
 	  finish = parser->tokens_buf[0].get_finish ();
 	  expr.value
-	    = c_build_function_call_vec (expr_loc, arg_loc, expr.value,
+	    = c_build_function_call_vec (expr_loc, expr.value,
 					 exprlist, origtypes);
 	  set_c_expr_source_range (&expr, start, finish);
 
@@ -9331,7 +9330,6 @@ c_parser_postfix_expression_after_primary (c_parser *parser,
 	      release_tree_vector (exprlist);
 	      release_tree_vector (origtypes);
 	    }
-	  arg_loc.release ();
 	  break;
 	case CPP_DOT:
 	  /* Structure element reference.  */
@@ -9536,8 +9534,7 @@ c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask,
 
 /* Parse a non-empty list of expressions.  If CONVERT_P, convert
    functions and arrays to pointers and lvalues to rvalues.  If
-   FOLD_P, fold the expressions.  If LOCATIONS is non-NULL, save the
-   locations of function arguments into this vector.
+   FOLD_P, fold the expressions.
 
    nonempty-expr-list:
      assignment-expression
@@ -9548,7 +9545,6 @@ static vec<tree, va_gc> *
 c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
 		    vec<tree, va_gc> **p_orig_types,
 		    location_t *sizeof_arg_loc, tree *sizeof_arg,
-		    vec<location_t> *locations,
 		    unsigned int *literal_zero_mask)
 {
   vec<tree, va_gc> *ret;
@@ -9572,8 +9568,6 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
   ret->quick_push (expr.value);
   if (orig_types)
     orig_types->quick_push (expr.original_type);
-  if (locations)
-    locations->safe_push (expr.get_location ());
   if (sizeof_arg != NULL
       && expr.original_code == SIZEOF_EXPR)
     {
@@ -9594,8 +9588,6 @@ c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p,
       vec_safe_push (ret, expr.value);
       if (orig_types)
 	vec_safe_push (orig_types, expr.original_type);
-      if (locations)
-	locations->safe_push (expr.get_location ());
       if (++idx < 3
 	  && sizeof_arg != NULL
 	  && expr.original_code == SIZEOF_EXPR)
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index 1135647..8ffe683 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -704,7 +704,7 @@ extern tree c_finish_omp_clauses (tree, enum c_omp_region_type);
 extern tree c_build_va_arg (location_t, tree, location_t, tree);
 extern tree c_finish_transaction (location_t, tree, int);
 extern bool c_tree_equal (tree, tree);
-extern tree c_build_function_call_vec (location_t, vec<location_t>, tree,
+extern tree c_build_function_call_vec (location_t, tree,
 				       vec<tree, va_gc> *, vec<tree, va_gc> *);
 extern tree c_omp_clause_copy_ctor (tree, tree, tree);
 
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index beeb740..ae5a729 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -93,7 +93,7 @@ static int function_types_compatible_p (const_tree, const_tree, bool *,
 					bool *);
 static int type_lists_compatible_p (const_tree, const_tree, bool *, bool *);
 static tree lookup_field (tree, tree);
-static int convert_arguments (location_t, vec<location_t>, tree,
+static int convert_arguments (location_t, tree,
 			      vec<tree, va_gc> *, vec<tree, va_gc> *, tree,
 			      tree);
 static tree pointer_diff (location_t, tree, tree);
@@ -2073,7 +2073,7 @@ convert_lvalue_to_rvalue (location_t loc, struct c_expr exp,
       params->quick_push (expr_addr);
       params->quick_push (tmp_addr);
       params->quick_push (seq_cst);
-      func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+      func_call = c_build_function_call_vec (loc, fndecl, params, NULL);
 
       /* EXPR is always read.  */
       mark_exp_read (exp.value);
@@ -2985,7 +2985,7 @@ build_function_call (location_t loc, tree function, tree params)
   vec_alloc (v, list_length (params));
   for (; params; params = TREE_CHAIN (params))
     v->quick_push (TREE_VALUE (params));
-  ret = c_build_function_call_vec (loc, vNULL, function, v, NULL);
+  ret = c_build_function_call_vec (loc, function, v, NULL);
   vec_free (v);
   return ret;
 }
@@ -3008,7 +3008,7 @@ inform_declaration (tree decl)
    PARAMS.  */
 
 tree
-build_function_call_vec (location_t loc, vec<location_t> arg_loc,
+build_function_call_vec (location_t loc,
 			 tree function, vec<tree, va_gc> *params,
 			 vec<tree, va_gc> *origtypes)
 {
@@ -3083,7 +3083,7 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
   /* Convert the parameters to the types declared in the
      function prototype, or apply default promotions.  */
 
-  nargs = convert_arguments (loc, arg_loc, TYPE_ARG_TYPES (fntype), params,
+  nargs = convert_arguments (loc, TYPE_ARG_TYPES (fntype), params,
 			     origtypes, function, fundecl);
   if (nargs < 0)
     return error_mark_node;
@@ -3114,8 +3114,7 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
   if (fundecl
       && DECL_BUILT_IN (fundecl)
       && DECL_BUILT_IN_CLASS (fundecl) == BUILT_IN_NORMAL
-      && !check_builtin_function_arguments (loc, arg_loc, fundecl, nargs,
-					    argarray))
+      && !check_builtin_function_arguments (loc, fundecl, nargs, argarray))
     return error_mark_node;
 
   /* Check that the arguments to the function are valid.  */
@@ -3167,8 +3166,8 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
 /* Like build_function_call_vec, but call also resolve_overloaded_builtin.  */
 
 tree
-c_build_function_call_vec (location_t loc, vec<location_t> arg_loc,
-			   tree function, vec<tree, va_gc> *params,
+c_build_function_call_vec (location_t loc, tree function,
+			   vec<tree, va_gc> *params,
 			   vec<tree, va_gc> *origtypes)
 {
   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
@@ -3185,7 +3184,7 @@ c_build_function_call_vec (location_t loc, vec<location_t> arg_loc,
       if (tem)
 	return tem;
     }
-  return build_function_call_vec (loc, arg_loc, function, params, origtypes);
+  return build_function_call_vec (loc, function, params, origtypes);
 }
 
 /* Convert the argument expressions in the vector VALUES
@@ -3203,14 +3202,12 @@ c_build_function_call_vec (location_t loc, vec<location_t> arg_loc,
 
    This is also where warnings about wrong number of args are generated.
 
-   ARG_LOC are locations of function arguments (if any).
-
    Returns the actual number of arguments processed (which may be less
    than the length of VALUES in some error situations), or -1 on
    failure.  */
 
 static int
-convert_arguments (location_t loc, vec<location_t> arg_loc, tree typelist,
+convert_arguments (location_t loc, tree typelist,
 		   vec<tree, va_gc> *values, vec<tree, va_gc> *origtypes,
 		   tree function, tree fundecl)
 {
@@ -3282,10 +3279,14 @@ convert_arguments (location_t loc, vec<location_t> arg_loc, tree typelist,
       tree parmval;
       /* Some __atomic_* builtins have additional hidden argument at
 	 position 0.  */
+#if 1
+      location_t ploc = EXPR_LOC_OR_LOC (val, input_location);
+#else
       location_t ploc
 	= !arg_loc.is_empty () && values->length () == arg_loc.length ()
 	  ? expansion_point_location_if_in_system_header (arg_loc[parmnum])
 	  : input_location;
+#endif
 
       if (type == void_type_node)
 	{
@@ -3972,7 +3973,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
       params->quick_push (lhs_addr);
       params->quick_push (rhs);
       params->quick_push (seq_cst);
-      func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+      func_call = c_build_function_call_vec (loc, fndecl, params, NULL);
       add_stmt (func_call);
 
       /* Finish the compound statement.  */
@@ -4051,7 +4052,7 @@ build_atomic_assign (location_t loc, tree lhs, enum tree_code modifycode,
       params->quick_push (lhs_addr);
       params->quick_push (rhs);
       params->quick_push (seq_cst);
-      func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+      func_call = c_build_function_call_vec (loc, fndecl, params, NULL);
 
       newval = create_tmp_var_raw (nonatomic_lhs_type);
       TREE_ADDRESSABLE (newval) = 1;
@@ -4092,7 +4093,7 @@ cas_loop:
   params->quick_push (lhs_addr);
   params->quick_push (old_addr);
   params->quick_push (seq_cst);
-  func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+  func_call = c_build_function_call_vec (loc, fndecl, params, NULL);
   old = build4 (TARGET_EXPR, nonatomic_lhs_type, old, func_call, NULL_TREE,
 		NULL_TREE);
   add_stmt (old);
@@ -4144,7 +4145,7 @@ cas_loop:
   params->quick_push (integer_zero_node);
   params->quick_push (seq_cst);
   params->quick_push (seq_cst);
-  func_call = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+  func_call = c_build_function_call_vec (loc, fndecl, params, NULL);
 
   goto_stmt = build1 (GOTO_EXPR, void_type_node, done_decl);
   SET_EXPR_LOCATION (goto_stmt, loc);
@@ -14061,7 +14062,7 @@ c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
   params->quick_push (src_addr);
   params->quick_push (tmp_addr);
   params->quick_push (seq_cst);
-  tree load = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+  tree load = c_build_function_call_vec (loc, fndecl, params, NULL);
 
   vec_alloc (params, 4);
 
@@ -14070,7 +14071,7 @@ c_omp_clause_copy_ctor (tree clause, tree dst, tree src)
   params->quick_push (dst_addr);
   params->quick_push (tmp_addr);
   params->quick_push (seq_cst);
-  tree store = c_build_function_call_vec (loc, vNULL, fndecl, params, NULL);
+  tree store = c_build_function_call_vec (loc, fndecl, params, NULL);
   return build2 (COMPOUND_EXPR, void_type_node, load, store);
 }
 
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 92b56ce..f7fb006 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8673,7 +8673,7 @@ build_cxx_call (tree fn, int nargs, tree *argarray,
       for (i = 0; i < nargs; i++)
 	argarray[i] = fold_non_dependent_expr (argarray[i]);
 
-      if (!check_builtin_function_arguments (EXPR_LOCATION (fn), vNULL, fndecl,
+      if (!check_builtin_function_arguments (EXPR_LOCATION (fn), fndecl,
 					     nargs, argarray))
 	return error_mark_node;
 
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index d4c4e47..3d04a0d 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3551,7 +3551,7 @@ build_function_call (location_t /*loc*/,
 
 /* Used by the C-common bits.  */
 tree
-build_function_call_vec (location_t /*loc*/, vec<location_t> /*arg_loc*/,
+build_function_call_vec (location_t /*loc*/,
 			 tree function, vec<tree, va_gc> *params,
 			 vec<tree, va_gc> * /*origtypes*/)
 {
diff --git a/gcc/objc/objc-gnu-runtime-abi-01.c b/gcc/objc/objc-gnu-runtime-abi-01.c
index 4321b36..4e5825c 100644
--- a/gcc/objc/objc-gnu-runtime-abi-01.c
+++ b/gcc/objc/objc-gnu-runtime-abi-01.c
@@ -704,7 +704,7 @@ build_objc_method_call (location_t loc, int super_flag, tree method_prototype,
      then cast the pointer, then call it with the method arguments.  */
   tv->quick_push (lookup_object);
   tv->quick_push (selector);
-  method = build_function_call_vec (loc, vNULL, sender, tv, NULL);
+  method = build_function_call_vec (loc, sender, tv, NULL);
   vec_free (tv);
 
   /* Pass the appropriate object to the method.  */
@@ -719,7 +719,7 @@ build_objc_method_call (location_t loc, int super_flag, tree method_prototype,
 
   /* Build an obj_type_ref, with the correct cast for the method call.  */
   t = build3 (OBJ_TYPE_REF, sender_cast, method, lookup_object, size_zero_node);
-  t = build_function_call_vec (loc, vNULL, t, parms, NULL);
+  t = build_function_call_vec (loc, t, parms, NULL);
   vec_free (parms);
   return t;
 }
@@ -2217,7 +2217,7 @@ build_throw_stmt (location_t loc, tree throw_expr, bool rethrown ATTRIBUTE_UNUSE
   /* A throw is just a call to the runtime throw function with the
      object as a parameter.  */
   parms->quick_push (throw_expr);
-  t = build_function_call_vec (loc, vNULL, objc_exception_throw_decl, parms,
+  t = build_function_call_vec (loc, objc_exception_throw_decl, parms,
 			       NULL);
   vec_free (parms);
   return add_stmt (t);
diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-runtime-abi-01.c
index 686d928..b8f0288 100644
--- a/gcc/objc/objc-next-runtime-abi-01.c
+++ b/gcc/objc/objc-next-runtime-abi-01.c
@@ -882,7 +882,7 @@ build_objc_method_call (location_t loc, int super_flag, tree method_prototype,
   /* Build an obj_type_ref, with the correct cast for the method call.  */
   t = build3 (OBJ_TYPE_REF, sender_cast, method,
 			    lookup_object, size_zero_node);
-  t = build_function_call_vec (loc, vNULL, t, parms, NULL);
+  t = build_function_call_vec (loc, t, parms, NULL);
   vec_free (parms);
   return t;
 }
@@ -2866,7 +2866,7 @@ build_throw_stmt (location_t loc, tree throw_expr, bool rethrown ATTRIBUTE_UNUSE
   /* A throw is just a call to the runtime throw function with the
      object as a parameter.  */
   parms->quick_push (throw_expr);
-  t = build_function_call_vec (loc, vNULL, objc_exception_throw_decl, parms,
+  t = build_function_call_vec (loc, objc_exception_throw_decl, parms,
 			       NULL);
   vec_free (parms);
   return add_stmt (t);
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index 0e7fd54..ed213b9 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -1087,7 +1087,7 @@ next_runtime_abi_02_get_class_reference (tree ident)
       t = my_build_string_pointer (IDENTIFIER_LENGTH (ident) + 1,
 				   IDENTIFIER_POINTER (ident));
       v->quick_push (t);
-      t = build_function_call_vec (input_location, vNULL, objc_get_class_decl,
+      t = build_function_call_vec (input_location, objc_get_class_decl,
 				   v, 0);
       vec_free (v);
       return t;
@@ -3622,7 +3622,7 @@ build_throw_stmt (location_t loc, tree throw_expr, bool rethrown)
   tree t;
   if (rethrown)
     /* We have a separate re-throw entry.  */
-    t = build_function_call_vec (loc, vNULL, objc_rethrow_exception_decl,
+    t = build_function_call_vec (loc, objc_rethrow_exception_decl,
 				 NULL, NULL);
   else
     {
@@ -3630,7 +3630,7 @@ build_throw_stmt (location_t loc, tree throw_expr, bool rethrown)
       vec<tree, va_gc> *parms;
       vec_alloc (parms, 1);
       parms->quick_push (throw_expr);
-      t = build_function_call_vec (loc, vNULL, objc_exception_throw_decl,
+      t = build_function_call_vec (loc, objc_exception_throw_decl,
 				   parms, 0);
       vec_free (parms);
     }
@@ -3710,7 +3710,7 @@ finish_catch (struct objc_try_context **cur_try_context, tree curr_catch)
 
   /* Pick up the new context we made in begin_try above...  */
   ct = *cur_try_context;
-  func = build_function_call_vec (loc, vNULL, objc2_end_catch_decl, NULL,
+  func = build_function_call_vec (loc, objc2_end_catch_decl, NULL,
 				  NULL);
   append_to_statement_list (func, &ct->finally_body);
   try_exp = build_stmt (loc, TRY_FINALLY_EXPR, ct->try_body, ct->finally_body);
-- 
1.8.5.3

