diff mbox series

tree-optimization/94266 - fix object type extraction heuristics

Message ID nycvar.YFH.7.76.2003201051260.5137@zhemvz.fhfr.qr
State New
Headers show
Series tree-optimization/94266 - fix object type extraction heuristics | expand

Commit Message

Richard Biener March 20, 2020, 9:51 a.m. UTC
This fixes the heuristic deriving an actual object type from a
MEM_REFs pointer operand to use the more sensible type of an
actual object instead of the pointed to type.

Bootstrapped / tested on x86_64-unknown-linux-gnu, applied.

Richard.

2020-03-20  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/94266
	* gimple-ssa-sprintf.c (get_origin_and_offset): Use the
	type of the underlying object to adjust for the containing
	field if available.
---
 gcc/gimple-ssa-sprintf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Jeff Law via Gcc-patches March 20, 2020, 2:43 p.m. UTC | #1
On Fri, 2020-03-20 at 10:51 +0100, Richard Biener wrote:
> This fixes the heuristic deriving an actual object type from a
> MEM_REFs pointer operand to use the more sensible type of an
> actual object instead of the pointed to type.
> 
> Bootstrapped / tested on x86_64-unknown-linux-gnu, applied.
> 
> Richard.
> 
> 2020-03-20  Richard Biener  <rguenther@suse.de>
> 
> 	PR tree-optimization/94266
> 	* gimple-ssa-sprintf.c (get_origin_and_offset): Use the
> 	type of the underlying object to adjust for the containing
> 	field if available.
Thanks.  I'll re-enable the tester momentarily.

Jeff
>
diff mbox series

Patch

diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 13640e0fd36..1879686ce0a 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -2331,7 +2331,9 @@  get_origin_and_offset (tree x, HOST_WIDE_INT *fldoff, HOST_WIDE_INT *off)
 
       if (off)
 	{
-	  tree xtype = TREE_TYPE (TREE_TYPE (x));
+	  tree xtype
+	    = (TREE_CODE (x) == ADDR_EXPR
+	       ? TREE_TYPE (TREE_OPERAND (x, 0)) : TREE_TYPE (TREE_TYPE (x)));
 
 	  /* The byte offset of the most basic struct member the byte
 	     offset *OFF corresponds to, or for a (multidimensional)