Bug 14730 – Wrong closure var access with -inline

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-24T13:21:16Z
Last change time
2022-06-05T08:51:04Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
Kenji Hara
See also
https://issues.dlang.org/show_bug.cgi?id=23112

Comments

Comment #0 by k.hara.pg — 2015-06-24T13:21:16Z
The assertion fails when you compile the code with -inline. void main() { static auto makeS2(int x) { struct S2 { int n; int get() { return x; } // x will be a cloaure variable } return S2(x); } auto s2a = makeS2(1); // Fails, because inlined get() returns incorrect value assert(s2a.get() == 1); } The parameter 'x' of makeS2 function is a closure variable. It's offset is calculated in makeS2->toObjFile(). But with -inline, the get function call is expanded in main(). Then the inlined code will access x via the hidden field of s2a, by using 0 offset (wrong). To fix the problem, we need to determine all offsets of closure vars in front-end.
Comment #1 by k.hara.pg — 2015-06-24T13:38:37Z
Comment #2 by github-bugzilla — 2016-02-07T03:18:59Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6f0f6db976af6fe6ebbaba05b968a354a58994ad fix Issue 14730 - Wrong closure var access with -inline https://github.com/D-Programming-Language/dmd/commit/2d0bcf1fbd4db3d4a96c5413cdda292c0f151ed4 Merge pull request #4765 from 9rnsr/fix14730 Issue 14730 - Wrong closure var access with -inline