Bug 20089 – FPU stack not cleaned up properly

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2019-07-27T17:03:50Z
Last change time
2019-08-21T03:36:08Z
Keywords
ice, pull, wrong-code
Assigned to
No Owner
Creator
Rainer Schuetze

Comments

Comment #0 by r.sagitario — 2019-07-27T17:03:50Z
dmd's own test18772.d causes an ICE when dmd is built with assertions enabled. float fun(cfloat z) { return z.re; } void main() { cfloat[1] A; float[1] B; int i = 0; double C = fun(A[i] * B[i]); } >dmd -m64 test18772.d DMD v2.087.0 DEBUG stackused = 2 core.exception.AssertError@..\dmd\backend\cgcod.d(694): Assertion failure The assembly of the code when built with the release version shows the problem is real: ... 00000000000000CE: 48 8D 45 F8 lea rax,[rbp-8] 00000000000000D2: D9 04 98 fld dword ptr [rax+rbx*4] 00000000000000D5: D9 45 D0 fld dword ptr [rbp-30h] 00000000000000D8: D9 C9 fxch st(1) 00000000000000DA: D9 45 DA fld dword ptr [rbp-26h] 00000000000000DD: D9 CA fxch st(2) 00000000000000DF: D9 C9 fxch st(1) 00000000000000E1: DC CA fmul st(2),st 00000000000000E3: DE C9 fmulp st(1),st 00000000000000E5: 48 83 EC 20 sub rsp,20h 00000000000000E9: E8 00 00 00 00 call _D9test187723funFqZf 00000000000000EE: 48 83 C4 20 add rsp,20h 00000000000000F2: F3 0F 5A C0 cvtss2sd xmm0,xmm0 ...
Comment #1 by r.sagitario — 2019-07-27T19:00:56Z
The problem rather seems to be fun: _D9test187723funFqZf: 0000000000000000: 55 push rbp 0000000000000001: 48 8B EC mov rbp,rsp 0000000000000004: 66 0F 6E C1 movd xmm0,ecx 0000000000000008: 5D pop rbp 0000000000000009: C3 ret the cfloat is passed in FPU registers to fun, but the function reads ECX.
Comment #2 by dlang-bot — 2019-07-31T16:13:29Z
@marler8997 updated dlang/dmd pull request #10247 "Handle extra case in fixresult_complex87" fixing this issue: - Fix issue 20089: Handle extra case in fixresult_complex87 https://github.com/dlang/dmd/pull/10247
Comment #3 by dlang-bot — 2019-08-21T03:36:08Z
dlang/dmd pull request #10247 "Fix issue 20089: Handle extra case in fixresult_complex87" was merged into master: - 3e2c68b3b27f0016712920af7d2d44f2192fa265 by Jonathan Marler: Fix issue 20089: Handle extra case in fixresult_complex87 https://github.com/dlang/dmd/pull/10247