From fa78eb86a3c6afff74b617bf379654efd5e17b24 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 25 Aug 2017 16:12:02 -0400
Subject: [PATCH 43/46] Undo non-testsuite part of r251238: "c-family/c/c++:
 pass optional vec<location_t> to c-format.c" (doesn't fully work yet)

---
 gcc/c-family/c-common.c |  4 ++--
 gcc/c-family/c-common.h |  4 ++--
 gcc/c-family/c-format.c | 48 ++++++++++++++----------------------------------
 gcc/c/c-typeck.c        |  2 +-
 gcc/cp/call.c           |  2 +-
 gcc/cp/typeck.c         |  2 +-
 6 files changed, 21 insertions(+), 41 deletions(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 59a4d93..24c995d 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5551,7 +5551,7 @@ attribute_fallthrough_p (tree attr)
    diagnostics.  Return true if -Wnonnull warning has been diagnosed.  */
 bool
 check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
-			  int nargs, tree *argarray, vec<location_t> *arglocs)
+			  int nargs, tree *argarray)
 {
   bool warned_p = false;
 
@@ -5565,7 +5565,7 @@ check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
   /* Check for errors in format strings.  */
 
   if (warn_format || warn_suggest_attribute_format)
-    check_function_format (TYPE_ATTRIBUTES (fntype), nargs, argarray, arglocs);
+    check_function_format (TYPE_ATTRIBUTES (fntype), nargs, argarray);
 
   if (warn_format)
     check_function_sentinel (fntype, nargs, argarray);
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 151a5d5..3fb767a 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -801,7 +801,7 @@ extern tree fname_decl (location_t, unsigned, tree);
 
 extern int check_user_alignment (const_tree, bool);
 extern bool check_function_arguments (location_t loc, const_tree, const_tree,
-				      int, tree *, vec<location_t> *);
+				      int, tree *);
 extern void check_function_arguments_recurse (void (*)
 					      (void *, tree,
 					       unsigned HOST_WIDE_INT),
@@ -809,7 +809,7 @@ extern void check_function_arguments_recurse (void (*)
 					      unsigned HOST_WIDE_INT);
 extern bool check_builtin_function_arguments (location_t, vec<location_t>,
 					      tree, int, tree *);
-extern void check_function_format (tree, int, tree *, vec<location_t> *);
+extern void check_function_format (tree, int, tree *);
 extern bool attribute_fallthrough_p (tree);
 extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
 extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index cdcd03a..6d71fdd 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -992,7 +992,6 @@ struct format_check_context
   format_check_results *res;
   function_format_info *info;
   tree params;
-  vec<location_t> *arglocs;
 };
 
 /* Return the format name (as specified in the original table) for the format
@@ -1015,16 +1014,14 @@ format_flags (int format_num)
   gcc_unreachable ();
 }
 
-static void check_format_info (function_format_info *, tree,
-			       vec<location_t> *);
+static void check_format_info (function_format_info *, tree);
 static void check_format_arg (void *, tree, unsigned HOST_WIDE_INT);
 static void check_format_info_main (format_check_results *,
 				    function_format_info *, const char *,
 				    location_t, tree,
 				    int, tree,
 				    unsigned HOST_WIDE_INT,
-				    object_allocator<format_wanted_type> &,
-				    vec<location_t> *);
+				    object_allocator<format_wanted_type> &);
 
 static void init_dollar_format_checking (int, tree);
 static int maybe_read_dollar_number (const char **, int,
@@ -1039,8 +1036,7 @@ static void check_format_types (const substring_loc &fmt_loc,
 				format_wanted_type *,
 				const format_kind_info *fki,
 				int offset_to_type_start,
-				char conversion_char,
-				vec<location_t> *arglocs);
+				char conversion_char);
 static void format_type_warning (const substring_loc &fmt_loc,
 				 location_t param_loc,
 				 format_wanted_type *, tree,
@@ -1083,8 +1079,7 @@ decode_format_type (const char *s)
    attribute themselves.  */
 
 void
