www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 233] New: Infinite loops with assembly crash DMD

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

           Summary: Infinite loops with assembly crash DMD
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: fvbommel wxs.nl


(Note: v0.162 isn't yet in the list of versions you can pick in Bugzilla, so I
selected 'unspecified'. But it's definitely 0.162)

This issue turned up in v0.162. Code that worked fine in v0.161 suddenly didn't
compile anymore.
Tested on both Windows & Linux.

No error is given by DMD itself.
On Windows, it says `The instruction at "0x00485bb9" referenced memory at
"0x00000030". The memory could not e "read".`
Linux, of course, just mentions `Segmentation fault`.

See comments for more details:


import std.stdio;           // for the last cases

void infiniteAsmLoops()
{

    /* This crashes DMD 0.162: */
    for (;;) asm { hlt; }

    /* It doesn't seem to matter what you use. These all crash: */
    //for (;;) asm { mov EAX, EBX; }
    //for (;;) asm { xor EAX, EAX; }
    //for (;;) asm { push 0; pop EAX; }
    //for (;;) asm { jmp infiniteAsmLoops; }

    /* This is a workaround: */
    for (bool a = true; a;) asm { hlt; }                    // compiles
    /* But this isn't: */
    //for (const bool a = true; a;) asm{ hlt; }             // crashes DMD

    /* It's not restricted to for-statements: */
    //while(1) asm { hlt; }                                 // crashes DMD
    /* This compiles: */
    {
        bool a = true;
        while(a) asm { hlt; }
    }
    /* But again, this doesn't: */
    /*
    {
        const bool a = true;    // note the const
        while(a) asm { hlt; }
    }
    //*/

    //do { asm { hlt; } } while (1);                          // crashes DMD
    /* This, of course, compiles: */
    {
        bool a = true;
        do asm { hlt; } while (a);
    }
    /* But predicably, this doesn't: */
    /*
    {
        const bool a = true;
        do asm { hlt; } while (a);
    }
    //**/

    /* Not even hand-coding the loop works: */
    /*
    {
label:
        asm { hlt; }   // commenting out this line to make it compile
        goto label;
    }
    //*/
    /* Unless you go all the way: (i.e. this compiles) */
    asm
    {
L1:
        hlt;
        jmp L1;
    }

    /* or like this (also compiles): */
    static void test()
    {
        asm { naked; hlt; jmp test; }
    }
    test();


    /* Wait... it gets weirder: */

    /* This also doesn't compile: */
    /*
    for (;;)
    {
        writef();
        asm { hlt; }
    }
    //*/
    /* But this does: */
    //*
    for (;;)
    {
        asm { hlt; }
        writef();
    }
    //*/
    /* The same loop that doesn't compile above 
     * /does/ compile after previous one:
     */
    //*
    for (;;)
    {
        writef();
        asm { hlt; }
    }
    //*/


    /* Note: this one is at the end because it seems to also trigger the
     * "now it works" event of the loop above.
     */
    /* There has to be /something/ in that asm block: */
    for (;;) asm {}                                         // compiles

}


-- 
Jul 01 2006
next sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail puremagic.com schrieb am 2006-07-01:
 http://d.puremagic.com/issues/show_bug.cgi?id=233
 (Note: v0.162 isn't yet in the list of versions you can pick in Bugzilla, so I
 selected 'unspecified'. But it's definitely 0.162)

 This issue turned up in v0.162. Code that worked fine in v0.161 suddenly didn't
 compile anymore.
 Tested on both Windows & Linux.

 No error is given by DMD itself.
 On Windows, it says `The instruction at "0x00485bb9" referenced memory at
 "0x00000030". The memory could not e "read".`
 Linux, of course, just mentions `Segmentation fault`.

 See comments for more details:


 import std.stdio;           // for the last cases

 void infiniteAsmLoops()
 {

     /* This crashes DMD 0.162: */
     for (;;) asm { hlt; }

     /* This is a workaround: */
     for (bool a = true; a;) asm { hlt; }                    // compiles
[snip] Added to DStress as http://dstress.kuehne.cn/compile/a/asm_01_A.d http://dstress.kuehne.cn/compile/a/asm_01_B.d http://dstress.kuehne.cn/compile/a/asm_01_C.d http://dstress.kuehne.cn/compile/a/asm_01_D.d http://dstress.kuehne.cn/compile/a/asm_01_E.d http://dstress.kuehne.cn/compile/a/asm_01_F.d http://dstress.kuehne.cn/compile/a/asm_01_G.d http://dstress.kuehne.cn/compile/a/asm_01_H.d http://dstress.kuehne.cn/compile/a/asm_01_I.d http://dstress.kuehne.cn/compile/a/asm_01_J.d http://dstress.kuehne.cn/compile/a/asm_01_K.d http://dstress.kuehne.cn/compile/a/asm_01_L.d http://dstress.kuehne.cn/compile/a/asm_01_M.d http://dstress.kuehne.cn/compile/a/asm_01_N.d http://dstress.kuehne.cn/compile/a/asm_01_O.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEp/JaLK5blCcjpWoRAtdLAKCiI6x6WLXn5OLb78L8YM+WRUzw4ACfZJic 8OJd4P4aijSyjGY5dtJ8QRk= =t+nF -----END PGP SIGNATURE-----
Jul 02 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=233


fvbommel wxs.nl changed:

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





This bug seems to have silently disappeared in v0.163.


-- 
Jul 24 2006