Bug 20130 – ICE when casting from string to other array type due to __ArrayCast not being written

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-13T21:49:25Z
Last change time
2020-03-21T03:56:31Z
Keywords
pull
Assigned to
No Owner
Creator
Remi Thebault
See also
https://issues.dlang.org/show_bug.cgi?id=20457

Comments

Comment #0 by remi.thebault — 2019-08-13T21:49:25Z
The following code crashes DMD with error 'Illegal instruction'. --- int main() { immutable array = cast(immutable(uint)[])import("12bytes.bin"); return array.length == 3 ? 0 : 1; } --- The following compiles and runs succesfully. --- int main() { immutable str = import("12bytes.bin"); immutable array = cast(immutable(uint)[])str; return array.length == 3 ? 0 : 1; } --- $ dmd --version | head -n 1 DMD64 D Compiler v2.087.1 The code worked at least up to 2.084.0.
Comment #1 by b2.temp — 2019-11-21T16:05:59Z
this is an __ArrayCast that's not written. Can be more simply reproduced with void main() { enum string a = "a"; immutable array = cast(uint[])a; } casting from strings is seriously broken (import() gives a string)
Comment #2 by b2.temp — 2019-11-21T16:09:04Z
little error in the reduced TC. Take this one. ---- void main() { enum string a = "a"; auto array = cast(uint[])a; } ----
Comment #3 by b2.temp — 2019-12-12T00:54:41Z
another one, same problem: --- void main() { auto data = cast(const char[5][]) "qwert"; } ---
Comment #4 by b2.temp — 2019-12-12T00:55:17Z
*** Issue 20319 has been marked as a duplicate of this issue. ***
Comment #5 by bugzilla — 2019-12-19T08:18:01Z
With a debug build of the compiler, this yields: core.exception.AssertError@dmd/e2ir.d(4308): This case should have been rewritten to `__ArrayCast` in the semantic phase Which shows once again the release build of dmd should NOT have asserts turned off.
Comment #6 by dlang-bot — 2020-03-18T13:18:22Z
@BorisCarvajal created dlang/dmd pull request #10941 "Fix Issue 20130 - ICE when casting from string to other array type du…" fixing this issue: - Fix Issue 20130 - ICE when casting from string to other array type due to __ArrayCast not being written https://github.com/dlang/dmd/pull/10941
Comment #7 by dlang-bot — 2020-03-19T06:31:16Z
dlang/dmd pull request #10941 "Fix Issue 20130 - ICE when casting from string to other array type du…" was merged into stable: - 8f2485277661b42be1d44236d2572a0ab7048324 by Boris Carvajal: Fix Issue 20130 - ICE when casting from string to other array type due to __ArrayCast not being written https://github.com/dlang/dmd/pull/10941