Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 31, 2012 [Issue 8923] New: Destructors of struct members get called at the wrong point | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=8923 Summary: Destructors of struct members get called at the wrong point Product: D Version: D2 Platform: x86_64 OS/Version: Linux Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: malteskarupke@web.de --- Comment #0 from Malte Skarupke <malteskarupke@web.de> 2012-10-31 10:55:37 PDT --- The destructor of the member of a struct doesn't get called when I expect it to be called. I'd expect it to be called at the end of the destructor of the containing struct. I'm not sure when it gets called instead, but it is too late. Here is a case that segfaults in DMD 2.060: void main() { bool destructorCalled = false; struct DestructorCounter { ~this() { destructorCalled = true; // segmentation fault } } struct S { DestructorCounter a; } S s; } If this is supposed to be invalid I can provide examples that are most definitely not supposed to be invalid, but are a bit more lengthy. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 31, 2012 [Issue 8923] Destructors of struct members get called at the wrong point | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 Maxim Fomin <maxim@maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim@maxim-fomin.ru --- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-10-31 11:51:58 PDT --- It seems that dmd doesn't pass allocated value correctly. In this case it emits in main function code: callq <_d_allocmemory> movq $0x0,(%rax) movb $0x0,0x8(%rax) lea -0x8(%rbp),%rax xor %rcx,%rcx mov %rcx,(%rax) mov %rax,%rdi So, allocated value is overwritten and destructor gets incorrect pointer in %rdi. However, if the case is simplified to one level (replace S s; with DestructorCounter s;) dmd emits correct code: callq <_d_allocmemory> movq $0x0,(%rax) movb $0x0,0x8(%rax) mov %rax,-0x8(%rbp) lea -0x8(%rbp),%rax xor %rcx,%rcx mov %rax,%rdi Now %rdi points to allocated memory. Probably, because S field destructor doesn't access destructorCalled object forces dmd to pass invalid value. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 31, 2012 [Issue 8923] Destructors of struct members get called at the wrong point | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 Kenji Hara <k.hara.pg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code --- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-10-31 11:54:36 PDT --- In Windows, s1's dtor causes Access Violation, but s2's dtor runs successfully. import core.stdc.stdio : printf; void main() { bool destructorCalled = false; struct DestructorCounter { ~this() { printf("-dtor\n"); destructorCalled = true; // segmentation fault } } struct S { DestructorCounter a; } S s1; // Access Violation S s2 = S(); // OK } Output: --- -dtor (s2's dtor call) -dtor (s1's dtor call) object.Error: Access Violation --- I think this is definitely a wrong-code bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 31, 2012 [Issue 8923] Destructors of struct members get called at the wrong point | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 --- Comment #3 from Malte Skarupke <malteskarupke@web.de> 2012-10-31 12:50:17 PDT --- I debugged the issue I was having further, and it is definitely a different problem than I thought it was. It does not have to do with destructors being called in the wrong order, and actually the test case from the first post isn't showing the problem that I encountered. It was just that once I had that test case I felt like I should submit it. I'll try to figure out a test case for my real problem, but I'll do that in a different bug report. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 07, 2012 [Issue 8923] Destructors of struct members get called at the wrong point | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 --- Comment #4 from github-bugzilla@puremagic.com 2012-11-06 20:31:59 PST --- Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/585f5a3a3db9f856dc4904910b8a705969b89d33 fix Issue 8923 - Destructors of struct members get called at the wrong point https://github.com/D-Programming-Language/phobos/commit/f76ea73eff85d260f6b1642dbada9701dc3a7fa6 Merge pull request #926 from 9rnsr/fix8923 Supplemental fix for Issue 8923 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 07, 2012 [Issue 8923] Destructors of struct members get called at the wrong point | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 --- Comment #5 from github-bugzilla@puremagic.com 2012-11-06 20:33:55 PST --- Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/704230b135f3e4b25470b4522927fe97a43604c1 fix Issue 8923 - Destructors of struct members get called at the wrong point If a default-initialized variable declaration requies some frame pointers for it's field, they should be initialized by the StructLiteralExp to fill the hidden field. https://github.com/D-Programming-Language/dmd/commit/e1c9119d2a622ecf4bfc3b5c34f20a33f7f4a2c1 Merge pull request #1259 from 9rnsr/fix8923 Issue 8923 - Destructors of struct members get called at the wrong point -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 07, 2012 [Issue 8923] Destructors of struct members get called at the wrong point | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla@digitalmars.com Resolution| |FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 08, 2012 [Issue 8923] Nested structs have null context pointers in static array variables and struct fields | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 Denis Shelomovskij <verylonglogin.reg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |verylonglogin.reg@gmail.com Summary|Destructors of struct |Nested structs have null |members get called at the |context pointers in static |wrong point |array variables and struct | |fields --- Comment #6 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-08 18:30:23 MSK --- As commits are already pushed referencing this one, renaming the issue and providing a comprehensive example (instead of creating a new one one marking this as a duplicate): --- void main() { int i; struct CS { void f() { ++i; } } struct S { CS cs; } CS cs; assert(cs.tupleof[$-1] != null); // ok CS[1] csArr; assert(csArr[0].tupleof[$-1] != null); // fails S s1 = S(); assert(s1.cs.tupleof[$-1] != null); // ok S s2; assert(s2.cs.tupleof[$-1] != null); // fails } --- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 08, 2012 [Issue 8923] Nested structs have null context pointers in static array variables and struct fields | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 Denis Shelomovskij <verylonglogin.reg@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |monarchdodra@gmail.com --- Comment #7 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-08 18:32:53 MSK --- *** Issue 8951 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
November 08, 2012 [Issue 8923] Nested structs have null context pointers in static array variables and struct fields | ||||
---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | http://d.puremagic.com/issues/show_bug.cgi?id=8923 --- Comment #8 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-08 18:33:29 MSK --- *** Issue 8952 has been marked as a duplicate of this issue. *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation