www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19974] New: [Reg 2.086] changed naked asm parameter offsets

https://issues.dlang.org/show_bug.cgi?id=19974

          Issue ID: 19974
           Summary: [Reg 2.086] changed naked asm parameter offsets (no
                    more frame pointer assumed)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: code dawg.eu

cat > asm.d << CODE
extern (C++):

void too_many_symbols()
{
    assert(0, "Failed");
}

int insidx(char *p,uint index)
{
    asm
    {
        naked                           ;
        mov     EAX,index - [ESP+4]     ;
        mov     ECX,p - [ESP+4]         ;
        cmp     EAX,0x7F                ;
        jae     L1                      ;
        mov     [ECX],AL                ;
        mov     EAX,1                   ;
        ret                             ;


    L1:                                 ;
        cmp     EAX,0x7FFF              ;
        ja      L2                      ;

        mov     [ECX+1],AL              ;
        or      EAX,0x8000              ;
        mov     [ECX],AH                ;
        mov     EAX,2                   ;
        ret                             ;
    }
    L2:
        too_many_symbols();
}

extern(D) void main()
{
    char[16] buf;
    insidx(buf.ptr, 1);
    assert(buf[0] == 1);
}
CODE
dmd.exe -m32 -run asm.d

Introduced by https://github.com/dlang/dmd/pull/9620
(0f66ef166fe6604754f20bc4424ad06c087df26e) on purpose. This change sets up
frame pointers only if necessary and thus affects the parameter offset
computation in naked asm functions.

2.085.1 works:

        assume  CS:?insidx  YAHPADI Z
L0:             mov     EAX,8[ESP]
                mov     ECX,4[ESP]
                cmp     EAX,07Fh

2.086.0 fails:

        assume  CS:?insidx  YAHPADI Z
L0:             mov     EAX,4[ESP]
                mov     ECX,[ESP]
                cmp     EAX,07Fh

--
Jun 16 2019