← Back to index
|
Original Bugzilla link
Bug 8891 – (D1 only) non-static opCall runs in initialization incorrectly
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2012-10-24T22:41:00Z
Last change time
2012-11-08T09:30:01Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0
by k.hara.pg — 2012-10-24T22:41:21Z
import core.stdc.stdio : printf; struct S { int value = 10; S opCall(int n) // non-static { printf("this.value = %d\n", this.value); // prints garbage! S s; s.value = n; return s; } } void main() { S s = 10; // calls instance opCall incorrectly }
Comment #1
by maxim — 2012-10-25T01:23:56Z
(In reply to comment #0) It seems dmd fails to push pointer to S object in case of S s = 10; 0x0000000000418559 <+1>: mov %rsp,%rbp 0x000000000041855c <+4>: sub $0x10,%rsp 0x0000000000418560 <+8>: mov $0xa,%esi 0x0000000000418565 <+13>: lea -0x8(%rbp),%rdi // %rdi is garbage 0x0000000000418569 <+17>: callq 0x418500 <_D4main1S6opCallMFiZS4main1S> In case of S s; s.opCall(10) it makes correctly: 0x0000000000418534 <+0>: push %rbp 0x0000000000418535 <+1>: mov %rsp,%rbp 0x0000000000418538 <+4>: sub $0x10,%rsp 0x000000000041853c <+8>: mov 0x1720e(%rip),%eax <_D4main1S6__initZ> 0x0000000000418542 <+14>: mov %eax,-0x8(%rbp) 0x0000000000418545 <+17>: mov $0xa,%esi 0x000000000041854a <+22>: lea -0x8(%rbp),%rdi // %rdi is S.init 0x000000000041854e <+26>: callq 0x418500 <_D4main1S6opCallMFiZS4main1S> opCall expects struct object to be in %esp 0x0000000000418500 <+0>: push %rbp 0x0000000000418501 <+1>: mov %rsp,%rbp 0x0000000000418504 <+4>: sub $0x20,%rsp 0x0000000000418508 <+8>: mov %esi,-0x8(%rbp) 0x000000000041850b <+11>: mov (%rdi),%esi // this.value 0x000000000041850d <+13>: movabs $0x42f758,%rdi 0x0000000000418517 <+23>: xor %eax,%eax 0x0000000000418519 <+25>: callq 0x418100 <printf@plt>
Comment #2
by k.hara.pg — 2012-10-27T08:07:34Z
https://github.com/D-Programming-Language/dmd/pull/1231
Comment #3
by github-bugzilla — 2012-10-27T10:25:33Z
Commits pushed to master at
https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/a4c8e8e295974e11cefa0ac9e8a10d8829efc4b7
fix Issue 8891 - non-static opCall runs in initialization incorrectly
https://github.com/D-Programming-Language/dmd/commit/6f51482f15976f3407ffef19b0c1322d0d3c9a56
Merge pull request #1231 from 9rnsr/fix8891 Issue 8891 - non-static opCall runs in initialization incorrectly
Comment #4
by yebblies — 2012-10-27T10:41:14Z
Fixed for D2
Comment #5
by k.hara.pg — 2012-11-08T09:30:01Z
Fixed D1:
https://github.com/D-Programming-Language/dmd/commit/e0d07bf6cdc7b5b41a8eec777a89ac0178c7549c