Bug 19381 – capture pointer in nested function should not be called "this"

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2018-11-09T09:02:48Z
Last change time
2018-11-19T04:43:16Z
Keywords
pull, symdeb
Assigned to
No Owner
Creator
Rainer Schuetze
See also
https://issues.dlang.org/show_bug.cgi?id=19410

Comments

Comment #0 by r.sagitario — 2018-11-09T09:02:48Z
struct Struct { int x = 3; int foo() { int y = 5; int nested() { int z = 7; return x + y + z; } return nested(); } } int main() { return Struct().foo(); } When compiled with -g, this shows a variable in nested() called "this", but is not the struct, but the capture of the outer function: (00004C) S_GPROC32: [0000:00000000], Cb: 0000002B, Type: 0x1004, dg.Struct.foo.nested Parent: 00000000, End: 00000000, Next: 00000000 Debug start: 0000000C, Debug end: 00000026 (000088) S_REGREL32: rbp+00000010, Type: 0x1019, this (0000A0) S_ENDARG (0000A4) S_REGREL32: rbp+FFFFFFF8, Type: T_INT4(0074), z (0000B4) S_END The type of "this" used to be void*, but has recently been populated with the captured stack variables of the outer function: 0x1016 : Length = 42, Leaf = 0x1505 LF_STRUCTURE # members = 2, field list type 0x1017, Derivation list type 0x0000, VT shape type 0x0000 Size = 0, class name = CAPTURE.dg.Struct.foo 0x1017 : Length = 34, Leaf = 0x1203 LF_FIELDLIST list[0] = LF_MEMBER, public, type = 0x1015, offset = 16 member name = 'this' list[1] = LF_MEMBER, public, type = 0x1002, offset = (LF_SHORT) -8 member name = 'y' 0x1019 : Length = 10, Leaf = 0x1002 LF_POINTER Pointer (__ptr64), Size: 8 Element type : 0x1016 Note the "this" member of the capture struct. Having multiple "this" variables confuses both the debugger and the user.
Comment #1 by r.sagitario — 2018-11-09T09:08:33Z
Comment #2 by github-bugzilla — 2018-11-09T13:34:51Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/7950336bbf810c62b2d3b3c75a3d48c94042c64f fix issue 19381 - capture pointer in nested function should not be called "this" rename the context pointer to the closure or the outer functions stack frame to '__capture' https://github.com/dlang/dmd/commit/9f1454be12e0ea89c984d277143386aa2b584cda Merge pull request #8933 from rainers/capture_name fix issue 19381 - capture pointer in nested function should not be called "this" merged-on-behalf-of: Nicholas Wilson <[email protected]>