Bug 22991 – GC array literals restricted in size

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-05T16:30:38Z
Last change time
2024-12-13T19:22:08Z
Assigned to
No Owner
Creator
kinke
Moved to GitHub: dmd#20085 →

Comments

Comment #0 by kinke — 2022-04-05T16:30:38Z
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 #2 by dkorpel — 2022-04-18T21:13:30Z
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
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20085 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB