https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127526

            Bug ID: 127526
           Summary: ICE: segfault in symtab_node::resolve_alias after
                    diagnosing a weakref/alias cycle
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: error-recovery, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: captainnemo9292 at gmail dot com
  Target Milestone: ---
            Target: x86_64-linux-gnu

When a weakref or alias chain loops back on itself, the front end emits the
right diagnostics ("'weakref' symbol 'g1' ultimately targets itself",
"variable 'g1' part of alias cycle") but the symbol table still contains the
cycle, and resolve_alias then walks it during analyze.

Self-targeting weakref:

  static int w __attribute__((weakref("g1")));
  extern int g1 __attribute__((weakref("g1")));
  extern int a __attribute__((alias("w")));

  $ gcc -c t.c
  t.c:2:12: error: 'weakref' symbol 'g1' ultimately targets itself
  t.c:2:12: error: 'weakref' symbol 'g1' must have static linkage
  t.c:2:12: error: variable 'g1' part of alias cycle
  cc1: internal compiler error: Segmentation fault
  varpool_node::analyze()
  symbol_table::finalize_compilation_unit()
  https://godbolt.org/z/bde7rbnPv

Two-function alias/weakref cycle:

  int f0() __attribute__((alias("f1")));
  int f1() __attribute__((weakref("f0")));
  int a() __attribute__((weakref("f1")));

  t.c:2:5: error: function 'f1' part of alias cycle
  t.c:3:5: internal compiler error: Segmentation fault
  cgraph_node::analyze()
  https://godbolt.org/z/a6T5EK6sh

Related inputs that get further but still ICE on the unresolved cycle:

  extern int g0 __attribute__((alias("")));      /* empty target */
  int g0 __attribute__((weakref));
  extern int g0 __attribute__((alias("g0")));
  -O2: internal compiler error: in get, at cgraph.h:3128 (varpool_node::get
from resolve_alias)
  https://godbolt.org/z/v7M5fGev5

  int g0; int g1; static int g1 = 4;
  extern int g1 __attribute__((alias("g0")));
  int a() { int b = g1; }
  extern int g0 __attribute__((alias("g1")));
  internal compiler error: in ctor_for_folding, at varpool.cc:445
(get_symbol_constant_value while gimplifying a)
  https://godbolt.org/z/sz8ojdz4h

gcc trunk 17.0.0 20260920; the first two also segfault in gcc 13.

Reply via email to