Comment #0 by thomas.bockman — 2019-07-10T19:52:29Z
import std.stdio;
struct Vec4 {
__vector(float[4]) raw;
this(const(float[4]) value...) inout pure @safe nothrow @nogc {
__vector(float[4]) raw;
raw[] = value[];
this.raw = raw;
}
}
void main() {
static immutable Vec4 v = Vec4( 1.0f, 2.0f, 3.0f, 4.0f );
static foreach(d; 0 .. 4)
write(v.raw[d], " ");
}
Attempting to compile the above yields "Illegal instruction (core dumped)". Removing the `static immutable` makes everything work as expected.
Comment #1 by b2.temp — 2019-07-10T22:08:54Z
Is this issue only about the crash or do you mind about the thing being accepted too ?
Preventing the crash is easy an then compiler would output
Error: slice operation `cast(__vector(float[4]))[nanF, nanF, nanF, nanF] = [1.00000F, 2.00000F, 3.00000F, 4.00000F][0..4]` cannot be evaluated at compile time
called from here: `Vec4(cast(__vector(float[4]))[nanF, nanF, nanF, nanF]).this(i)`
which is accurate. The code to handle this case is not there.
Then the issue would become an ER.
Comment #2 by dlang-bot — 2019-07-10T22:25:27Z
@Basile-z created dlang/dmd pull request #10160 "fix issue 20042 - __vector CTFE crashes the compiler" fixing this issue:
- fix issue 20042 - __vector CTFE crashes the compiler
https://github.com/dlang/dmd/pull/10160
Comment #3 by thomas.bockman — 2019-07-10T23:14:23Z
The top priority is to make sure that the compiler doesn't pretend to support operations in CTFE which don't actually work right. So, your proposal is acceptable, and definitely better than delaying action on this bug and 20041.
However, it would be nice if this actually worked, too. Seeing as the runtime in-memory layout of __vector(float[4]) and regular float[4] is identical, I'd hope that the CTFE machinery for the latter could be applied to both fairly easily.
Comment #4 by dlang-bot — 2019-07-11T08:27:05Z
dlang/dmd pull request #10160 "fix issue 20042 - __vector CTFE crashes the compiler" was merged into stable:
- cb81e3cb13bae540516636ea294a207c0d4e2ac2 by Basile Burg:
fix issue 20042 - __vector CTFE crashes the compiler
https://github.com/dlang/dmd/pull/10160
Comment #5 by dlang-bot — 2019-08-01T07:49:46Z
dlang/dmd pull request #10232 "Merge remote-tracking branch 'upstream/stable' into merge_stable" was merged into master:
- 02df7b345a359ea9109c1aa5f8043c7f5dc7b6d1 by Basile-z:
fix issue 20042 - __vector CTFE crashes the compiler (#10160)
fix issue 20042 - __vector CTFE crashes the compiler
merged-on-behalf-of: Nicholas Wilson <[email protected]>
https://github.com/dlang/dmd/pull/10232