Bug 24139 – 'this' corruption in extern(C++) dtor when destructing via TypeInfo_Struct

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2023-09-10T13:42:05Z
Last change time
2023-09-16T07:31:19Z
Keywords
pull
Assigned to
No Owner
Creator
kinke

Comments

Comment #0 by kinke — 2023-09-10T13:42:05Z
Iff. the struct itself has no `extern(C++)` linkage, but its destructor. E.g., the assertion in line 3 fails for 32-bit x86: ``` struct S1 { int x; extern(C++) ~this() { assert(&this == s1); } } extern(C++) struct S2 { int x; ~this() { assert(&this == s2); } } S1* s1; S2* s2; void main() { s1 = new S1; s2 = new S2; typeid(s1).destroy(s1); typeid(s2).destroy(s2); } ```
Comment #1 by dlang-bot — 2023-09-10T13:51:40Z
@kinke created dlang/dmd pull request #15598 "[stable] Fix Issue 24139 - 'this' corruption in extern(C++) dtor when destructing via TypeInfo_Struct" fixing this issue: - Fix Issue 24139 - 'this' corruption in extern(C++) dtor when destructing via TypeInfo_Struct For the `TypeInfo_Struct.xdtor` field, the linkage of the aggregate itself plays no role; it's the linkage of the destructor that matters. A real-life example for this is DMD's own `OutBuffer`. https://github.com/dlang/dmd/pull/15598
Comment #2 by dlang-bot — 2023-09-11T07:55:21Z
dlang/dmd pull request #15598 "[stable] Fix Issue 24139 - 'this' corruption in extern(C++) dtor when destructing via TypeInfo_Struct" was merged into stable: - fe46a936c9652980b2e55511542c9149f5ba93a3 by Martin Kinkelin: Fix Issue 24139 - 'this' corruption in extern(C++) dtor when destructing via TypeInfo_Struct For the `TypeInfo_Struct.xdtor` field, the linkage of the aggregate itself plays no role; it's the linkage of the destructor that matters. A real-life example for this is DMD's own `OutBuffer`. https://github.com/dlang/dmd/pull/15598
Comment #3 by dlang-bot — 2023-09-16T07:31:19Z
dlang/dmd pull request #15609 "merge stable" was merged into master: - fbafba879073b33b3d2f235b7ebd3bc3a508248d by Martin Kinkelin: Fix Issue 24139 - 'this' corruption in extern(C++) dtor when destructing via TypeInfo_Struct (#15598) For the `TypeInfo_Struct.xdtor` field, the linkage of the aggregate itself plays no role; it's the linkage of the destructor that matters. A real-life example for this is DMD's own `OutBuffer`. https://github.com/dlang/dmd/pull/15609