Hi,

Currently when we clone alias we also clone its target and create alias 
reference during alias target cloning.  This doesn't work in case alias clone 
is removed and later is re-created.  This patch moves alias reference creation 
to fix that.  Bootstrapped and tested on x86_64-unknown-linux-gnu.  Will apply 
after prerequisite patch 
(https://gcc.gnu.org/ml/gcc-patches/2015-03/msg00992.html) is applied.

Thanks,
Ilya
--
gcc/

2015-03-19  Ilya Enkovich  <ilya.enkov...@intel.com>

        * ipa-chkp.c (chkp_maybe_create_clone): Create alias
        reference when cloning alias node.

gcc/testsuite/

2015-03-19  Ilya Enkovich  <ilya.enkov...@intel.com>

        * gcc.dg/lto/chkp-removed-alias_0.c: New.


diff --git a/gcc/ipa-chkp.c b/gcc/ipa-chkp.c
index 0b857ff..bd3db5f 100644
--- a/gcc/ipa-chkp.c
+++ b/gcc/ipa-chkp.c
@@ -535,12 +535,7 @@ chkp_maybe_create_clone (tree fndecl)
 
       /* Clone all aliases.  */
       for (i = 0; node->iterate_direct_aliases (i, ref); i++)
-       {
-         struct cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
-         struct cgraph_node *chkp_alias
-           = chkp_maybe_create_clone (alias->decl);
-         chkp_alias->create_reference (clone, IPA_REF_ALIAS, NULL);
-       }
+       chkp_maybe_create_clone (ref->referring->decl);
 
       /* Clone all thunks.  */
       for (e = node->callers; e; e = e->next_caller)
@@ -563,7 +558,10 @@ chkp_maybe_create_clone (tree fndecl)
 
          ref = node->ref_list.first_reference ();
          if (ref)
-           chkp_maybe_create_clone (ref->referred->decl);
+           {
+             target = chkp_maybe_create_clone (ref->referred->decl);
+             clone->create_reference (target, IPA_REF_ALIAS);
+           }
 
          if (node->alias_target)
            {
diff --git a/gcc/testsuite/gcc.dg/lto/chkp-removed-alias_0.c 
b/gcc/testsuite/gcc.dg/lto/chkp-removed-alias_0.c
new file mode 100644
index 0000000..96d728d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/chkp-removed-alias_0.c
@@ -0,0 +1,28 @@
+/* { dg-lto-do link } */
+/* { dg-require-effective-target mpx } */
+/* { dg-lto-options { { -O2 -flto -flto-partition=max -fcheck-pointer-bounds 
-mmpx } } } */
+
+int test1 (const char *c)
+{
+  return c[0] * 2;
+}
+
+int test2 (const char *c)
+{
+  return c[1] * 3;
+}
+
+int test1_alias (const char *c) __attribute__ ((alias ("test1")));
+int test2_alias (const char *c) __attribute__ ((alias ("test2")));
+
+struct S
+{
+  int (*fnptr[2]) (const char *);
+} S;
+
+struct S s = {test1_alias, test2_alias};
+
+int main (int argc, const char **argv)
+{
+  return s.fnptr[argc] (argv[0]);
+}

Reply via email to