Bug 24157 – [REG2.105] class `this` as lvalue leads to memory corruption

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-09-25T16:29:34Z
Last change time
2023-11-27T11:54:11Z
Assigned to
No Owner
Creator
kinke
See also
https://issues.dlang.org/show_bug.cgi?id=24024

Comments

Comment #0 by kinke — 2023-09-25T16:29:34Z
This assertion fails since v2.105: ``` class Promise { auto ref unshared() shared { return cast() this; } } pragma(msg, typeof(&Promise.unshared)); void smashStack() { char[64] blub; } void main() { shared p = new Promise; Promise* u = &p.unshared(); smashStack(); assert(*u is cast() p); } ``` Almost certainly introduced by the (IMO totally controversial) https://github.com/dlang/dmd/pull/15389.
Comment #1 by kinke — 2023-09-25T18:07:28Z
Interestingly, this does NOT return a ref (the correct thing to do - the `this` class ref is passed in a CPU register): ``` class Promise { auto ref unshared() { return this; } } ```
Comment #2 by dlang-bot — 2023-09-28T19:35:18Z
@kinke created dlang/dmd pull request #15637 "Revert "fix Issue 24024 - cannot pass class this to ref class"" mentioning this issue: - Add test case for Issue 24157 - [REG2.105] class `this` as lvalue leads to memory corruption https://github.com/dlang/dmd/pull/15637
Comment #3 by dlang-bot — 2023-11-01T19:13:40Z
dlang/dmd pull request #15637 "[stable] Revert "fix Issue 24024 - cannot pass class this to ref class"" was merged into stable: - a88677ace1b9e3f925c332b7ad10d2ac095e6c09 by Martin Kinkelin: Add test case for Issue 24157 - [REG2.105] class `this` as lvalue leads to memory corruption https://github.com/dlang/dmd/pull/15637
Comment #4 by razvan.nitu1305 — 2023-11-23T11:42:51Z