The following fixes PR69951, hopefully the last case of decl alias
issues with alias analysis.  This time it's points-to and the DECL_UIDs
used in points-to sets not being canonicalized.

The simplest (and cheapest) fix is to make aliases refer to the
ultimate alias target via their DECL_PT_UID which we conveniently
have available.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2016-02-26  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/69551
        * tree-ssa-structalias.c (get_constraint_for_ssa_var): When
        looking through aliases adjust DECL_PT_UID to refer to the
        ultimate alias target.

        * gcc.dg/torture/pr69951.c: New testcase.

Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c  (revision 233693)
--- gcc/tree-ssa-structalias.c  (working copy)
*************** get_constraint_for_ssa_var (tree t, vec<
*** 2943,2948 ****
--- 2943,2956 ----
        if (node && node->alias && node->analyzed)
        {
          node = node->ultimate_alias_target ();
+         /* Canonicalize the PT uid of all aliases to the ultimate target.
+            ???  Hopefully the set of aliases can't change in a way that
+            changes the ultimate alias target.  */
+         gcc_assert ((! DECL_PT_UID_SET_P (node->decl)
+                      || DECL_PT_UID (node->decl) == DECL_UID (node->decl))
+                     && (! DECL_PT_UID_SET_P (t)
+                         || DECL_PT_UID (t) == DECL_UID (node->decl)));
+         DECL_PT_UID (t) = DECL_UID (node->decl);
          t = node->decl;
        }
      }
Index: gcc/testsuite/gcc.dg/torture/pr69951.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr69951.c      (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr69951.c      (working copy)
***************
*** 0 ****
--- 1,21 ----
+ /* { dg-do run } */
+ /* { dg-require-alias "" } */
+ 
+ extern void abort (void);
+ 
+ int a = 1, c = 1;
+ extern int b __attribute__((alias("a")));
+ extern int d __attribute__((alias("c")));
+ int main(int argc)
+ {
+   int *p, *q;
+   if (argc)
+     p = &c, q = &d;
+   else
+     p = &b, q = &d;
+   *p = 1;
+   *q = 2;
+   if (*p == 1)
+     abort();
+   return 0;
+ }

Reply via email to