[Issue 10645] New: Wrong codegen for shared struct with constructor and pass to atomicLoad
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jul 15 03:02:13 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10645
Summary: Wrong codegen for shared struct with constructor and
pass to atomicLoad
Product: D
Version: D2
Platform: x86_64
OS/Version: Linux
Status: NEW
Severity: critical
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: jfanatiker at gmx.at
--- Comment #0 from jfanatiker at gmx.at 2013-07-15 03:02:10 PDT ---
The following simple code:
---
cat > app2.d << EOF
import core.atomic;
import std.stdio;
struct Test {
this(long v) {
val = v;
}
long val;
}
void main() {
shared(Test) test = Test(7);
auto buf = atomicLoad(test);
writefln("buf: %s, orig: %s", buf, cast(Test)test);
}
EOF
---
produces the following output:
buf: Test(0), orig: Test(7)
instead of the expected:
buf: Test(7), orig: Test(7)
Assembly with objdump -d -g -C -S -l app2.o (full output appended):
void main() {
0: 55 push %rbp
1: 48 8b ec mov %rsp,%rbp
4: 48 83 ec 10 sub $0x10,%rsp
/home/robert/projects/phobosx/source/app2.d:11
shared(Test) test = Test(7);
8: 48 8d 45 f0 lea -0x10(%rbp),%rax <<<<< -0x10 is
right
c: 48 31 c9 xor %rcx,%rcx
f: 48 89 08 mov %rcx,(%rax)
12: 48 be 07 00 00 00 00 movabs $0x7,%rsi
19: 00 00 00
1c: 48 89 c7 mov %rax,%rdi <<<< used here
correctly
1f: e8 00 00 00 00 callq 24 <_Dmain+0x24>
24: 48 8d 75 f0 lea -0x10(%rbp),%rsi
/home/robert/projects/phobosx/source/app2.d:12
auto buf = atomicLoad(test);
28: 48 8d 7d f8 lea -0x8(%rbp),%rdi <<<< now -0x8, why?
2c: e8 00 00 00 00 callq 31 <_Dmain+0x31>
It seems that the wrong address gets passed to atomicLoad. If you remove the
constructor of Test the right address (-0x10) is used. Various transformation
of this program all have the same wrong output: You can make test global, put
it in a union together with a plain long, create a non shared temporary before
assigning to the shared variable, use casts, ... The only thing that helps is
removing the constructor.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list