Bug 4940 – ICE(symbol.c): Accessing tuple-typed field of struct literal with user-defined constructor

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-09-25T18:39:00Z
Last change time
2012-01-17T11:05:29Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
k.hanazuki

Comments

Comment #0 by k.hanazuki — 2010-09-25T18:39:51Z
DMD v2.049 on Windows crashes with the message: Internal error: ..\ztc\symbol.c 1043 This only occurs when accessing a tuple-typed field on a struct literal directly and using an user-defined constructor. ---- void main() { auto w = S(0).x; } template Tuple(T...) { alias T Tuple; } struct S { Tuple!(int, int) x; this(int) { } }
Comment #1 by yebblies — 2011-08-29T22:13:26Z
*** Issue 6530 has been marked as a duplicate of this issue. ***
Comment #2 by yebblies — 2011-08-29T22:13:59Z
Test case from 6530: struct S { int a, b, c; } struct HasPostblit { this(this) {} // Bug goes away without this. } auto toRandomAccessTuple(T...)(T input, HasPostblit hasPostblit) { return S(1, 2, 3); } void doStuff(T...)(T args) { HasPostblit hasPostblit; // Bug goes away without the .tupleof. auto foo = toRandomAccessTuple(args, hasPostblit).tupleof; } void main() { doStuff(1, 2, 3); }
Comment #3 by k.hara.pg — 2012-01-06T01:34:59Z
In the expression e1.tupleof, if e1 has some side effect, this problem occurs. The explanation of bug mechanism: 1. e1.tupleof is translated to e1.field0, e1.field1, ..., e1.fieldN (e1.tupleof.length == N). But if e1 has some side effect (e.g. e1 is function call), e1 is simply duplicated. funcall().tupleof -> (funcall().field0, funcall, field1, ..., funcall.fieldN) 2. Postblit call on function argument creates hidden temporary variable. toRandomAccessTuple(args, hasPostblit) -> toRandomAccessTuple(args, (auto __cpcttmp = hasPostblit, __cpcttmp)) The combination of #1 and #2 causes duplication of hidden variable like follows: toRandomAccessTuple(args, hasPostblit).tupleof -> (toRandomAccessTuple(args, (auto __cpcttmp = hasPostblit, __cpcttmp)).a, toRandomAccessTuple(args, (auto __cpcttmp = hasPostblit, __cpcttmp)).b, toRandomAccessTuple(args, (auto __cpcttmp = hasPostblit, __cpcttmp)).c) Finally the repetation of __cpcttmp cause ICE in backend.
Comment #4 by k.hara.pg — 2012-01-06T01:36:27Z
*** Issue 6729 has been marked as a duplicate of this issue. ***
Comment #5 by k.hara.pg — 2012-01-06T01:36:43Z
*** Issue 7233 has been marked as a duplicate of this issue. ***
Comment #6 by k.hara.pg — 2012-01-06T02:34:55Z
Comment #7 by bugzilla — 2012-01-17T11:05:29Z