Bug 16400 – naked variadic C function emits broken prologue

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2016-08-17T15:03:42Z
Last change time
2020-08-15T13:36:53Z
Keywords
iasm, pull, wrong-code
Assigned to
No Owner
Creator
Cauterite

Comments

Comment #0 by cauterite — 2016-08-17T15:03:42Z
extern(C) void f(int, ...) { asm {naked; ret;}; }; void main() { assert(*(cast(ubyte*) &f) == 0xc3); // fails f(0); // corrupts the stack }; -------------------------- The generated instructions in `f` are: lea eax, [ebp+0C]; mov [ebp-4], eax; ret; which is obviously wrong, since it's supposed to be a naked function, and it has no business reading the previous stack frame's EBP. Note that if you give `f` fixed arity `extern(C) void f(int)` there is no problem.
Comment #1 by dlang-bot — 2020-08-11T09:54:19Z
@WalterBright created dlang/dmd pull request #11550 "fix Issue 16400 - naked variadic C function emits broken prologue" fixing this issue: - fix Issue 16400 - naked variadic C function emits broken prologue https://github.com/dlang/dmd/pull/11550
Comment #2 by dlang-bot — 2020-08-12T09:06:27Z
dlang/dmd pull request #11550 "fix Issue 16400 - naked variadic C function emits broken prologue" was merged into stable: - 2b14364e0ca5044385df6c3c771b14f6923a831d by Walter Bright: fix Issue 16400 - naked variadic C function emits broken prologue https://github.com/dlang/dmd/pull/11550
Comment #3 by dlang-bot — 2020-08-15T13:36:53Z
dlang/dmd pull request #11576 "Merge stable into master" was merged into master: - 07e354a5b3955691f6692105b2b13d0bec994cb7 by Walter Bright: fix Issue 16400 - naked variadic C function emits broken prologue https://github.com/dlang/dmd/pull/11576