3336 – ICE(glue.c) declaring AA with tuple key, only with -g

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3336 - ICE(glue.c) declaring AA with tuple key, only with -g
Summary: ICE(glue.c) declaring AA with tuple key, only with -g
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, ice-on-invalid-code, patch
Depends on:
Blocks:
Reported: 2009年09月20日 21:16 UTC by Bernard Helyer
Modified: 2014年02月15日 13:13 UTC (History)
3 users (show)

See Also:


Attachments
Source file that causes compiler to crash. (3.25 KB, application/octet-stream)
2009年09月20日 21:17 UTC, Bernard Helyer
Details
Entire project, run make; should fail with same assertion as before. (195.88 KB, application/octet-stream)
2009年09月22日 08:43 UTC, Bernard Helyer
Details
Show Obsolete (2) 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 Bernard Helyer 2009年09月20日 21:16:10 UTC
File is attached. You don't need to be able to link (and won't be able to), but compiling it with `dmd main.d -c -g` causes an assertion failure:
 $ dmd main.d -c -g
 dmd: glue.c:958: virtual unsigned int Type::totym(): Assertion `0' failed.
 Aborted
However, using `-gc` works fine:
 $ dmd main.d -c -gc
 $
Comment 1 Bernard Helyer 2009年09月20日 21:17:45 UTC
Created attachment 462 [details] 
Source file that causes compiler to crash.
Main entry to my roguelike; the context is not important.
Comment 2 Don 2009年09月22日 06:16:01 UTC
This cannot be compiled. It imports a whole bunch of files which are not attached.
Please provide a complete test case.
Comment 3 Bernard Helyer 2009年09月22日 06:38:05 UTC
Oops, sorry I didn't think that through. 
Okay, rolling back to the commit that triggered the bug... and it's no longer triggered (and it was reliably when I submitted it). Nevermind, 'cannot reproduce' I guess. Bizarre.
Comment 4 Don 2009年09月22日 07:06:43 UTC
If it's like the other ICE(glue.c) bug which is currently open, it might be compile-order dependent. Otherwise, please close as invalid.
Comment 5 Bernard Helyer 2009年09月22日 07:17:50 UTC
Jimmied around a bit; no luck. If it comes up again I'll pay closer attention.
Comment 6 Bernard Helyer 2009年09月22日 08:43:46 UTC
Created attachment 463 [details] 
Entire project, run make; should fail with same assertion as before.
I figured it out; I had uncommited changes which I had reverted to post the project -- once I re-added them, the problem came back. In level.d:
alias TypeTuple!(int, int) Coordinate;
...
 Creature[Coordinate] mCreatureMap; // <-- Remove this line and the compiler doesn't crash.
Comment 7 Don 2009年09月23日 00:38:42 UTC
I reduced that 1MB test case down to 3 lines <g>:
template Tuple(T...){
 alias T Tuple;
}
int[ Tuple!(int) ] foo;
---------
Segfaults on D1, as well; also happens on Windows as well as Linux.
Curiously, this didn't segfault on 1.010 and earlier, but segfaults on 1.020. But I believe it was bad code generation on those early compilers, so not a regression.
Comment 8 Don 2009年09月23日 00:39:21 UTC
Comment on attachment 463 [details] 
Entire project, run make; should fail with same assertion as before.
This attachment is now obsolete.
Comment 9 Don 2009年09月23日 05:52:50 UTC
This is ice-on-invalid: the key of an AA must be a type. Although the declaration is accepted when the -g flag isn't used, that's also a bug. It's pretty meaningless -- there's no way to put anything into the AA! The declaration should be rejected.
Comment 10 Don 2009年09月24日 00:45:31 UTC
PATCH: This is very easy. Just disallow tuples as AA keys.
In mtype.c, in Type *TypeAArray::semantic(Loc loc, Scope *sc), at line 3293:
 switch (index->toBasetype()->ty)
 {
	case Tbool:
	case Tfunction:
	case Tvoid:
	case Tnone:
+	case Ttuple:
	 error(loc, "can't have associative array key of %s", index->toBasetype()->toChars());
	 break;
 }
And here's a test case for the test suite. Should compile without error.
---
template Tuple(T...){
 alias T Tuple;
}
// Bugzilla 3336
static assert(!is(int[ Tuple!(int, int) ]));
Comment 11 Walter Bright 2009年10月06日 02:18:55 UTC
Fixed dmd 1.048 and 2.033


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