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] FIx PR 28812, wrong code with strict aliasing, struct and mayalias


On Thu, 2006-11-09 at 20:13 -0800, Andrew_Pinski@PlayStation.Sony.Com
wrote:
> Hi,
>   The problem here is that we decide that the struct (whos aliasing set is 
> 0) set cannot 
> interfer with the access to the local variable.  This is wrong because the 
> aliasing set of the memory
> access of the struct so we know it can interfer with the local variable. 
> This problem is like mayalias-2.c
> which caused a problem on the tree level but this causes a problem for the 
> RTL level.
> 
> This patch fixes the problem by checking if the aliasing set of the struct 
> memory access is not 0.
> 
> OK? Bootstrapped and tested on i686-linux-gnu with no regressions.


Applied the following patch after approve from Daniel Berlin on IRC and
the suggested change of moving the check of MEM_ALIAS_SET up to the
beginning of the if.

Thanks,
Andrew Pinski


ChangeLog:

	* alias.c (fixed_scalar_and_varying_struct_p): Don't return a
	non null value if the struct memory access is in the 0th
	aliasing set.


        * gcc.c-torture/execute/mayalias-3.c: New test.
Index: alias.c
===================================================================
--- alias.c	(revision 118681)
+++ alias.c	(working copy)
@@ -1857,13 +1857,15 @@ fixed_scalar_and_varying_struct_p (rtx m
   if (! flag_strict_aliasing)
     return NULL_RTX;
 
-  if (MEM_SCALAR_P (mem1) && MEM_IN_STRUCT_P (mem2)
+  if (MEM_ALIAS_SET (mem2)
+      && MEM_SCALAR_P (mem1) && MEM_IN_STRUCT_P (mem2)
       && !varies_p (mem1_addr, 1) && varies_p (mem2_addr, 1))
     /* MEM1 is a scalar at a fixed address; MEM2 is a struct at a
        varying address.  */
     return mem1;
 
-  if (MEM_IN_STRUCT_P (mem1) && MEM_SCALAR_P (mem2)
+  if (MEM_ALIAS_SET (mem1)
+      && MEM_IN_STRUCT_P (mem1) && MEM_SCALAR_P (mem2)
       && varies_p (mem1_addr, 1) && !varies_p (mem2_addr, 1))
     /* MEM2 is a scalar at a fixed address; MEM1 is a struct at a
        varying address.  */
Index: testsuite/gcc.c-torture/execute/mayalias-3.c
===================================================================
--- testsuite/gcc.c-torture/execute/mayalias-3.c	(revision 0)
+++ testsuite/gcc.c-torture/execute/mayalias-3.c	(revision 0)
@@ -0,0 +1,27 @@
+struct S { short x; };
+typedef struct S __attribute__((__may_alias__)) test;
+
+test *p;
+
+int g(int *a)
+{
+ p = (test*)a;
+}
+
+int f()
+{
+  int a;
+  g(&a);
+  a = 10;
+  test s={1};
+  *p=s;
+  return a;
+}
+
+int main() {
+  if (f() == 10)
+    __builtin_abort();
+  return 0;
+}
+
+

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