www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 324] New: DMD Optimization Bug (access violation due to bad stack pointer)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=324

           Summary: DMD Optimization Bug (access violation due to bad stack
                    pointer)
           Product: D
           Version: 0.165
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: iceelyne gmail.com


file dbug1.d

import std.stdio;
import std.process;

void[] buildKey(char[] a, int b) {
        return cast(void[])a~(cast(void*)&b)[0..4];
}

bool[void[]] reg;
void addToReg(void[] a, int b, bool v) {
        //if(!v) throw new Exception("");
        if(!v) writefln("X");
        void[] key = a~(cast(void*)&b)[0..4];
        reg[key] = v;
        writefln("OK");
}

int main(char[][] args) {
        addToReg("test", 1024, true);
        system("pause");
        return 0;
}

compile with dmd -release -O -g dbug1.d
dmd 0.163~0.166

here is some windbg view:

========
bug:

void addToReg(void[] a, int b, bool v) {
        //if(!v) throw new Exception("");
        if(!v) writefln("X");
        void[] key = a~(cast(void*)&b)[0..4];
        reg[key] = v;
        writefln("OK");
}

_D5dbug18addToRegFAvixZv:
0x00402034 83ec0c           sub         esp,0c
0x00402037 53               push        ebx
0x00402038 89442408         mov         dword ptr [esp+08],eax
0x0040203c 807c240800       cmp         byte ptr [esp+08],00
0x00402041 7520             jne         _D5dbug18addToRegFAvixZv+0000002f
(00402063)
0x00402043 ff358c504100     push        dword ptr [_TMP0+00000004 (0041508c)]
0x00402049 ff3588504100     push        dword ptr [_TMP0 (00415088)]
0x0040204f ff3514514100     push        dword ptr [_arguments_Aa+00000004
(00415114)]
0x00402055 ff3510514100     push        dword ptr [_arguments_Aa (00415110)]
0x0040205b e8c80a0000       call        _D3std5stdio8writeflnFYv (00402b28)
0x00402060 83c410           add         esp,10

;jne to here:
0x00402063 8a442408         mov         al,byte ptr [esp+08]
0x00402067 50               push        eax

;mal-manipulation of esp:
0x00402068 29dc             sub         esp,ebx
0x0040206a bb04000000       mov         ebx,00000004
;fix:
;mov ebx, 0x4
;sub esp, ebx

;access violation due to bad esp:
0x0040206f 6a01             push        01

0x00402071 8d4c2420         lea         ecx,dword ptr [esp+20]
0x00402075 51               push        ecx
0x00402076 53               push        ebx
0x00402077 ff742430         push        dword ptr [esp+30]
0x0040207b ff742430         push        dword ptr [esp+30]
0x0040207f e810080000       call        __d_arraycat (00402894)

========
ok:

void addToReg(void[] a, int b, bool v) {
        //if(!v) throw new Exception("");
        if(!v) writefln("X");
        void[] key = a~(cast(void*)&b)[0..3];
        reg[key] = v;
        writefln("OK");
}

0x00402063 8a442408         mov         al,byte ptr [esp+08]
0x00402067 bb03000000       mov         ebx,00000003
0x0040206c 50               push        eax
;
0x0040206d 83ec04           sub         esp,04
0x00402070 6a01             push        01
0x00402072 8d4c2420         lea         ecx,dword ptr [esp+20]
0x00402076 51               push        ecx
0x00402077 53               push        ebx
0x00402078 ff742430         push        dword ptr [esp+30]
0x0040207c ff742430         push        dword ptr [esp+30]
0x00402080 e80f080000       call        __d_arraycat (00402894)


-- 
Sep 05 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=324


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed in DMC 0.167.


-- 
Sep 19 2006