On 08/01/2018 08:33 AM, David Malcolm wrote:
On Tue, 2018-07-31 at 13:06 -0600, Martin Sebor wrote:
The GCC internal %G directive takes a gcall* argument and prints
the call's inlining stack in diagnostics.  The argument type makes
it unsuitable for gimple expressions such as those diagnosed by
-Warray-bounds.

As the first step in adding inlining context to -Warray-bounds
warnings the attached patch changes the %G argument to accept
gimple* instead of gcall*.  (More work is needed for %G to
preserve the location range within diagnostics so this patch
just implements the first step.)

Thanks for the patch.

I'm afraid I've been touching some of the same code recently (as part
of my work on dumpfile.c), so I think this patch needs rebasing and
retesting (sorry!).

No problem.  I have seen some of your changes but didn't spot
any serious conflicts.


In particular, my r263181:
  https://gcc.gnu.org/ml/gcc-patches/2018-07/msg01765.html
   ("c-family: clean up the data tables in c-format.c",
    aka 98605dea9f97f74e6a5e75308774c117292b184e)
cleaned up part of c-format.c that your patch touches; I think your
patch is from before then.

Yes, I think the only adjustments to be made here should be
to the gcall*/gimple* comments.


Also, I noticed that your patch conflicts with my (not yet approved)
patch here:

   [PATCH 5/5] Formatted printing for dump_* in the middle-end
     https://gcc.gnu.org/ml/gcc-patches/2018-07/msg01763.html

(which *adds* a usage of "gimple *" for a new pretty_printer subclass,
whereas yours changes the "gcall *" usage to "gimple *"), so we need to
sync up on that - I'm volunteering for me to wait for you (but please
send me a heads-up email when you eventually commit).

I saw this patch yesterday but didn't notice a conflict.  Your
changes are more extensive than mine so thanks for the offer to
deal with any potential collisions.  If your patch is approved
first it shouldn't be too hard for me to adjust to yours.  I
think we can just wait and see.

PR tree-optimization/86650 - -Warray-bounds missing inlining context

gcc/c/ChangeLog:

        PR tree-optimization/86650
        * c-objc-common.c (c_tree_printer): Adjust.

I feel a bit hypocritical saying this, as I dislike writing ChangeLog
entries, but I find this one too terse: I find myself asking "what
adjustment is being made, and why?"

How about something like:

gcc/c/ChangeLog:

        PR tree-optimization/86650
        * c-objc-common.c (c_tree_printer): Move usage of
        EXPR_LOCATION (t) and TREE_BLOCK (t) from within percent_K_format
        to this callsite.

or somesuch (assuming that I've read the intent of the change
correctly); *is* that the intent of this part of the patch?

The intent is to be able to call percent_K_format() with location
and block arguments that are different from those embedded in arg.
This is relied on in percent_G_format(), otherwise the change has
no effect on percent_K_format() or its other callers.

Most of the changes in this patch were mechanical, and this one
is in my mind obvious: call the function with its new arguments.
No functionality has been added or removed here.  But I agree
that your description is more -- descriptive? -- so I've replaced
the entry with the text as you suggest.

gcc/c-family/ChangeLog:

        PR tree-optimization/86650
        * c-format.c (local_gcall_ptr_node): Rename...
         (local_gimple_ptr_node): ...to this.
        * c-format.h (T89_G): Adjust.

Likewise, I find this too terse, and it's incomplete: it's missing the
changes to gcc_diag_char_table and to init_dynamic_diag_info.

How about something like this:

        * c-format.c (local_gcall_ptr_node): Rename...
        (local_gimple_ptr_node): ...to this.
        (gcc_diag_char_table): Update comment for "%G".
        (init_dynamic_diag_info): Update from "gcall *" to "gimple *".
        * c-format.h (T89_G): Update to be "gimple *" rather than
        "gcall *".

I've changed it to the above.  (I didn't know that trivial changes
like updating comments was expected to be documented in ChangeLogs,
but fine.)


FWIW I use this script to help ChangeLog entries.
It saves a lot of gruntwork:

  
https://github.com/davidmalcolm/gcc-refactoring-scripts/blob/master/generate-changelog.py

