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]

[PATCH, PR 42703] Check whether we can construct a reference to the original before creating a SRA replacement


Hi,

PR 42703 contains an out of bounds reference to an array within a
union.  When SRA tries to load data from that piece of memory, it
cannot find a field which conforms to offset and size requirements and
thus unexpectedly fails, hitting an assert.

This patch avoids that by checking that we can create a reference
expression to access the original data within the aggregate before
deciding to create each individual replacement.

Bootstrapped and tested on x86_64-linux.  OK for trunk?

Thanks,

Martin


2010-01-13  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/42703
	* tree-sra.c (analyze_access_subtree): Check that we can vuild a
	reference to the original data within the aggregate.

	* testsuite/gcc.c-torture/compile/pr42703.c: New test.


Index: mine/gcc/tree-sra.c
===================================================================
--- mine.orig/gcc/tree-sra.c
+++ mine/gcc/tree-sra.c
@@ -1659,7 +1659,13 @@ analyze_access_subtree (struct access *r
 
   if (allow_replacements && scalar && !root->first_child
       && (root->grp_hint
-	  || (direct_read && root->grp_write)))
+	  || (direct_read && root->grp_write))
+      /* We must not ICE later on when trying to build an access to the
+	 original data within the aggregate even when it is impossible to do in
+	 a defined way like in the PR 42703 testcase.  Therefore we check
+	 pre-emptively here that we will be able to do that.  */
+      && build_ref_for_offset (NULL, TREE_TYPE (root->base), root->offset,
+			       root->type, false))
     {
       if (dump_file && (dump_flags & TDF_DETAILS))
 	{
Index: mine/gcc/testsuite/gcc.c-torture/compile/pr42703.c
===================================================================
--- /dev/null
+++ mine/gcc/testsuite/gcc.c-torture/compile/pr42703.c
@@ -0,0 +1,12 @@
+__extension__ typedef unsigned long long int uint64_t;
+typedef uint64_t ScmUInt64;
+void swapb64(ScmUInt64 *loc) 
+{
+    union {
+        ScmUInt64 l;
+        unsigned char c[4];
+    } dd;
+    unsigned char t;
+    dd.l = *loc;
+    (t = dd.c[3], dd.c[3] = dd.c[4], dd.c[4] = t);
+}


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