Bug 15607 – [ICE] CTFE internal error: bad compare on accessing default-initialized static immutable array of array

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-25T20:52:00Z
Last change time
2017-08-02T08:07:02Z
Keywords
ice, ice-on-valid-code
Assigned to
nobody
Creator
mathias.lang

Comments

Comment #0 by mathias.lang — 2016-01-25T20:52:07Z
The following code: ``` private static immutable char[2][ubyte.max + 1] code_base = [ 0: "??" ]; static assert(code_base[0] == "??"); static assert(code_base[1] == typeof(code_base[1]).init); ``` results in: crash.d(3): Error: CTFE internal error: bad compare [email protected](1367): Assertion failure ---------------- ??:? _d_assert [0x6cb907] ??:? void ddmd.ctfeexpr.__assert(int) [0x4f53b4] This is just a manifestation of what I believe is a wider bug. E.g. the following: ``` private static immutable char[2][ubyte.max + 1] code_base; static assert(code_base[1] == typeof(code_base[1]).init); ``` Results in: ``` crash.d(3): Error: static variable code_base cannot be read at compile time crash.d(3): while evaluating: static assert(code_base[1] == ['\xff', '\xff']) ``` Tested with 2.066, 2.069 and master (DMD64 D Compiler v2.069-devel-1adb2f0) And it's a D1 regression ;)
Comment #1 by destructionator — 2016-01-25T21:49:45Z
That's an associative array literal which you are trying to assign to a static array... it should be a type error, but not a ctfe error.
Comment #2 by mathias.lang — 2016-01-25T21:54:58Z
Comment #3 by destructionator — 2016-01-25T21:57:23Z
Wow, I had no idea! Wild.
Comment #4 by clugdbug — 2016-01-27T11:46:25Z
Yeah, I had no idea this existed, either. There are *no tests* in the CTFE test suite for static initialization of static arrays with index specified! There is code for struct static initializers, but not for these beasts. So I guess this is a weird case which CTFE has never implemented at all. Quite possibly the semantic pass is leaving it as an AA literal (but marked as a static array type) instead of converting it to an actual array literal.
Comment #5 by mathias.lang — 2016-01-27T11:52:11Z
I just used that syntax because it is how it's defined in the original code. However, it isn't related to this syntax, sorry if it induced confusion. This segv all the same: ``` private static immutable char[2][ubyte.max + 1] code_base = [ "??" ]; ``` and so does: ``` private static immutable char[2][ubyte.max + 1] code_base = [ [ '?', '?' ] ]; ``
Comment #6 by public — 2016-04-29T13:29:37Z
Worth noting that after switching to DDMD this crashes without even printing assertion, just plain segfaults.
Comment #7 by bugzilla — 2016-05-20T04:43:46Z
(In reply to Mathias Lang from comment #5) > This segv all the same: > > ``` > private static immutable char[2][ubyte.max + 1] code_base = [ "??" ]; > ``` > > and so does: > > ``` > private static immutable char[2][ubyte.max + 1] code_base = [ [ '?', '?' ] ]; > `` Neither of these seg fault when I put them in a file and compile them.
Comment #8 by bugzilla — 2016-05-20T08:11:40Z
Comment #9 by github-bugzilla — 2016-06-26T13:31:14Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/9394bf6e4c017aa9f3008f8bbb3594c04ab5e292 fix Issue 15607 - [ICE] CTFE internal error: bad compare on accessing default-initialized static immutable array of array https://github.com/dlang/dmd/commit/8e4947ff5a80fbf2b0b34b2025a75cd9774b252a Merge pull request #5796 from WalterBright/fix15607 fix Issue 15607 - [ICE] CTFE internal error: bad compare on accessing default-initialized static immutable array of array
Comment #10 by github-bugzilla — 2016-10-01T11:47:03Z
Comment #11 by github-bugzilla — 2017-08-02T08:07:02Z