(but the remaining work is still tedious, alas)

gcc/cp/ChangeLog:

        PR tree-optimization/86650
        * error.c (cp_printer): Adjust.

See the suggestion above for c-objc-common.c (c_tree_printer).

Ditto.


gcc/ChangeLog:

        PR tree-optimization/86650
        * gimple-pretty-print.c (percent_G_format): Simplify.
        * tree-diagnostic.c (default_tree_printer): Adjust.
        * tree-pretty-print.c (percent_K_format): Add argument.
        * tree-pretty-print.h: Add argument.
        * gimple-fold.c (gimple_fold_builtin_strncpy): Adjust.
        * gimple-ssa-warn-restrict.h (check_bounds_or_overlap): Replace
        gcall* argument with gimple*.
        * gimple-ssa-warn-restrict.c (check_call): Same.
        (wrestrict_dom_walker::before_dom_children): Same.
        (builtin_access::builtin_access): Same.
        (check_bounds_or_overlap): Same.
        * tree-ssa-ccp.c (pass_post_ipa_warn::execute): Adjust.
        * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Adjust.

The filenames in this changelog entry aren't in alphabetical order. Was
that deliberate, or an accident of the way you generated them?  It
makes it harder to review the change, as the changes aren't in the
same order as the patch itself.  I think it can occasionally be useful
to do them out-of-order if it helps express the intent of the change,
but I  don't think that's the case here; keeping them in alphabetical
order is probably best here.

I do have a script that generates ChangeLog templates for me to
fill in.  It relies on lsdiff that I think sorts files on its
own.  I don't know why these aren't sorted.  Probably because
I moved things around.  I had no idea that anyone expected
ChangeLog entries to be in any particular order.

I've made the change you suggest and I can see that it could
make the changes easier to cross-reference (I myself search
for each entry as go through my own review).  With no
disrespect, though, I find insisting on it excessive.  AFAIK,
the GNU Coding Standard doesn't require it, neither do the
GCC Coding Conventions, and there are plenty of examples of
entries by others that aren't sorted (probably for the same
reason mine weren't). If you feel that it's important they
be sorted then please bring it up for discussion.  If there
is consensus to adopt this requirement then I will certainly
follow it.

Please can you provide a less terse ChangeLog describing the intent of
the changes.  I believe the two essential things in your patch are:

(a) moving the usage of EXPR_LOCATION (t) and TREE_BLOCK (t) from
within percent_K/G_format out to all of their callsites, and

(b) the change from gcall * to gimple *,

assuming I'm reading things right, but in my pre-caffeinated state I'd
greatly prefer the ChangeLog spell that out.

gcc/testsuite/ChangeLog:

        PR tree-optimization/86650
        * gcc.dg/format/gcc_diag-10.c: Adjust.

[...snip...]

The patch is almost ready.  Please rebase to past r263181, updating
accordingly, and retest, and please provide a less terse ChangeLog
(then repost for re-review).

Attached is an updated and retested patch.  The only code
change I had to make was resolve a conflict in a comment.
Otherwise the patch is the same.

Martin

PR tree-optimization/86650 - -Warray-bounds missing inlining context

gcc/c/ChangeLog:

	PR tree-optimization/86650
	* c-objc-common.c (c_tree_printer): Move usage of EXPR_LOCATION (t)
	and TREE_BLOCK (t) from within percent_K_format	to this callsite.

gcc/c-family/ChangeLog:

	PR tree-optimization/86650
	(gcc_tdiag_char_table): Update comment for "%G".
	(gcc_cdiag_char_table, gcc_cxxdiag_char_table): Same.
 	(init_dynamic_diag_info): Update from "gcall *" to "gimple *".
 	* c-format.h (T89_G): Update to be "gimple *" rather than
 	"gcall *".

gcc/cp/ChangeLog:

	PR tree-optimization/86650
	* error.c (cp_printer): Move usage of EXPR_LOCATION (t) and
	TREE_BLOCK (t) from within percent_K_format to this callsite.

