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

            Bug ID: 125526
           Summary: asm goto + thread_local "m" input + noreturn branch:
                    wrong code (-O1), ICE in calc_dfs_tree (-O2)
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: agri at akamo dot info
  Target Milestone: ---

Created attachment 64599
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64599&action=edit
reproducing program

Summary:
  A specific combination of asm volatile goto features causes wrong code
  generation at -O1 and an ICE at -O2 on x86-64.

  Trigger requires all five of:
    1. Early `if (!p) return false` before any stack allocation
    2. thread_local variable as "m" asm input (plain global does not trigger)
    3. asm volatile goto with "+m" output and conditional jump to a label
    4. if (asm_output == 0) noreturn_fn() after the asm
    5. Identical expression on both the fall-through and the asm-goto target
paths

  Observed behavior:
    GCC 14.2 -O1: wrong code — lab_abort label merged with early-return label
                 (before prologue); `ret` pops local variable instead of return
                 address → segfault at runtime
    GCC 16.1 -O1: correct output, no crash
    GCC 16.1 -O2: ICE — internal compiler error in calc_dfs_tree,
dominance.cc:458

  Expected behavior:
    Compiles and runs correctly at all optimization levels (clang 22.1.0 -O2:
correct)

Reply via email to