1586 – DMD and GDC segfaults on incomplete code segment.

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1586 - DMD and GDC segfaults on incomplete code segment.
Summary: DMD and GDC segfaults on incomplete code segment.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
Reported: 2007年10月16日 12:06 UTC by Hoyt Koepke
Modified: 2015年06月09日 01:14 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Hoyt Koepke 2007年10月16日 12:06:31 UTC
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
Comment 2 Brad Roberts 2007年10月28日 04:10:17 UTC
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 david 2007年12月14日 00:30:40 UTC
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.
Comment 4 Don 2009年05月07日 02:21:15 UTC
Fixed in DMD2.028; not yet in D1.
Comment 5 Don 2009年05月14日 01:20:36 UTC
Fixed DMD2.028 and 1.045.


AltStyle によって変換されたページ (->オリジナル) /