[Issue 233] New: Infinite loops with assembly crash DMD

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 1 03:20:42 PDT 2006


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 at digitalmars.com
        ReportedBy: fvbommel at 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

}


-- 




More information about the Digitalmars-d-bugs mailing list