D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20130 - ICE when casting from string to other array type due to __ArrayCast not being written
Summary: ICE when casting from string to other array type due to __ArrayCast not being...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
: 20319 (view as issue list)
Depends on:
Blocks:
 
Reported: 2019-08-13 21:49 UTC by Remi Thebault
Modified: 2020-03-21 03:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Remi Thebault 2019-08-13 21:49:25 UTC
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 basile-z 2019-11-21 16:05:59 UTC
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 basile-z 2019-11-21 16:09:04 UTC
little error in the reduced TC. Take this one.

----
void main() {
    enum string a = "a";
    auto array = cast(uint[])a;
}
----
Comment 3 basile-z 2019-12-12 00:54:41 UTC
another one, same problem:

---
void main()
{
    auto data = cast(const char[5][]) "qwert";
}
---
Comment 4 basile-z 2019-12-12 00:55:17 UTC
*** Issue 20319 has been marked as a duplicate of this issue. ***
Comment 5 Walter Bright 2019-12-19 08:18:01 UTC
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 Dlang Bot 2020-03-18 13:18:22 UTC
@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 Dlang Bot 2020-03-19 06:31:16 UTC
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