D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3803 - compiler segfaults
Summary: compiler segfaults
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other Mac OS X
: P2 regression
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2010-02-14 09:27 UTC by Fawzi Mohamed
Modified: 2014-02-15 02:28 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Fawzi Mohamed 2010-02-14 09:27:53 UTC
The following (incorrect) code segfaults the compiler

I suppose that it is connected with something segfault on correct code of xf.omg.core.CoordSys and that it is connected with #3792

{{{
struct S {
    int x;

    template T(int val) {
        const P T = { val }; // the P here is an error it should be S
    }
}

template V(R,int val){
    const R V=R.T!(val);
}

const S x = V!(S,0);
}}}
Comment 1 Don 2010-02-15 01:16:22 UTC
This was a regression since 1.053. Suprisingly, it is fixed by bug 3767, in svn 367.
Comment 2 Fawzi Mohamed 2010-02-27 15:49:51 UTC
I have tried to find the problem using ldc (that shares the problem), also using the larger correct code that shows the problem (stacktraces are similar).

The problem seems to be located in expression.c:5048

		Dsymbol *s = ti->inst->toAlias();

ti->inst == NULL, so that the compiler segfaults.
In the correct code I am not sure if inst is NULL because a single pass cannot instantiate the template, or because it is in an is expression.
In any case simply catching this case and return new ErrorExp(); doesn't seem to be enough (then I have other problems).
Comment 3 Fawzi Mohamed 2010-02-28 16:02:28 UTC
a clean compile, and my fix doesn't look to bad.

klickverbot even tested dstess, and it did not make anything worse.

It might not be the correct fix, but still improves things.
{{{
diff -r 9cc791423e20 dmd/expression.c
--- a/dmd/expression.c	Thu Feb 25 17:12:54 2010 -0700
+++ b/dmd/expression.c	Sun Feb 28 23:59:36 2010 +0100
 -5946,6 +5946,7 @@
 	eleft = dte->e1;
 	ti->tempdecl = td;
 	ti->semantic(sc);
+        if (ti->inst == NULL) return new ErrorExp();
 	Dsymbol *s = ti->inst->toAlias();
 	Declaration *v = s->isDeclaration();
 	if (v)
}}}
Comment 4 Kosmonaut 2010-03-02 18:41:32 UTC
SVN commit: http://www.dsource.org/projects/dmd/changeset/404
Comment 5 Walter Bright 2010-03-08 22:23:57 UTC
Fixed dmd 1.057 and 2.041