Bug 233 – Infinite loops with assembly crash DMD

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2006-07-01T05:20:00Z
Last change time
2014-02-15T13:21:08Z
Keywords
ice-on-valid-code
Assigned to
bugzilla
Creator
fvbommel

Comments

Comment #0 by fvbommel — 2006-07-01T05:20:40Z
(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 }
Comment #1 by fvbommel — 2006-07-24T09:58:26Z
This bug seems to have silently disappeared in v0.163.