[Issue 16400] New: naked variadic C function emits broken prologue
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Aug 17 08:03:42 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16400
Issue ID: 16400
Summary: naked variadic C function emits broken prologue
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: cauterite at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list