Bug 1586 – DMD and GDC segfaults on incomplete code segment.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-10-16T12:06:00Z
Last change time
2015-06-09T01:14:18Z
Keywords
ice-on-invalid-code, patch
Assigned to
bugzilla
Creator
hoytak
Comments
Comment #0 by hoytak — 2007-10-16T12:06:31Z
Hello,
A typo revealed a way to make the compiler segfault. Trying to compile the following incomplete code segment as a complete module causes the official D compiler (versions 1.022 and 2.005) and GDC 0.24 to segfault.
////////////
module badcode;
void myFunc()
{
auto func = &NotHere!(1).Bar!(k); // NotHere is not defined.
}
/////////////
Thanks!
--Hoyt
The segv is in this code:
Expression *DotTemplateInstanceExp::semantic(Scope *sc)
...
if (!s2)
{ error("template identifier %s is not a member of %s %s", id->toChars(), s->kind(), s->ident ? s->ident->toChars() : "(null)");
goto Lerr;
}
...
s->ident is null, so s->ident->toChars() is invalid. I added the ?: expression to validate that, and here's the resulting error message:
/home/braddr/sandbox/d/bugs/bug1586.d:5: template instance identifier 'NotHere' is not defined
/home/braddr/sandbox/d/bugs/bug1586.d:5: Error: template identifier Bar is not a member of template instance (null)
My fix is wrong, but hopefully this will save Walter a few minutes of narrowing down.
Comment #3 by davidl — 2007-12-14T00:30:40Z
While I enjoy another fix:
if (!s2)
{
if(s->ident)
error("template identifier %s is not a member of %s %s", id->toChars(),
s->kind(), s->ident->toChars() : "(null)");
goto Lerr;
}
Since the Template Instance is unknown so this error message is useless.