This segfaults at runtime with DMD v2.099.0 on Linux:
```
struct S {
void[32 * 1_048_576] bla;
}
public S* deserializeFull(int i) {
return &[ getS(i) ][0];
}
S getS(int i) {
if (i != 0)
throw new Exception("blub");
return S();
}
void main(string[] args) {
deserializeFull(cast(int) args.length);
}
```
Works fine with LDC.
DMD's glue layer apparently creates the literal as a static array on the stack, before moving it to the GC allocation. This came up in https://github.com/dlang/dmd/pull/13951.
Comment #1 by ibuclaw — 2022-04-06T09:04:39Z
(In reply to kinke from comment #0)
> public S* deserializeFull(int i) {
> return &[ getS(i) ][0];
> }
Related example:
public S[int] deserializeFull2 ()
{
return [0:getS()];
}
Comment #3 by stanislav.blinov — 2022-04-18T22:40:33Z
(In reply to Dennis from comment #2)
> Note that the spec currently says:
>
> > The total size of a static array cannot exceed 16Mb.
>
Sounds like a totally arbitrary rule that has no good reason to exist. One could argue, perhaps, for guaranteeing a certain size that all implementations should provide (i.e. no less than), but setting a hard absolute limit in the spec? Dubious.
Comment #4 by ibuclaw — 2022-04-19T07:38:42Z
(In reply to Dennis from comment #2)
> Note that the spec currently says:
>
> > The total size of a static array cannot exceed 16Mb.
>
> https://dlang.org/spec/arrays.html#static-arrays
>
> But `bla` is 32Mb
That's true for Optlink, but not others, where the max static data size allowed is half the address space.
Comment #5 by kinke — 2022-04-26T11:44:42Z
(In reply to Dennis from comment #2)
> Note that the spec currently says:
>
> > The total size of a static array cannot exceed 16Mb.
>
> https://dlang.org/spec/arrays.html#static-arrays
>
> But `bla` is 32Mb
[I've only used the static array to easily create a huge struct. A struct size isn't restricted.]
Comment #6 by robert.schadek — 2024-12-13T19:22:08Z