Thread overview
[Issue 20812] _d_assocarrayliteralTX segfault assigning a shared associative array an AA literal
Dec 17, 2022
Iain Buclaw
Dec 17, 2022
Iain Buclaw
Jun 13, 2023
mw
Jun 14, 2023
mw
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=20812

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=20812

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
           Severity|normal                      |critical

--
June 13, 2023
https://issues.dlang.org/show_bug.cgi?id=20812

mw <mingwu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P1
                 CC|                            |mingwu@gmail.com
           Severity|critical                    |blocker

--- Comment #1 from mw <mingwu@gmail.com> ---
Encountered this bug again today with DMD64 D Compiler v2.104.0


You can also try on the run.dlang.org link, the bug still there.


Sigh, we have so many such basic bugs for more than 3 years now, with no fix.


Does anyone know how to fix it? or any work-around?


Thanks.

--
June 13, 2023
https://issues.dlang.org/show_bug.cgi?id=20812

mail@ernestocastellotti.it changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mail@ernestocastellotti.it

--- Comment #2 from mail@ernestocastellotti.it ---
I investigate this bug and the problem is that ti.key (field of
TypeInfo_AssociativeArray) is null.

The sigsegv obviously occurs at this line https://github.com/dlang/dmd/blob/342a226833a0e9c7a90bbb64ae8dc35aa6d6bfdc/druntime/src/rt/aaA.d#L766

I'm trying to figure out what the reason for this would be and how to fix it.

--
June 14, 2023
https://issues.dlang.org/show_bug.cgi?id=20812

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe, wrong-code
                 CC|                            |schveiguy@gmail.com

--- Comment #3 from Steven Schveighoffer <schveiguy@gmail.com> ---
I further diagnosed this. You don't need to declare the shared aa separately, this will do:

```d
void main() { shared aa = ["abc": "123"]; }
```

If you declare `aa` as const instead, the `ti` parameter passed to `_d_assocarrayliteralTX` is a legit `TypeInfo_AssociativeArray`. However, when you use shared, the `ti` parameter is pointing to the wrapping `TypeInfo_Shared`.

Note that this is a *reinterpret cast*, not a dynamic cast, and so it really thinks it's pointing at a `TypeInfo_AssociativeArray`. Therefore the `key` field doesn't actually exists, and is garbage.

I'm not sure on LDC if this is a similar problem but it's possible since it's reading invalid memory it happens to work? I tend to think not.

I ran on run.dlang.io for all compilers, and all segfault. So this has been happening for a while.

const, immutable, and inout all do not have this problem, only shared.

I also confirmed this is a problem on gdc.

--
June 14, 2023
https://issues.dlang.org/show_bug.cgi?id=20812

mw <mingwu@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zorael@gmail.com

--