Thread overview
[Issue 19639] Initializing static array with slice enum of different length crashes the compiler
Feb 02, 2019
Neia Neutuladh
Feb 02, 2019
Neia Neutuladh
Feb 02, 2019
Neia Neutuladh
Feb 05, 2019
kinke@gmx.net
February 02, 2019
https://issues.dlang.org/show_bug.cgi?id=19639

Neia Neutuladh <dhasenan@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
                 CC|                            |dhasenan@gmail.com

--- Comment #1 from Neia Neutuladh <dhasenan@gmail.com> ---
It's a segfault, to be more specific.

Stacktrace:
__memmove_sse2_unaligned_erms () at
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:332
332     ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: Dosiero aŭ
dosierujo ne ekzistas.
(gdb) bt
#0  __memmove_sse2_unaligned_erms () at
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:332
#1  0x00005555557d5621 in castTo::CastTo::visit(StringExp*)
(this=0x7fffffffb230, e=0x555555e12100) at dmd/dcast.d:1863
#2  0x0000555555843096 in StringExp::accept(Visitor*) (this=0x555555e12100,
v=0x7fffffffb230) at dmd/expression.d:2587
#3  0x00005555557d45ff in
_D3dmd5dcast6castToFCQt10expression10ExpressionPSQBv6dscope5ScopeCQCm5mtype4TypeZQCj
(t=0x7ffff6b01790,
    sc=0x7ffff682d620, e=0x555555e12100) at dmd/dcast.d:2574
#4  0x000055555583f3c9 in Expression::castTo(Scope*, Type*)
(this=0x555555e12100, sc=0x7ffff682d620, t=0x7ffff6b01790) at
dmd/expression.d:923
#5  0x00005555557d1786 in implicitCastTo::ImplicitCastTo::visit(Expression*)
(this=0x7fffffffb3e0, e=0x555555e12100) at dmd/dcast.d:124
#6  0x00005555557d18b9 in implicitCastTo::ImplicitCastTo::visit(StringExp*)
(this=0x7fffffffb3e0, e=0x555555e12100) at dmd/dcast.d:157
#7  0x0000555555843096 in StringExp::accept(Visitor*) (this=0x555555e12100,
v=0x7fffffffb3e0) at dmd/expression.d:2587

I wasn't able to get this to work with other types of arrays. Changing from "\0" to [cast(immutable)'\0'] also made the problem go away.

--
February 02, 2019
https://issues.dlang.org/show_bug.cgi?id=19639

--- Comment #2 from Neia Neutuladh <dhasenan@gmail.com> ---
For some reason, this is doing a reinterpret cast.

It isn't documented that you can do this kind of cast into a static array. It's only mentioned for dynamic arrays to dynamic arrays.

The examples in the compiler source code (is that where we're keeping the spec these days?) explicitly involve not keeping the same length.

Similar example:

---
void main()
{
  writeln(cast(wchar[64])"hi"c);
}
---

Expected output: some sort of error about "hi" not being long enough to fill a wchar[64].

Actual output: 楨錀缳Ჰ鏌缳 ɱ荀Ű

--
February 02, 2019
https://issues.dlang.org/show_bug.cgi?id=19639

--- Comment #3 from Neia Neutuladh <dhasenan@gmail.com> ---
https://github.com/dlang/dmd/pull/9317 fixes this, but I won't be able to pursue this further, and there are associated breakages.

--
February 05, 2019
https://issues.dlang.org/show_bug.cgi?id=19639

kinke@gmx.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice-on-invalid-code         |ice-on-valid-code
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from kinke@gmx.net ---
This is apparently valid code since v2.066, as is `char[64] = "abc"`. - https://github.com/dlang/dmd/pull/9321 fixes the segfault and a read-beyond-buffer bug.

--