Bug 3192 – Segfault(iasm.c) asm in a anonymous delegate
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2009-07-19T16:38:00Z
Last change time
2014-04-18T09:12:04Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
lifc0
Comments
Comment #0 by lifc0 — 2009-07-19T16:38:57Z
below lines crash dmd 1.046/2.031 on linux and window platfrom:
void func (void delegate () callback) {
callback();
}
void main () {
func(() { asm{ int 3; }; });
}
Comment #1 by clugdbug — 2009-07-20T00:26:41Z
Reduced test case:
void delegate () foo = (){ asm{ int 3; }};
This is segfaulting in iasm.c (line 4269 in DMD2).
if( sc->func->type->nextOf()->isScalar()) // segfaults here: nextOf() is null.
Comment #2 by clugdbug — 2009-07-20T00:50:55Z
This patch is enough to fix the segfault, and allow the code to compile. I'm not sure if it's correct that nextOf() is null, though -- there may be a deeper problem here.
iasm.c line 4269. (in Statement *AsmStatement::semantic(Scope *sc)):
asmstate.bReturnax = 1;
- if (sc->func->type->nextOf()->isscalar())
+ if (sc->func->type->nextOf() && sc->func->type->nextOf()->isscalar())
asmstate.bReturnax = 0;
Comment #3 by bugzilla — 2009-07-20T02:24:23Z
For inferring function return type, the nextOf() is null. That would be a problem here, but we never use bReturnax anyway, so just #if out the code.
Comment #4 by clugdbug — 2009-07-20T02:38:02Z
(In reply to comment #3)
> For inferring function return type, the nextOf() is null.
It'd be great if you could put that in a comment in the definition of nextOf(). I'd never been sure when it's supposed to be non-null, it's one of the least obvious things in the code. Should it become non-null in a later semantic pass?
Also a comment about the cto, ito, sto members of type would be really useful. When should they be non-null?
In a great many of the compiler bugs I've looked at, they're null, but I've not been sure whether the bug is that they're null, or that other code is not dealing with the case that they're null.