Patchwork Fix PR44946

login
register
mail settings
Submitter Richard Guenther
Date July 15, 2010, 11:13 a.m.
Message ID <alpine.LNX.2.00.1007151312330.1429@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/58971/
State New
Headers show

Comments

Richard Guenther - July 15, 2010, 11:13 a.m.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2010-07-15  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/44946
	* tree-ssa-structalias.c (get_constraint_for_component_ref): Deal
	with accessing only padding properly.

	* gcc.c-torture/compile/pr44946.c: New testcase.

Patch

Index: gcc/tree-ssa-structalias.c
===================================================================
--- gcc/tree-ssa-structalias.c	(revision 162209)
+++ gcc/tree-ssa-structalias.c	(working copy)
@@ -3177,13 +3177,19 @@  get_constraint_for_component_ref (tree t
 	      cexpr.var = curr->id;
 	      VEC_safe_push (ce_s, heap, *results, &cexpr);
 	    }
-	  else
+	  else if (VEC_length (ce_s, *results) == 0)
 	    /* Assert that we found *some* field there. The user couldn't be
 	       accessing *only* padding.  */
 	    /* Still the user could access one past the end of an array
 	       embedded in a struct resulting in accessing *only* padding.  */
-	    gcc_assert (VEC_length (ce_s, *results) >= 1
-			|| ref_contains_array_ref (orig_t));
+	    /* Or accessing only padding via type-punning to a type
+	       that has a filed just in padding space.  */
+	    {
+	      cexpr.type = SCALAR;
+	      cexpr.var = anything_id;
+	      cexpr.offset = 0;
+	      VEC_safe_push (ce_s, heap, *results, &cexpr);
+	    }
 	}
       else if (bitmaxsize == 0)
 	{
Index: gcc/testsuite/gcc.c-torture/compile/pr44946.c
===================================================================
--- gcc/testsuite/gcc.c-torture/compile/pr44946.c	(revision 0)
+++ gcc/testsuite/gcc.c-torture/compile/pr44946.c	(revision 0)
@@ -0,0 +1,27 @@ 
+struct A
+{
+  int i;
+  long l;
+};
+
+struct B
+{
+  int i;
+};
+
+struct C
+{
+  int i;
+  struct B b;
+};
+
+struct B foo (struct A a)
+{
+  struct C *c = (struct C *) &a;
+  return c->b;
+}
+void bar (struct A a, struct B b)
+{
+  struct C *c = (struct C *) &a;
+  c->b = b;
+}