Hi, this patch adds logic to detect cycles and cgraph and varpool aliases. Prevoiusly we just output them into asm file and let gas to complain, but now we catch ourselves in infinite loop. I assumed that this is already tested in varasm but it is not.
Bootstrapped/regtested x86_64-linux, will commit it shortly. Jan Hubicka <j...@suse.cz> Tom de Vries <t...@codesourcery.com> PR middle-end/51998 * cgraphunit.c (cgraph_analyze_function): Break cyclic aliases. * varpool.c (varpool_analyze_pending_decls): Likewise. * testsuite/gcc.dg/alias-12.c: New testcase. * testsuite/gcc.dg/alias-13.c: New testcase. Index: cgraphunit.c =================================================================== --- cgraphunit.c (revision 183757) +++ cgraphunit.c (working copy) @@ -836,6 +836,16 @@ cgraph_analyze_function (struct cgraph_n if (node->alias && node->thunk.alias) { struct cgraph_node *tgt = cgraph_get_node (node->thunk.alias); + struct cgraph_node *n; + + for (n = tgt; n && n->alias; + n = n->analyzed ? cgraph_alias_aliased_node (n) : NULL) + if (n == node) + { + error ("function %q+D part of alias cycle", node->decl); + node->alias = false; + return; + } if (!VEC_length (ipa_ref_t, node->ref_list.references)) ipa_record_reference (node, NULL, tgt, NULL, IPA_REF_ALIAS, NULL); if (node->same_body_alias) Index: testsuite/gcc.dg/alias-12.c =================================================================== --- testsuite/gcc.dg/alias-12.c (revision 0) +++ testsuite/gcc.dg/alias-12.c (revision 0) @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-require-alias "" } */ +/* { dg-options "-O2" } */ +static void f (void) __attribute__((alias("f"))); // { dg-error "part of alias cycle" "" } + +void g () +{ + f (); +} Index: testsuite/gcc.dg/alias-13.c =================================================================== --- testsuite/gcc.dg/alias-13.c (revision 0) +++ testsuite/gcc.dg/alias-13.c (revision 0) @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-require-alias "" } */ +/* { dg-options "-O2" } */ +static void f (void) __attribute__((alias("g"))); static void g (void) __attribute__((alias("f"))); // { dg-error "part of alias cycle" "" } + +void h () +{ + f (); +} Index: varpool.c =================================================================== --- varpool.c (revision 183757) +++ varpool.c (working copy) @@ -477,6 +477,16 @@ varpool_analyze_pending_decls (void) if (node->alias && node->alias_of) { struct varpool_node *tgt = varpool_node (node->alias_of); + struct varpool_node *n; + + for (n = tgt; n && n->alias; + n = n->analyzed ? varpool_alias_aliased_node (n) : NULL) + if (n == node) + { + error ("variable %q+D part of alias cycle", node->decl); + node->alias = false; + continue; + } if (!VEC_length (ipa_ref_t, node->ref_list.references)) ipa_record_reference (NULL, node, NULL, tgt, IPA_REF_ALIAS, NULL); /* C++ FE sometimes change linkage flags after producing same body aliases. */