Bug 22124 – Corrupted closure when compiling with -preview=dip1000
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-07-14T07:47:26Z
Last change time
2021-08-23T09:12:44Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
Vladimir Panteleev
Comments
Comment #0 by dlang-bugzilla — 2021-07-14T07:47:26Z
The following program will segfault when compiled with -preview=dip1000, but not otherwise:
/////////////// test.d //////////////
import core.thread;
static import std.parallelism; // ???
struct Elem
{
uint[16] pad;
}
Elem[] arr;
void main(string[] args)
{
arr = new Elem[1];
fun1();
}
void fun1()
{
fun2();
}
void fun2()
{
fun3();
}
void fun3()
{
foreach (ref elem; arr)
fun4(elem);
}
void fun4(ref Elem elem)
{
auto pelem = &elem;
auto thread = new Thread({
assert(&elem is pelem);
});
thread.start();
}
/////////////////////////////////////
Comment #1 by dlang-bugzilla — 2021-07-14T07:49:21Z
(In reply to Vladimir Panteleev from comment #0)
> The following program will segfault
Assert, not segfault.
Comment #2 by dkorpel — 2021-07-14T13:33:59Z
Probably a combination of issue 20150 and/or issue 21912.
See also my thread example in: https://forum.dlang.org/thread/[email protected]
A closure should be created on the heap for the stackframe of fun4, but dmd doesn't do that because Thread's constructor is `pure` so the delegate becomes `scope`. We can make the parameter in the constructor explicitly `return scope`, but considering issue 21912, that might not be enough.
Comment #3 by dlang-bot — 2021-07-15T22:50:13Z
@dkorpel created dlang/druntime pull request #3520 "Fix issue 22124 - Corrupted closure with -dip1000 " fixing this issue:
- Fix issue 22124 - Corrupted closure with -dip1000
- Add test case for issue 22124
https://github.com/dlang/druntime/pull/3520
Comment #4 by dlang-bot — 2021-08-19T19:35:04Z
@dkorpel created dlang/druntime pull request #3550 "Add test case for issue 22124" mentioning this issue:
- Add test case for issue 22124
https://github.com/dlang/druntime/pull/3550
Comment #5 by dlang-bot — 2021-08-23T09:12:44Z
dlang/druntime pull request #3550 "Add test case for issue 22124" was merged into master:
- b4006f2b7a6dd8357f8f87bb3cad606078dfa9d7 by dkorpel:
Fix issue 22124 - Corrupted closure when compiling with -preview=dip1000
https://github.com/dlang/druntime/pull/3550