www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13147] New: Wrong codegen for thisptr in naked extern (C++)


          Issue ID: 13147
           Summary: Wrong codegen for thisptr in naked extern (C++)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: me philpax.me

Naked extern (C++) methods are missing "mov [EBP-4], ECX", resulting in a
failed invariant assertion ('null this'). This appears to be because the
instruction to load [EBP-4] with ECX is treated as part of the stack frame.
While it is expected that a stack frame is set up by the user in a naked
function, the invariant is tested before my inline assembly preventing me from
doing so.

This means that anything to do with 'this' in a naked extern (C++) fails to
work, as D looks for 'this' in the untouched [EBP-4]. A test case is below:

class Test
    extern (C++) Test test()
        asm { naked; }
        return this;

When the above function is disassembled, the mov [EBP-4], ECX instruction will
be missing. When run, it will assert with "null this".

A related issue appears to be https://issues.dlang.org/show_bug.cgi?id=2350.

Jul 16 2014