D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10639 - Win64: wrong optimizer codegen with struct literal with complex fields
Summary: Win64: wrong optimizer codegen with struct literal with complex fields
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 All
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2013-07-14 06:13 UTC by Rainer Schuetze
Modified: 2015-06-09 05:10 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2013-07-14 06:13:54 UTC
This source extracted from the phobos unittests:

struct S1 
{ 
	cdouble val; 
}

void formatTest(S1 s, double re, double im)
{
	assert(s.val.re == re);
	assert(s.val.im == im);
}

unittest
{
	S1 s = S1(3+2.25i);
	formatTest(s, 3, 2.25);
}

void main() {}

compile with "dmd -unittest -m64 -O test.d" and run to see the assertions failing.
This does not happen with -m32 or without -O.

Here is the disassembly of the unittest code:

_D4test15__unittestL12_1FZv:
  0000000000000000: 55                 push        rbp
  0000000000000001: 48 8B EC           mov         rbp,rsp
  0000000000000004: 48 83 EC 10        sub         rsp,10h
  0000000000000008: 48 C7 45 F0 00 00  mov         qword ptr [rbp-10h],0
                    00 00
  0000000000000010: 48 C7 45 F8 00 00  mov         qword ptr [rbp-8],0
                    00 00
  0000000000000018: 4C 8D 45 F0        lea         r8,[rbp-10h]
  000000000000001C: F2 48 0F 10 0D 00  movsd       xmm1,mmword ptr [_TMP3]
                    00 00 00
  0000000000000025: F2 48 0F 10 05 00  movsd       xmm0,mmword ptr [_TMP4]
                    00 00 00
  000000000000002E: 48 83 EC 20        sub         rsp,20h
  0000000000000032: 66 48 0F 7E CA     movd        rdx,xmm1
  0000000000000037: 66 48 0F 7E C1     movd        rcx,xmm0
  000000000000003C: E8 00 00 00 00     call        _D4test10formatTestFS4test2S1ddZv
  0000000000000041: 48 83 C4 20        add         rsp,20h
  0000000000000045: 48 8D 65 00        lea         rsp,[rbp]
  0000000000000049: 5D                 pop         rbp
  000000000000004A: C3                 ret

The struct literal is initialized with two 0 values at offset 8/10.
Comment 2 github-bugzilla 2013-07-19 00:11:32 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a3d33e3937d42fdead489a7f04413583f4451491
fix
Issue 10639 - Win64: wrong optimizer codegen with struct literal with complex fields

https://github.com/D-Programming-Language/dmd/commit/de687981f72b0256b1dc1233306b4cfe94db626c
Merge pull request #2359 from WalterBright/fix10639

fix Issue 10639 - Win64: wrong optimizer codegen with struct literal with complex fields
Comment 3 github-bugzilla 2013-07-19 14:25:33 UTC
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6f38739b45f65f1173db4401fdb88c583937fd76
Merge pull request #2359 from WalterBright/fix10639

fix Issue 10639 - Win64: wrong optimizer codegen with struct literal with complex fields