gcc/ChangeLog:

	PR tree-optimization/86650
	* gimple-pretty-print.c (percent_G_format): Simplify.
	* gimple-fold.c (gimple_fold_builtin_strncpy): Adjust.
	* gimple-ssa-warn-restrict.h (check_bounds_or_overlap): Replace
	gcall* argument with gimple*.
	* gimple-ssa-warn-restrict.c (check_call): Same.
	(wrestrict_dom_walker::before_dom_children): Same.
	(builtin_access::builtin_access): Same.
	(check_bounds_or_overlap): Same.
	* tree-diagnostic.c (default_tree_printer): Move usage of
	EXPR_LOCATION (t) and TREE_BLOCK (t) from within percent_K_format
	to this callsite.
	* tree-pretty-print.c (percent_K_format): Add argument.
	* tree-pretty-print.h: Add argument.
	* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Adjust.
	* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Adjust.

gcc/testsuite/ChangeLog:

	PR tree-optimization/86650
	* gcc.dg/format/gcc_diag-10.c: Adjust.

diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index a0192dd..705bffb 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -56,7 +56,7 @@ struct function_format_info
 
 /* Initialized in init_dynamic_diag_info.  */
 static GTY(()) tree local_tree_type_node;
-static GTY(()) tree local_gcall_ptr_node;
+static GTY(()) tree local_gimple_ptr_node;
 static GTY(()) tree locus;
 
 static bool decode_format_attr (tree, function_format_info *, int);
@@ -722,7 +722,7 @@ static const format_char_info gcc_tdiag_char_table[] =
   { "E", 1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "",   NULL },
   { "K", 1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "\"",   NULL },
 
-  /* G requires a "gcall*" argument at runtime.  */
+  /* G requires a "gimple*" argument at runtime.  */
   { "G", 1, STD_C89, { T89_G,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "\"",   NULL },
 
   { "v",   0, STD_C89, { T89_I,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q#",  "",   NULL },
@@ -754,7 +754,7 @@ static const format_char_info gcc_cdiag_char_table[] =
   { "E",   1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "",   NULL },
   { "K",   1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "\"",   NULL },
 
-  /* G requires a "gcall*" argument at runtime.  */
+  /* G requires a "gimple*" argument at runtime.  */
   { "G",   1, STD_C89, { T89_G,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "\"",   NULL },
 
   { "v",   0, STD_C89, { T89_I,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q#",  "",   NULL },
@@ -787,7 +787,7 @@ static const format_char_info gcc_cxxdiag_char_table[] =
   { "K", 1, STD_C89,{ T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "",   "\"",   NULL },
   { "v", 0,STD_C89, { T89_I,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q#",  "",   NULL },
 
-  /* G requires a "gcall*" argument at runtime.  */
+  /* G requires a "gimple*" argument at runtime.  */
   { "G", 1, STD_C89,{ T89_G,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "",   "\"",   NULL },
 
   /* These accept either an 'int' or an 'enum tree_code' (which is handled as an 'int'.)  */
@@ -3875,27 +3875,27 @@ init_dynamic_diag_info (void)
 	local_tree_type_node = void_type_node;
     }
 
-  /* Similar to the above but for gcall*.  */
-  if (!local_gcall_ptr_node
-      || local_gcall_ptr_node == void_type_node)
+  /* Similar to the above but for gimple*.  */
+  if (!local_gimple_ptr_node
+      || local_gimple_ptr_node == void_type_node)
     {
-      if ((local_gcall_ptr_node = maybe_get_identifier ("gcall")))
+      if ((local_gimple_ptr_node = maybe_get_identifier ("gimple")))
 	{
-	  local_gcall_ptr_node
-	    = identifier_global_value (local_gcall_ptr_node);
-	  if (local_gcall_ptr_node)
+	  local_gimple_ptr_node
+	    = identifier_global_value (local_gimple_ptr_node);
+	  if (local_gimple_ptr_node)
 	    {
-	      if (TREE_CODE (local_gcall_ptr_node) != TYPE_DECL)
+	      if (TREE_CODE (local_gimple_ptr_node) != TYPE_DECL)
 		{
-		  error ("%<gcall%> is not defined as a type");
-		  local_gcall_ptr_node = 0;
+		  error ("%<gimple%> is not defined as a type");
+		  local_gimple_ptr_node = 0;
 		}
 	      else
-		local_gcall_ptr_node = TREE_TYPE (local_gcall_ptr_node);
+		local_gimple_ptr_node = TREE_TYPE (local_gimple_ptr_node);
 	    }
 	}
       else
-	local_gcall_ptr_node = void_type_node;
+	local_gimple_ptr_node = void_type_node;
     }
 
   static tree hwi;
diff --git a/gcc/c-family/c-format.h b/gcc/c-family/c-format.h
index f828e77..d984d10 100644
--- a/gcc/c-family/c-format.h
+++ b/gcc/c-family/c-format.h
@@ -298,7 +298,7 @@ struct format_kind_info
 #define T_UC	&unsigned_char_type_node
 #define T99_UC	{ STD_C99, NULL, T_UC }
 #define T_V	&void_type_node
-#define T89_G   { STD_C89, NULL, &local_gcall_ptr_node }
+#define T89_G   { STD_C89, NULL, &local_gimple_ptr_node }
 #define T89_T   { STD_C89, NULL, &local_tree_type_node }
 #define T89_V	{ STD_C89, NULL, T_V }
 #define T_W	&wchar_type_node
diff --git a/gcc/c/c-objc-common.c b/gcc/c/c-objc-common.c
index a841bc1..ddbd60c 100644
--- a/gcc/c/c-objc-common.c
+++ b/gcc/c/c-objc-common.c
@@ -67,7 +67,7 @@ c_objc_common_init (void)
    %D: a general decl,
    %E: an identifier or expression,
    %F: a function declaration,
-   %G: a Gimple call statement,
+   %G: a Gimple statement,
    %K: a CALL_EXPR,
    %T: a type.
    %V: a list of type qualifiers from a tree.
@@ -99,7 +99,7 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
   if (*spec == 'K')
     {
       t = va_arg (*text->args_ptr, tree);
-      percent_K_format (text, t);
+      percent_K_format (text, EXPR_LOCATION (t), TREE_BLOCK (t));
       return true;
     }
 
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index b0d8e32..6496256 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -4096,7 +4096,7 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
 
     case 'K':
       t = va_arg (*text->args_ptr, tree);
-      percent_K_format (text, t);
+      percent_K_format (text, EXPR_LOCATION (t), TREE_BLOCK (t));
       return true;
 
     case 'H':
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index c3fa570..506a296 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1657,7 +1657,6 @@ gimple_fold_builtin_strncpy (gimple_stmt_iterator *gsi,
       if (!nonstring)
 	{
 	  tree fndecl = gimple_call_fndecl (stmt);
-	  gcall *call = as_a <gcall *> (stmt);
 
 	  /* Warn about the lack of nul termination: the result is not
 	     a (nul-terminated) string.  */
@@ -1666,11 +1665,11 @@ gimple_fold_builtin_strncpy (gimple_stmt_iterator *gsi,
 	    warning_at (loc, OPT_Wstringop_truncation,
 			"%G%qD destination unchanged after copying no bytes "
 			"from a string of length %E",
-			call, fndecl, slen);
+			stmt, fndecl, slen);
 	  else
 	    warning_at (loc, OPT_Wstringop_truncation,
 			"%G%qD destination unchanged after copying no bytes",
-			call, fndecl);
+			stmt, fndecl);
 	}
 
       replace_call_with_value (gsi, dest);
@@ -1991,7 +1990,7 @@ gimple_fold_builtin_strcat_chk (gimple_stmt_iterator *gsi)
 static bool
 gimple_fold_builtin_strncat (gimple_stmt_iterator *gsi)
 {
-  gcall *stmt = as_a <gcall *> (gsi_stmt (*gsi));
+  gimple *stmt = gsi_stmt (*gsi);
   tree dst = gimple_call_arg (stmt, 0);
   tree src = gimple_call_arg (stmt, 1);
   tree len = gimple_call_arg (stmt, 2);
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 19cdb40..d3c5ec6 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -2887,20 +2887,13 @@ gimple_dump_bb_for_graph (pretty_printer *pp, basic_block bb)
 
 
 /* Handle the %G format for TEXT.  Same as %K in handle_K_format in
-   tree-pretty-print.c but with a Gimple call statement as an argument.  */
+   tree-pretty-print.c but with a Gimple statement as an argument.  */
 
 void
 percent_G_format (text_info *text)
 {
-  gcall *stmt = va_arg (*text->args_ptr, gcall*);
+  gimple *stmt = va_arg (*text->args_ptr, gimple*);
 
-  /* Build a call expression from the Gimple call statement and
-     pass it to the K formatter that knows how to format it.  */
-  tree exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
-  CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
-  TREE_TYPE (exp) = gimple_call_return_type (stmt);
-  CALL_EXPR_STATIC_CHAIN (exp) = gimple_call_chain (stmt);
-  SET_EXPR_LOCATION (exp, gimple_location (stmt));
-
-  percent_K_format (text, exp);
+  tree block = gimple_block (stmt);
+  percent_K_format (text, gimple_location (stmt), block);
 }
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c
index 7dedb24..01503d6 100644
--- a/gcc/gimple-ssa-warn-restrict.c
+++ b/gcc/gimple-ssa-warn-restrict.c
@@ -88,7 +88,7 @@ class wrestrict_dom_walker : public dom_walker
   bool handle_gimple_call (gimple_stmt_iterator *);
 
  private:
-  void check_call (gcall *);
+  void check_call (gimple *);
 };
 
 edge
@@ -102,8 +102,7 @@ wrestrict_dom_walker::before_dom_children (basic_block bb)
       if (!is_gimple_call (stmt))
 	continue;
 
-      if (gcall *call = as_a <gcall *> (stmt))
-	check_call (call);
+      check_call (stmt);
     }
 
   return NULL;
@@ -192,7 +191,7 @@ class builtin_access
     return detect_overlap != &builtin_access::generic_overlap;
   }
 
-  builtin_access (gcall *, builtin_memref &, builtin_memref &);
+  builtin_access (gimple *, builtin_memref &, builtin_memref &);
 
   /* Entry point to determine overlap.  */
   bool overlap ();
@@ -563,7 +562,7 @@ builtin_memref::offset_out_of_bounds (int strict, offset_int ooboff[2]) const
 /* Create an association between the memory references DST and SRC
    for access by a call EXPR to a memory or string built-in funtion.  */
 
-builtin_access::builtin_access (gcall *call, builtin_memref &dst,
+builtin_access::builtin_access (gimple *call, builtin_memref &dst,
 				builtin_memref &src)
 : dstref (&dst), srcref (&src), sizrange (), ovloff (), ovlsiz (),
   dstoff (), srcoff (), dstsiz (), srcsiz ()
@@ -1324,7 +1323,7 @@ builtin_access::overlap ()
    Return true when one has been detected, false otherwise.  */
 
 static bool
-maybe_diag_overlap (location_t loc, gcall *call, builtin_access &acs)
+maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs)
 {
   if (!acs.overlap ())
     return false;
@@ -1577,7 +1576,7 @@ maybe_diag_overlap (location_t loc, gcall *call, builtin_access &acs)
    has been issued.  */
 
 static bool
-maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict,
+maybe_diag_offset_bounds (location_t loc, gimple *call, tree func, int strict,
 			  tree expr, const builtin_memref &ref)
 {
   if (!warn_array_bounds)
@@ -1722,7 +1721,7 @@ maybe_diag_offset_bounds (location_t loc, gcall *call, tree func, int strict,
    if/when appropriate.  */
 
 void
-wrestrict_dom_walker::check_call (gcall *call)
+wrestrict_dom_walker::check_call (gimple *call)
 {
   /* Avoid checking the call if it has already been diagnosed for
      some reason.  */
@@ -1822,7 +1821,7 @@ wrestrict_dom_walker::check_call (gcall *call)
    detected and diagnosed, true otherwise.  */
 
 bool
-check_bounds_or_overlap (gcall *call, tree dst, tree src, tree dstsize,
+check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize,
 			 tree srcsize, bool bounds_only /* = false */)
 {
   location_t loc = gimple_nonartificial_location (call);
diff --git a/gcc/gimple-ssa-warn-restrict.h b/gcc/gimple-ssa-warn-restrict.h
index 9bf84a3..c624589 100644
--- a/gcc/gimple-ssa-warn-restrict.h
+++ b/gcc/gimple-ssa-warn-restrict.h
@@ -20,7 +20,7 @@
 
 #ifndef GIMPLE_SSA_WARN_RESTRICT_H
 
-extern bool check_bounds_or_overlap (gcall *, tree, tree, tree, tree,
+extern bool check_bounds_or_overlap (gimple *, tree, tree, tree, tree,
 				     bool = false);
 
 #endif /* GIMPLE_SSA_WARN_RESTRICT_H */
diff --git a/gcc/testsuite/gcc.dg/format/gcc_diag-10.c b/gcc/testsuite/gcc.dg/format/gcc_diag-10.c
index 9bda73b..d724231 100644
--- a/gcc/testsuite/gcc.dg/format/gcc_diag-10.c
+++ b/gcc/testsuite/gcc.dg/format/gcc_diag-10.c
@@ -15,9 +15,9 @@ typedef struct location_s
 union tree_node;
 typedef union tree_node *tree;
 
-/* Define gcall as a dummy type.  The typedef must be provided for
+/* Define gimple as a dummy type.  The typedef must be provided for
    the C test to find the symbol.  */
-typedef struct gcall gcall;
+typedef struct gimple gimple;
 
 #define FORMAT(kind) __attribute__ ((format (__gcc_## kind ##__, 1, 2)))
 
@@ -26,7 +26,7 @@ void cdiag (const char*, ...) FORMAT (cdiag);
 void tdiag (const char*, ...) FORMAT (tdiag);
 void cxxdiag (const char*, ...) FORMAT (cxxdiag);
 
-void test_diag (tree t, gcall *gc)
+void test_diag (tree t, gimple *gc)
 {
   diag ("%<");   /* { dg-warning "unterminated quoting directive" } */
   diag ("%>");   /* { dg-warning "unmatched quoting directive " } */
@@ -50,7 +50,7 @@ void test_diag (tree t, gcall *gc)
   diag ("%<%r%R%>", "");
 }
 
-void test_cdiag (tree t, gcall *gc)
+void test_cdiag (tree t, gimple *gc)
 {
   cdiag ("%<");   /* { dg-warning "unterminated quoting directive" } */
   cdiag ("%>");   /* { dg-warning "unmatched quoting directive " } */
@@ -90,7 +90,7 @@ void test_cdiag (tree t, gcall *gc)
   cdiag ("%<%qT%>", t);  /* { dg-warning ".q. flag used within a quoted sequence" } */
 }
 
-void test_tdiag (tree t, gcall *gc)
+void test_tdiag (tree t, gimple *gc)
 {
   tdiag ("%<");       /* { dg-warning "unterminated quoting directive" } */
   tdiag ("%>");       /* { dg-warning "unmatched quoting directive " } */
@@ -127,7 +127,7 @@ void test_tdiag (tree t, gcall *gc)
   tdiag ("%<%qT%>", t);  /* { dg-warning ".q. flag used within a quoted sequence" } */
 }
 
-void test_cxxdiag (tree t, gcall *gc)
+void test_cxxdiag (tree t, gimple *gc)
 {
   cxxdiag ("%A", t);     /* { dg-warning ".A. conversion used unquoted" } */
   cxxdiag ("%D", t);     /* { dg-warning ".D. conversion used unquoted" } */
diff --git a/gcc/tree-diagnostic.c b/gcc/tree-diagnostic.c
index 9814d02..6b03b31 100644
--- a/gcc/tree-diagnostic.c
+++ b/gcc/tree-diagnostic.c
@@ -282,7 +282,7 @@ default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
 
     case 'K':
       t = va_arg (*text->args_ptr, tree);
-      percent_K_format (text, t);
+      percent_K_format (text, EXPR_LOCATION (t), TREE_BLOCK (t));
       return true;
 
     default:
diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c
index e65c40a..627d8d7 100644
--- a/gcc/tree-pretty-print.c
+++ b/gcc/tree-pretty-print.c
@@ -3980,15 +3980,14 @@ newline_and_indent (pretty_printer *pp, int spc)
 
 /* Handle the %K format for TEXT.  Separate from default_tree_printer
    so it can also be used in front ends.
-   Argument is a statement from which EXPR_LOCATION and TREE_BLOCK will
-   be recorded.  */
+   The location LOC and BLOCK are expected to be extracted by the caller
+   from the %K argument arg via EXPR_LOCATION(arg) and TREE_BLOCK(arg).  */
 
 void
-percent_K_format (text_info *text, tree t)
+percent_K_format (text_info *text, location_t loc, tree block)
 {
-  text->set_location (0, EXPR_LOCATION (t), true);
+  text->set_location (0, loc, true);
   gcc_assert (pp_ti_abstract_origin (text) != NULL);
-  tree block = TREE_BLOCK (t);
   *pp_ti_abstract_origin (text) = NULL;
 
   if (in_lto_p)
diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h
index cf2427f..adfc77b 100644
--- a/gcc/tree-pretty-print.h
+++ b/gcc/tree-pretty-print.h
@@ -45,7 +45,7 @@ extern int op_code_prio (enum tree_code);
 extern int op_prio (const_tree);
 extern const char *op_symbol_code (enum tree_code);
 extern void print_call_name (pretty_printer *, tree, dump_flags_t);
-extern void percent_K_format (text_info *, tree);
+extern void percent_K_format (text_info *, location_t, tree);
 extern void pp_tree_identifier (pretty_printer *, tree);
 extern void dump_function_header (FILE *, tree, dump_flags_t);
 extern void pp_double_int (pretty_printer *pp, double_int d, bool uns);
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 2f0e542..63c9531 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -3456,7 +3456,7 @@ pass_post_ipa_warn::execute (function *fun)
 		      location_t loc = gimple_location (stmt);
 		      if (warning_at (loc, OPT_Wnonnull,
 				      "%Gargument %u null where non-null "
-				      "expected", as_a <gcall *>(stmt), i + 1))
+				      "expected", stmt, i + 1))
 			{
 			  tree fndecl = gimple_call_fndecl (stmt);
 			  if (fndecl && DECL_IS_BUILTIN (fndecl))
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index 736e2d9..43cdba8 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -1627,8 +1627,7 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
 	  tree type = TREE_TYPE (oldlen);
 	  oldlen = fold_build2 (PLUS_EXPR, type, oldlen,
 				build_int_cst (type, 1));
-	  check_bounds_or_overlap (as_a <gcall *>(stmt), olddsi->ptr, src,
-				   oldlen, NULL_TREE);
+	  check_bounds_or_overlap (stmt, olddsi->ptr, src, oldlen, NULL_TREE);
 	}
 
       return;
@@ -1715,8 +1714,7 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi)
 
   if (const strinfo *chksi = olddsi ? olddsi : dsi)
     if (si
-	&& !check_bounds_or_overlap (as_a <gcall *>(stmt), chksi->ptr, si->ptr,
-				     NULL_TREE, len))
+	&& !check_bounds_or_overlap (stmt, chksi->ptr, si->ptr, NULL_TREE, len))
       {
 	gimple_set_no_warning (stmt, true);
 	set_no_warning = true;
@@ -2031,8 +2029,6 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
 	  lenrange[0] = wi::shwi (0, prec);
 	}
 
-      gcall *call = as_a <gcall *> (stmt);
-
       /* Set to true for strncat whose bound is derived from the length
 	 of the destination (the expected usage pattern).  */
       bool cat_dstlen_bounded = false;
@@ -2048,7 +2044,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
 			  "%G%qD output truncated before terminating nul "
 			  "copying %E bytes from a string of the same "
 			  "length",
-			  call, func, cnt);
+			  stmt, func, cnt);
       else if (!cat_dstlen_bounded)
 	{
 	  if (wi::geu_p (lenrange[0], cntrange[1]))
@@ -2062,12 +2058,12 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
 				  "from a string of length %wu",
 				  "%G%qD output truncated copying %E bytes "
 				  "from a string of length %wu",
-				  call, func, cnt, lenrange[0].to_uhwi ());
+				  stmt, func, cnt, lenrange[0].to_uhwi ());
 
 	      return warning_at (callloc, OPT_Wstringop_truncation,
 				 "%G%qD output truncated copying between %wu "
 				 "and %wu bytes from a string of length %wu",
-				 call, func, cntrange[0].to_uhwi (),
+				 stmt, func, cntrange[0].to_uhwi (),
 				 cntrange[1].to_uhwi (), lenrange[0].to_uhwi ());
 	    }
 	  else if (wi::geu_p (lenrange[1], cntrange[1]))
@@ -2081,12 +2077,12 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
 				  "byte from a string of length %wu",
 				  "%G%qD output may be truncated copying %E "
 				  "bytes from a string of length %wu",
-				  call, func, cnt, lenrange[1].to_uhwi ());
+				  stmt, func, cnt, lenrange[1].to_uhwi ());
 
 	      return warning_at (callloc, OPT_Wstringop_truncation,
 				 "%G%qD output may be truncated copying between "
 				 "%wu and %wu bytes from a string of length %wu",
-				 call, func, cntrange[0].to_uhwi (),
+				 stmt, func, cntrange[0].to_uhwi (),
 				 cntrange[1].to_uhwi (), lenrange[1].to_uhwi ());
 	    }
 	}
@@ -2102,7 +2098,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
 	  return warning_at (callloc, OPT_Wstringop_truncation,
 			     "%G%qD output may be truncated copying between "
 			     "%wu and %wu bytes from a string of length %wu",
-			     call, func, cntrange[0].to_uhwi (),
+			     stmt, func, cntrange[0].to_uhwi (),
 			     cntrange[1].to_uhwi (), lenrange[0].to_uhwi ());
 	}
     }
@@ -2122,7 +2118,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
       if (cntrange[0] == cntrange[1])
 	return warning_at (callloc, OPT_Wstringop_truncation,
 			   "%G%qD specified bound %E equals destination size",
-			   as_a <gcall *> (stmt), func, cnt);
+			   stmt, func, cnt);
     }
 
   return false;
