Bug 17287 – [ICE] backend/cgcod.c 255: zero length static arrays

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-03-30T08:57:06Z
Last change time
2019-04-12T15:02:06Z
Keywords
ice-on-valid-code
Assigned to
No Owner
Creator
Илья Ярошенко

Comments

Comment #0 by ilyayaroshenko — 2017-03-30T08:57:06Z
struct Sl { size_t a; ptrdiff_t[0] str; size_t b; this(ptrdiff_t[0] str) { } auto opIndex() { auto c = b; auto ret = Sl(str); } } dmd -m32 Internal error: backend/cgcod.c 255
Comment #1 by uplink.coder — 2017-03-30T10:53:53Z
Apparently no one has written such code. until now, otherwise this issue would have surfaced sooner. any length zero array is non-nonsensical in D.
Comment #2 by petar.p.kirov — 2017-03-30T14:38:40Z
@Stefan It easily comes up in generic code when length is based on some calculation and/or code generation via string mixins For reference see http://docs.algorithm.dlang.io/latest/mir_ndslice_slice.html#Slice and browse through the source code (https://github.com/libmir/mir-algorithm). T[0] is pretty normal if you think about it as struct S { }. If passing around structs without any members works, why wouldn't zero-sized static arrays be ok? Structs without members are invalid in C, but on the contrary are quite common in C++ and similarly D allows them for a reason. See also http://en.cppreference.com/w/cpp/language/ebo, https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html and http://dlang.org/spec/arrays.html: > A static array with a dimension of 0 is allowed, but no space is allocated for it. It's useful as the last member of a variable length struct, or as the degenerate case of a template expansion.
Comment #3 by hsteoh — 2017-03-30T19:15:32Z
I've used zero-length static arrays at the end of structs before, and they work, for the most part. I'm surprised having a zero-length member in the middle of a struct causes an ICE, though. Or is it the zero-length ctor parameter that's causing the problem?
Comment #4 by ilyayaroshenko — 2017-03-30T19:23:21Z
(In reply to hsteoh from comment #3) > I've used zero-length static arrays at the end of structs before, and they > work, for the most part. I'm surprised having a zero-length member in the > middle of a struct causes an ICE, though. Or is it the zero-length ctor > parameter that's causing the problem? It is all factors together. No one line can be removed to reduce this example.
Comment #5 by kinke — 2017-03-30T22:02:17Z
(In reply to Илья Ярошенко from comment #4) > (In reply to hsteoh from comment #3) > > I've used zero-length static arrays at the end of structs before, and they > > work, for the most part. I'm surprised having a zero-length member in the > > middle of a struct causes an ICE, though. Or is it the zero-length ctor > > parameter that's causing the problem? > > It is all factors together. No one line can be removed to reduce this > example. We've had the same issue with LDC. Zero-length static arrays are so special because they are the only type with a size of 0. Empty structs have a size of 1. If I recall correctly, we ended up ignoring zero-sized aggregate fields in the backend and passing/returning them as byte (analogous to empty structs).