Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #397 (new defect)

Opened 2 years ago

Last modified 2 years ago

Segfault when referencing an aliased struct-valued template through a struct variable

Reported by: Deewiant Assigned to: lindquist
Priority: major Milestone:
Component: backend Version: hg tip
Keywords: Cc:

Description

Hooray for complex bugs:

struct S { uint x; }

template MakeS(uint x) { const MakeS = S(x); }

struct S2 { alias .MakeS MakeS; }

void f() {
	S2 s2;
	auto n = s2.MakeS!(0); //////////// XXX
}
$ ldc -c arst.d
0   ldc             0x0000000000cc2bcf
1   ldc             0x0000000000cc321d
2   libpthread.so.0 0x00007f2990cdde80
3   ldc             0x0000000000645ca3 DtoIndexStruct(llvm::Value*, StructDeclaration*, VarDeclaration*) + 99
4   ldc             0x00000000005f5161 DotVarExp::toElem(IRState*) + 385
5   ldc             0x00000000005f5791 AssignExp::toElem(IRState*) + 193
6   ldc             0x0000000000616a74 DtoDeclarationExp(Dsymbol*) + 596
7   ldc             0x00000000005f2231 DeclarationExp::toElem(IRState*) + 65
8   ldc             0x000000000060475c ExpStatement::toIR(IRState*) + 108
9   ldc             0x00000000006048e7 CompoundStatement::toIR(IRState*) + 103
zsh: segmentation fault  ldc -c arst.d

The line marked XXX causes the segfault.

A workaround is to use S2.MakeS!(0) instead—i.e. access the template through the struct type instead of the variable.

This has the additional annoyance of breaking with statements in which something like MakeS is accessed from within the struct:

struct S2 {
	alias .MakeS MakeS;
	void f() {
		S2 s2;
		with (s2)
			auto n = MakeS!(0); // XXX
	}
}

The lined marked XXX would ordinarily be fine, but the with (s2) transforms it into s2.MakeS!(0) thus triggering this bug.

Change History

03/08/10 13:17:49 changed by Deewiant

This is doubly annoying now that the workaround doesn't work: see #400.

Copyright © 2008, LDC Development Team.