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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1934 - ICE(e2ir.c) using static array as AA key
Summary: ICE(e2ir.c) using static array as AA key
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
: 2502 (view as issue list)
Depends on: 2954
Blocks:
Show dependency tree / graph
Reported: 2008年03月20日 02:14 UTC by david
Modified: 2014年02月16日 15:25 UTC (History)
4 users (show)

See Also:


Attachments
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 david 2008年03月20日 02:14:16 UTC
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 Don 2009年05月08日 04:58:37 UTC
*** Bug 2502 has been marked as a duplicate of this bug. ***
Comment 2 Don 2009年09月13日 11:37:06 UTC
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 Don 2009年09月14日 07:53:33 UTC
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 Fawzi Mohamed 2009年10月01日 08:21:28 UTC
*** Issue 3357 has been marked as a duplicate of this issue. ***
Comment 5 Don 2009年10月06日 00:28:16 UTC
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 Walter Bright 2009年10月13日 13:50:51 UTC
Fixed dmd 1.049


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