-check_function_format (tree attrs, int nargs, tree *argarray,
-		       vec<location_t> *arglocs)
+check_function_format (tree attrs, int nargs, tree *argarray)
 {
   tree a;
 
@@ -1105,7 +1100,7 @@ check_function_format (tree attrs, int nargs, tree *argarray,
 	      int i;
 	      for (i = nargs - 1; i >= 0; i--)
 		params = tree_cons (NULL_TREE, argarray[i], params);
-	      check_format_info (&info, params, arglocs);
+	      check_format_info (&info, params);
 	    }
 
 	  /* Attempt to detect whether the current function might benefit
@@ -1408,8 +1403,7 @@ get_flag_spec (const format_flag_spec *spec, int flag, const char *predicates)
    PARAMS is the list of argument values.  */
 
 static void
-check_format_info (function_format_info *info, tree params,
-		   vec<location_t> *arglocs)
+check_format_info (function_format_info *info, tree params)
 {
   format_check_context format_ctx;
   unsigned HOST_WIDE_INT arg_num;
@@ -1443,7 +1437,6 @@ check_format_info (function_format_info *info, tree params,
   format_ctx.res = &res;
   format_ctx.info = info;
   format_ctx.params = params;
-  format_ctx.arglocs = arglocs;
 
   check_function_arguments_recurse (check_format_arg, &format_ctx,
 				    format_tree, arg_num);
@@ -1528,7 +1521,6 @@ check_format_arg (void *ctx, tree format_tree,
   format_check_results *res = format_ctx->res;
   function_format_info *info = format_ctx->info;
   tree params = format_ctx->params;
-  vec<location_t> *arglocs = format_ctx->arglocs;
 
   int format_length;
   HOST_WIDE_INT offset;
@@ -1721,7 +1713,7 @@ check_format_arg (void *ctx, tree format_tree,
   res->number_other++;
   object_allocator <format_wanted_type> fwt_pool ("format_wanted_type pool");
   check_format_info_main (res, info, format_chars, fmt_param_loc, format_tree,
-			  format_length, params, arg_num, fwt_pool, arglocs);
+			  format_length, params, arg_num, fwt_pool);
 }
 
 /* Support class for argument_parser and check_format_info_main.
@@ -1786,8 +1778,7 @@ class argument_parser
 		   const char * const orig_format_chars,
 		   location_t format_string_loc, flag_chars_t &flag_chars,
 		   int &has_operand_number, tree first_fillin_param,
-		   object_allocator <format_wanted_type> &fwt_pool_,
-		   vec<location_t> *arglocs);
+		   object_allocator <format_wanted_type> &fwt_pool_);
 
   bool read_any_dollar ();
 
@@ -1866,7 +1857,6 @@ class argument_parser
  private:
   format_wanted_type *first_wanted_type;
   format_wanted_type *last_wanted_type;
-  vec<location_t> *arglocs;
 };
 
 /* flag_chars_t's constructor.  */
@@ -2017,8 +2007,7 @@ argument_parser (function_format_info *info_, const char *&format_chars_,
 		 flag_chars_t &flag_chars_,
 		 int &has_operand_number_,
 		 tree first_fillin_param_,
-		 object_allocator <format_wanted_type> &fwt_pool_,
-		 vec<location_t> *arglocs_)
+		 object_allocator <format_wanted_type> &fwt_pool_)
 : info (info_),
   fki (&format_types[info->format_type]),
   flag_specs (fki->flag_specs),
@@ -2034,8 +2023,7 @@ argument_parser (function_format_info *info_, const char *&format_chars_,
   has_operand_number (has_operand_number_),
   first_fillin_param (first_fillin_param_),
   first_wanted_type (NULL),
-  last_wanted_type (NULL),
-  arglocs (arglocs_)
+  last_wanted_type (NULL)
 {
 }
 
@@ -2758,7 +2746,7 @@ check_argument_type (const format_char_info *fci,
       ptrdiff_t offset_to_type_start = type_start - orig_format_chars;
       check_format_types (fmt_loc, first_wanted_type, fki,
 			  offset_to_type_start,
-			  conversion_char, arglocs);
+			  conversion_char);
     }
 
   return true;
@@ -2777,8 +2765,7 @@ check_format_info_main (format_check_results *res,
 			location_t fmt_param_loc, tree format_string_cst,
 			int format_length, tree params,
 			unsigned HOST_WIDE_INT arg_num,
-			object_allocator <format_wanted_type> &fwt_pool,
-			vec<location_t> *arglocs)
+			object_allocator <format_wanted_type> &fwt_pool)
 {
   const char * const orig_format_chars = format_chars;
   const tree first_fillin_param = params;
@@ -2825,7 +2812,7 @@ check_format_info_main (format_check_results *res,
       argument_parser arg_parser (info, format_chars, format_string_cst,
 				  orig_format_chars, format_string_loc,
 				  flag_chars, has_operand_number,
-				  first_fillin_param, fwt_pool, arglocs);
+				  first_fillin_param, fwt_pool);
 
       if (!arg_parser.read_any_dollar ())
 	return;
@@ -3055,8 +3042,7 @@ static void
 check_format_types (const substring_loc &fmt_loc,
 		    format_wanted_type *types, const format_kind_info *fki,
 		    int offset_to_type_start,
-		    char conversion_char,
-		    vec<location_t> *arglocs)
+		    char conversion_char)
 {
   for (; types != 0; types = types->next)
     {
@@ -3098,12 +3084,6 @@ check_format_types (const substring_loc &fmt_loc,
       location_t param_loc = UNKNOWN_LOCATION;
       if (EXPR_HAS_LOCATION (cur_param))
 	param_loc = EXPR_LOCATION (cur_param);
-      else if (arglocs)
-	{
-	  /* arg_num is 1-based.  */
-	  gcc_assert (types->arg_num > 0);
-	  param_loc = (*arglocs)[types->arg_num - 1];
-	}
 
       STRIP_NOPS (cur_param);
 
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index ea4f7cc..beeb740 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -3120,7 +3120,7 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
 
   /* Check that the arguments to the function are valid.  */
   bool warned_p = check_function_arguments (loc, fundecl, fntype,
-					    nargs, argarray, &arg_loc);
+					    nargs, argarray);
 
   if (name != NULL_TREE
       && !strncmp (IDENTIFIER_POINTER (name), "__builtin_", 10))
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 7dfac4f..92b56ce 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8017,7 +8017,7 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
 	fargs[j] = maybe_constant_value (argarray[j]);
 
       warned_p = check_function_arguments (input_location, fn, TREE_TYPE (fn),
-					   nargs, fargs, NULL);
+					   nargs, fargs);
     }
 
   if (DECL_INHERITED_CTOR (fn))
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 35a1790..d4c4e47 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3732,7 +3732,7 @@ cp_build_function_call_vec (tree function, vec<tree, va_gc> **params,
   /* Check for errors in format strings and inappropriately
      null parameters.  */
   bool warned_p = check_function_arguments (input_location, fndecl, fntype,
-					    nargs, argarray, NULL);
+					    nargs, argarray);
 
   ret = build_cxx_call (function, nargs, argarray, complain);
 
-- 
1.8.5.3

