This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, PR40351] When creating artificial (copy-propagation) sub-accesses, check that they make sense


On Mon, Jun 08, 2009 at 04:41:43PM -0400, Richard Guenther wrote:
> 2009/6/8 Martin Jambor <mjambor@suse.cz>:
> > Hi,
> >
> > this  patch fixes  PR 40351, caused  by  the  fact  that we  propagate
> > sub-accesses across assignments, unions can now trick us into creating
> > some which  do not make  sense (they do  not exist in a  union field).
> > The  patch  below checks  that  does  not  happen before  creating  an
> > artificial access.
> >
> > Bootstrapped and regression tested on x86_64-linux.  OK for trunk?
> 
> Hm.  Ok with a comment before that call.

OK, this is what I committed as revision 148315.

Thanks,

Martin

2009-06-09  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/40351
	* tree-sra.c (propagate_subacesses_accross_link): Check that a refrence
	to a potential artifical subaccess can be constructed.

	* testsuite/gcc.c-torture/compile/pr40351.c: New file.

Index: gcc/testsuite/gcc.c-torture/compile/pr40351.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.c-torture/compile/pr40351.c	2009-06-09 17:12:12.000000000 +0200
@@ -0,0 +1,22 @@
+/* PR tree-optimizations/40351 */
+
+struct IO_APIC_route_entry {
+    unsigned int vector : 8;
+    unsigned int delivery_mode : 1;
+    unsigned int mask : 1;
+    unsigned int __reserved_2 : 15;
+    unsigned int __reserved_3 : 8;
+} __attribute__ ((packed));
+union entry_union {
+    struct {
+        unsigned int w1, w2;
+    };
+    struct IO_APIC_route_entry entry;
+};
+unsigned int io_apic_read(void);
+struct IO_APIC_route_entry ioapic_read_entry(void)
+{
+  union entry_union eu;
+  eu.w1 = io_apic_read();
+  return eu.entry;
+}
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c.orig	2009-06-08 22:54:02.000000000 +0200
+++ gcc/tree-sra.c	2009-06-09 18:25:40.000000000 +0200
@@ -1544,6 +1544,13 @@ propagate_subacesses_accross_link (struc
 	  continue;
 	}
 
+      /* If a (part of) a union field in on the RHS of an assignment, it can
+	 have sub-accesses which do not make sense on the LHS (PR 40351).
+	 Check that this is not the case.  */
+      if (!build_ref_for_offset (NULL, TREE_TYPE (lacc->base), norm_offset,
+				 rchild->type, false))
+	continue;
+
       new_acc = create_artificial_child_access (lacc, rchild, norm_offset);
       if (racc->first_child)
 	propagate_subacesses_accross_link (new_acc, rchild);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]