Bug 1934 – ICE(e2ir.c) using static array as AA key

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-03-20T02:14:00Z
Last change time
2014-02-16T15:25:50Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
davidl
Depends on
2954

Comments

Comment #0 by davidl — 2008-03-20T02:14:16Z
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=67928 He mentioned that static array can't be used as AA keys. So I tested with the newest DMD: void main() { char[char[3]] k; k["dfs"]='a'; } fails with msg: Internal error: ..\ztc\cod1.c 2529
Comment #1 by clugdbug — 2009-05-08T04:58:37Z
*** Bug 2502 has been marked as a duplicate of this bug. ***
Comment #2 by clugdbug — 2009-09-13T11:37:06Z
The original version for this bug report was 2.012, and in both D1 and D2, it used to ICE in cod1.c. (Test cases also ICEs in 1.020). It was fixed in DMD2.026, but not listed in the changelog and not fixed in D1. In recent versions of D1, it ICEs in e2ir.c. I've changed compiler version and title accordingly.
Comment #3 by clugdbug — 2009-09-14T07:53:33Z
Actually in D2 it doesn't ICE, but it generates incorrect code, because of bug 2954. D2 needs this patch, as well as a fix to bug 2954. The ICE is because e2->elem() turns the string literal into a TYarray, instead of a TYsarray, so the length is lost. This patch restores it in the case where a fixed-length array is used. PATCH against DMD1.047. =================================================================== --- e2ir.c (revision 192) +++ e2ir.c (working copy) @@ -4020,10 +4020,15 @@ // n2 becomes the index, also known as the key n2 = e2->toElem(irs); - if (n2->Ety == TYstruct || n2->Ety == TYarray) + if (tybasic(n2->Ety) == TYstruct || tybasic(n2->Ety) == TYarray) { n2 = el_una(OPstrpar, TYstruct, n2); n2->Enumbytes = n2->E1->Enumbytes; + if (taa->index->ty==Tsarray) + { + assert(e2->type->size() == taa->index->size()); + n2->Enumbytes = taa->index->size(); + } //printf("numbytes = %d\n", n2->Enumbytes); assert(n2->Enumbytes); } ========= TEST CASE (still fails on D2): void main() { char[char[3]] ac; char[3] c = "abc"; ac["abc"]='a'; assert(ac[c]=='a'); char[dchar[3]] ad; dchar[3] d = "abc"d; ad["abc"d]='a'; assert(ad[d]=='a'); }
Comment #4 by fawzi — 2009-10-01T08:21:28Z
*** Issue 3357 has been marked as a duplicate of this issue. ***
Comment #5 by clugdbug — 2009-10-06T00:28:16Z
The patch for bug 3357 should be applied at the same time, it's the other half of the same issue (the fix needs to be applied to opIn() as well as opIndex()).
Comment #6 by bugzilla — 2009-10-13T13:50:51Z
Fixed dmd 1.049