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

            Bug ID: 129279
           Summary: [14/15/16/17 Regression] wrong code at -O0: stale sp
                    offset after ms_abi shadow-space pop at EH end
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ABI, wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeffchen006 at gmail dot com
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

Tested with gcc version 17.0.0 20261203 (experimental), r17-7143-g592f605117e,
x86_64-pc-linux-gnu.

extern "C" int printf(const char *, ...);
int g;
__attribute__((ms_abi)) void f(int *p) { if (g) throw 0; }
int main() {
  alignas(32) int x = 1;
  try {
    f(&x);
    x = 2;
  } catch (...) {}
  printf("%d\n", x);
}

$ g++ -O0 t.cc && ./a.out
1
$ g++ -O2 t.cc && ./a.out
2

Expected 2 (clang: 2). -O0 and -O1 are wrong. -maccumulate-outgoing-args fixes
it.
Bisected to r8-1911-g35c95658180 ("x86: Use DRAP only if there are outgoing
arguments on stack"); its parent is fine. Without DRAP, x is addressed from the
realigned sp. main does "subq $32,%rsp" (shadow space for the ms_abi call),
"call f", "addq $32,%rsp", then "movl $2,-32(%rsp)": the store uses the sp
offset from before the pop (it must be (%rsp)). The call ends an EH region, so
the store starts a new basic block, and the sp offset after the pop is not used
for elimination there.
  • [Bug target/129279] New: [14/15/... jeffchen006 at gmail dot com via Gcc-bugs

Reply via email to