Bug 23982 – segfault when printing scope inference failure
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-06-09T18:38:58Z
Last change time
2023-07-02T13:41:42Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis
Comments
Comment #0 by dkorpel — 2023-06-09T18:38:58Z
```D
// REQUIRED_ARGS: -preview=dip1000
@safe:
struct B()
{
this(int* a)
{
this.a = a;
}
int* a;
}
class C()
{
int* foo2(int* a)
{
auto b = B!()(a);
return b.a;
}
}
void main()
{
scope int* a;
C!() c;
c.foo2(a);
}
```
Results in a segmentation fault.
The expression `this.a = a;` gets put into the `EscapeState.scopeInferFailure` associative array, but by the time it gets read in `printScopeFailure`, the class instance is corrupted: the vtable is 0x000000000000005F. This suggests it gets freed, even while the AA still has a reference to it.
Comment #1 by dlang-bot — 2023-06-16T12:32:16Z
@dkorpel created dlang/dmd pull request #15329 "Fix 23982 - segfault when printing scope inference failure" fixing this issue:
- Fix 23982 - segfault when printing scope inference failure
https://github.com/dlang/dmd/pull/15329
Comment #2 by dlang-bot — 2023-06-18T10:24:47Z
dlang/dmd pull request #15329 "Fix 23982 - segfault when printing scope inference failure" was merged into stable:
- 37ac2fd8790bf8d1ce60f54b596a5ba35225f52c by Dennis Korpel:
Fix 23982 - segfault when printing scope inference failure
https://github.com/dlang/dmd/pull/15329
Comment #3 by dlang-bot — 2023-07-02T13:41:42Z
dlang/dmd pull request #15373 "merge stable" was merged into master:
- 17facd1dc5dca4ad323044c973a1208d790ea9dc by Dennis:
Fix 23982 - segfault when printing scope inference failure (#15329)
https://github.com/dlang/dmd/pull/15373