3737 – SEG-V at expression.c:6255 from bad opDispatch

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3737 - SEG-V at expression.c:6255 from bad opDispatch
Summary: SEG-V at expression.c:6255 from bad opDispatch
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 major
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
Reported: 2010年01月23日 13:03 UTC by BCS
Modified: 2015年06月09日 01:27 UTC (History)
3 users (show)

See Also:


Attachments
patch to convert seg-v to assert (915 bytes, application/octet-stream)
2010年01月23日 13:03 UTC, BCS
Details
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 BCS 2010年01月23日 13:03:57 UTC
Created attachment 554 [details] 
patch to convert seg-v to assert
I'm getting a seg-v (not an assert) at expression.c:6255 from some bad template
code.
this is the test case:
http://www.dsource.org/projects/scrapple/browser/trunk/units/si2.d?rev=689
compile with "-unittest -version=BUG" to get error
compile with "-unittest" to get correct result.
attached is a patch that converts the seg-v to an assert.
Comment 1 BCS 2010年01月23日 13:05:00 UTC
I forgot to mention; I tried to cut down the test case and it quit erroring.
Comment 2 Don 2010年01月25日 04:21:29 UTC
I can't reproduce the segfault. When compiling si2, I just get this:
------
si2.d(155): Error: Cannot interpret SIB!(__T5BatchVi1Vi1Vi0Vi1Vi0Vi1Vi0Vi1Vi0Vi1
Z,real) at compile time
si2.d(155): Error: Cannot interpret SIB!(__T5BatchVi1Vi1Vi0Vi1Vi0Vi1Vi0Vi1Vi0Vi1
Z,real) at compile time
si2.d(155): Error: template instance 'Batch!(LengthN,1,MassN,1,TimeN,1,TempN,1,C
urrentN,1)' is not a variable
si2.d(155): Error: no property 'LenD' for type 'int'
Comment 3 BCS 2010年01月25日 10:32:24 UTC
What version of DMD? I got it with 2.039 on both windows and linux. Might it already be fixed in SVN?
Comment 4 Don 2010年01月25日 12:22:35 UTC
(In reply to comment #3)
> What version of DMD? I got it with 2.039 on both windows and linux. Might it
> already be fixed in SVN?
I can reproduce it now. I think I had the wrong rational.d.
Comment 5 Don 2010年01月25日 13:01:07 UTC
Reduced test case. Something to do with opDispatch.
======================
int crayon;
struct SIB(alias junk)
{
	template Alike(V) {
		enum bool Alike = Q == V.garbage;
	}
	void opDispatch(string s)() {
		static assert(Alike!(SIB!(crayon)));
	}
}
void main() {
 SIB!(SIB!(crayon).E)(3.0);
}
Comment 6 Don 2010年01月26日 00:06:30 UTC
Cause: If global.errors && !global.gag, TemplateInstance::semantic doesn't set 'inst'. So this is a possible patch (not recommended) inside template.c:
 {
	if (!global.gag)
	{
	 /* Trying to soldier on rarely generates useful messages
	 * at this point.
	 */
	 fatal();
	}
+	inst = this; // error recovery
	return;
 }
===
But, on the other hand, most other functions in expression.c only run ti->semantic() if there are global.errors.
So this patch to expression.c line 6252 may be better:
Expression *DotTemplateInstanceExp::semantic(Scope *sc)
{
#if LOGSEMANTIC
 printf("DotTemplateInstanceExp::semantic('%s')\n", toChars());
#endif
 Expression *eleft;
 Expression *e = new DotIdExp(loc, e1, ti->name);
L1:
 e = e->semantic(sc);
 
 if (e->op == TOKdottd)
 {
+	if (global.errors) return new ErrorExp();
	DotTemplateExp *dte = (DotTemplateExp *)e;
	TemplateDeclaration *td = dte->td;
The same problem occurs in mtype.c, line 6613, 7101, inside ::dotExp(), for structs and classes, and they should probably have the same fix.
(they shouldn't be running ti->semantic() if there are global errors).
Comment 7 Walter Bright 2010年02月04日 21:10:21 UTC
changeset 367
Comment 8 Kosmonaut 2010年02月04日 22:48:30 UTC
(In reply to comment #7)
> changeset 367
http://www.dsource.org/projects/dmd/changeset/367 
Comment 9 Walter Bright 2010年03月08日 22:22:36 UTC
Fixed dmd 1.057 and 2.041


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