Skip to content

array runtime erroneously copies flags from existing block #1769

Open
@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

Steven Schveighoffer reported this on 2024-06-18T11:56:09Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24617

Description

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions