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.
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)
little error in the reduced TC. Take this one. ---- void main() { enum string a = "a"; auto array = cast(uint[])a; } ----
another one, same problem: --- void main() { auto data = cast(const char[5][]) "qwert"; } ---
*** Issue 20319 has been marked as a duplicate of this issue. ***
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.
@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
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