This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR 28807 - wrong code with may_alias and structs
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 24 Aug 2006 08:15:47 -0700
- Subject: [PATCH] Fix PR 28807 - wrong code with may_alias and structs
The problem here is that access_can_touch_variable would return false
for accesses via a base which has an aliasing set of 0 which is
incorrect. Anyways this fixes the problem by checking the aliasing set
to make sure that does not happen.
I added a testcase to the testsuite for a possible missed optimization
which Daniel Berlin had caught with an earlier version of this patch.
OK? Bootstrapped and tested on i686-linux-gnu with no regressions.
Thanks,
Andrew Pinski
PS. The testcase for testing if this works fails at "-O3 -g" currently
but it is fails with an ICE which was also there before my patch. I
filed the bug under PR 28834 and also noticed it is a regression.
ChangeLog:
* tree-ssa-operands.c (access_can_touch_variable): Don't say
the access through a base which has an alias set of 0 cannot
touch the variable.
testsuite/ChangeLog:
* gcc.c-torture/execute/mayalias-2.c: New test.
* gcc.dg/tree-ssa/alias-13.c: New test.
Index: testsuite/gcc.c-torture/execute/mayalias-2.c
===================================================================
--- testsuite/gcc.c-torture/execute/mayalias-2.c (revision 0)
+++ testsuite/gcc.c-torture/execute/mayalias-2.c (revision 0)
@@ -0,0 +1,17 @@
+struct S { short x; };
+typedef struct S __attribute__((__may_alias__)) test;
+
+int f() {
+ int a=10;
+ test *p=(test *)&a;
+ p->x = 1;
+ return a;
+}
+
+int main() {
+ if (f() == 10)
+ __builtin_abort();
+ return 0;
+}
+
+
Index: testsuite/gcc.dg/tree-ssa/alias-13.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/alias-13.c (revision 0)
+++ testsuite/gcc.dg/tree-ssa/alias-13.c (revision 0)
@@ -0,0 +1,33 @@
+/* { dg-do link } */
+/* { dg-options "-O2" } */
+
+
+struct a
+{
+ char a1;
+};
+
+int *aa;
+
+void g(int *a)
+{
+ aa = a;
+ *a = 2;
+}
+
+int t(int i, struct a *b)
+{
+ g(&i);
+ b->a1 = 1;
+ i = 2;
+ if (b->a1 != 1)
+ link_failure ();
+}
+int main(void)
+{
+ struct a b;
+ t(1, &b);
+ return 0;
+}
+
+
Index: tree-ssa-operands.c
===================================================================
--- tree-ssa-operands.c (revision 116342)
+++ tree-ssa-operands.c (working copy)
@@ -1150,7 +1150,10 @@ access_can_touch_variable (tree ref, tre
|| TREE_CODE (TREE_TYPE (base)) != UNION_TYPE)
&& !AGGREGATE_TYPE_P (TREE_TYPE (alias))
&& TREE_CODE (TREE_TYPE (alias)) != COMPLEX_TYPE
- && !POINTER_TYPE_P (TREE_TYPE (alias)))
+ && !POINTER_TYPE_P (TREE_TYPE (alias))
+ /* When the struct has may_alias attached to it, we need not to
+ return true. */
+ && get_alias_set (base))
{
#ifdef ACCESS_DEBUGGING
fprintf (stderr, "Access to ");