@@ -2180,8 +2176,7 @@ handle_builtin_stxncpy (built_in_function, gimple_stmt_iterator *gsi)
   else
     srcsize = NULL_TREE;
 
-  if (!check_bounds_or_overlap (as_a <gcall *>(stmt), dst, src,
-				dstsize, srcsize))
+  if (!check_bounds_or_overlap (stmt, dst, src, dstsize, srcsize))
     {
       gimple_set_no_warning (stmt, true);
       return;
@@ -2222,13 +2217,13 @@ handle_builtin_stxncpy (built_in_function, gimple_stmt_iterator *gsi)
       && warning_at (callloc, OPT_Wstringop_truncation,
 		     "%G%qD output truncated before terminating nul "
 		     "copying as many bytes from a string as its length",
-		     as_a <gcall *>(stmt), func))
+		     stmt, func))
     warned = true;
   else if (silen && is_strlen_related_p (src, silen->ptr))
     warned = warning_at (callloc, OPT_Wstringop_overflow_,
 			 "%G%qD specified bound depends on the length "
 			 "of the source argument",
-			 as_a <gcall *>(stmt), func);
+			 stmt, func);
   if (warned)
     {
       location_t strlenloc = pss->second;
@@ -2467,8 +2462,7 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi)
 
 	tree sptr = si && si->ptr ? si->ptr : src;
 
-	if (!check_bounds_or_overlap (as_a <gcall *>(stmt), dst, sptr,
-				      NULL_TREE, slen))
+	if (!check_bounds_or_overlap (stmt, dst, sptr, NULL_TREE, slen))
 	  {
 	    gimple_set_no_warning (stmt, true);
 	    set_no_warning = true;
@@ -2578,8 +2572,7 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi)
 
       tree sptr = si && si->ptr ? si->ptr : src;
 
-      if (!check_bounds_or_overlap (as_a <gcall *>(stmt), dst, sptr,
-				    dstlen, srcsize))
+      if (!check_bounds_or_overlap (stmt, dst, sptr, dstlen, srcsize))
 	{
 	  gimple_set_no_warning (stmt, true);
 	  set_no_warning = true;

Reply via email to