Bug 24617 – array runtime erroneously copies flags from existing block

Status
NEW
Severity
minor
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-06-18T11:56:09Z
Last change time
2024-12-07T13:43:38Z
Keywords
pull
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#17482 →

Comments

Comment #0 by schveiguy — 2024-06-18T11:56:09Z
If an array slice starts from a GC allocated block that is *not* marked appendable, the appendable flag never gets set until appending occurs. example: ```d struct S { int[1] val; } void main() { auto s = new S; int[] arr = s.val[]; assert(arr.capacity == 0); // starts out without appendability arr.length = 2; assert(arr.capacity > 0); // this fails arr.reserve(100); assert(arr.capacity > 0); // this fails arr ~= 10; assert(arr.capacity > 0); // finally, this succeeds } ``` The issue is that the `__arrayAlloc` function copies the original bits instead of using the typeinfo to decide the new array bits if a BlkInfo has already been looked up. I guess the thought is that using the TypeInfo to build the bits is more expensive, and we "already have something". Options are to just always use the typeinfo, or to check for the appendable bit before using the old bits (but copying the other bits might be questionable as well).
Comment #1 by dlang-bot — 2024-06-19T17:03:11Z
@ntrel created dlang/dmd pull request #16599 "Fix Bugzilla 24617 - array runtime erroneously copies flags from exis…" fixing this issue: - Fix Bugzilla 24617 - array runtime erroneously copies flags from existing block https://github.com/dlang/dmd/pull/16599
Comment #2 by robert.schadek — 2024-12-07T13:43:38Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17482 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB