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

            Bug ID: 122933
           Summary: invalid epilogue for x86_64-w64-mingw32
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lh_mouse at 126 dot com
  Target Milestone: ---

```
// x86_64-w64-mingw32-g++ test.cpp -O2 -S -masm=intel

void
something_that_may_throw(void*);

int
test()
  {
    char large[500];
    something_that_may_throw(large);
    return 42;
  }
```


```
        .seh_proc       "_Z4testv"
"_Z4testv":
.LFB0:
        lea     rsp, -552[rsp]
        .seh_stackalloc 552
        .seh_endprologue
        lea     rcx, 32[rsp]
        call    "_Z24something_that_may_throwPv"
        mov     eax, 42
        lea     rsp, 552[rsp]    # <==== not allowed in epilogue
        ret
        .seh_endproc
```

Using LEA with RSP as the base pointer is prohibited; it must be `add rsp,
552`. Only LEA with RBP is allowed.

(https://learn.microsoft.com/en-us/cpp/build/prolog-and-epilog?view=msvc-170#epilog-code)
> When a frame pointer is not used, the epilog must use `add RSP,constant`
> to deallocate the fixed part of the stack. It may not use
> `lea RSP,constant[RSP]` instead. This restriction exists so the unwind
> code has fewer patterns to recognize when searching for epilogs.

Reply via email to