Bug 23805 – Runtime segmentation fault when destructor access function frame

Status
NEW
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-03-24T03:15:37Z
Last change time
2024-12-13T19:28:00Z
Keywords
pull
Assigned to
No Owner
Creator
Mathias LANG
Moved to GitHub: dmd#18160 →

Comments

Comment #0 by pro.mathias.lang — 2023-03-24T03:15:37Z
``` void main () { size_t destructionCount; struct CantDestruct { int value; ~this () { ++destructionCount; } } static void test(CantDestruct a) {} test(CantDestruct.init); } ``` This crashes with a segfault when running the program.
Comment #1 by pro.mathias.lang — 2023-03-24T12:13:03Z
As Steven Schveighoffer pointed out, this is because the context pointer is `null`. So we should probably disable `.init` for nested structures, or find a way to prevent this mistake.
Comment #2 by razvan.nitu1305 — 2023-03-28T12:15:56Z
Makes sense to me to have it error. Another incosistency: void fun(T)() { T a; } If `fun` is instantiated with DontDestruct you end up with: "Error: cannot access frame pointer of `test.main.CantDestruct`" at line "T a;". However, if you replace it with `T a = T.init` it compiles. `T a` and `T a = T.init` are exactly the same thing.
Comment #3 by dlang-bot — 2023-03-28T14:48:45Z
@RazvanN7 created dlang/dmd pull request #15046 "Fix Issue 23805 - Runtime segmentation fault when destructor access function frame" fixing this issue: - Fix Issue 23805 - Runtime segmentation fault when destructor access function frame https://github.com/dlang/dmd/pull/15046
Comment #4 by robert.schadek — 2024-12-13T19:28:00Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18160 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB