www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16400] New: naked variadic C function emits broken prologue


          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 puremagic.com
          Reporter: cauterite 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;
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

Aug 17 2016