← Back to index
|
Original Bugzilla link
Bug 10633 – Win64: wrong codegen with %=
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2013-07-13T09:36:00Z
Last change time
2015-06-09T05:11:53Z
Keywords
wrong-code
Assigned to
nobody
Creator
r.sagitario
Comments
Comment #0
by r.sagitario — 2013-07-13T09:36:33Z
This code crashes when compiled for win64: struct TimeOfDay { void roll(int value) { value %= 60; auto newVal = _seconds + value; if(newVal < 0) newVal += 60; else if(newVal >= 60) newVal -= 60; _seconds = cast(ubyte)newVal; } ubyte _seconds; } void main() { TimeOfDay tod = TimeOfDay(0); tod.roll(-1); assert(tod._seconds == 59); } generated asm for roll: _D4test9TimeOfDay4rollMFiZv: 0000000000000000: 55 push rbp 0000000000000001: 48 8B EC mov rbp,rsp 0000000000000004: 48 83 EC 18 sub rsp,18h 0000000000000008: 53 push rbx 0000000000000009: 48 89 4D 10 mov qword ptr [rbp+10h],rcx 000000000000000D: 89 55 18 mov dword ptr [rbp+18h],edx 0000000000000010: 48 83 7D 10 00 cmp qword ptr [rbp+10h],0 0000000000000015: 75 1D jne 0000000000000034 0000000000000017: 41 B8 03 00 00 00 mov r8d,3 000000000000001D: 48 8D 15 00 00 00 lea rdx,[_TMP1] 00 0000000000000024: 48 8D 0D 00 00 00 lea rcx,[_TMP3] 00 000000000000002B: 48 83 EC 20 sub rsp,20h 000000000000002F: E8 00 00 00 00 call _d_assert_msg 0000000000000034: 41 B9 3C 00 00 00 mov r9d,3Ch 000000000000003A: 8B 45 18 mov eax,dword ptr [rbp+18h] 000000000000003D: 99 cdq 000000000000003E: 41 F7 F9 idiv eax,r9d 0000000000000041: 89 55 18 mov dword ptr [rbp+18h],edx 0000000000000044: 48 8B 5D 10 mov rbx,qword ptr [rbp+10h] 0000000000000048: 0F B6 03 movzx eax,byte ptr [rbx] 000000000000004B: 03 C2 add eax,edx 000000000000004D: 89 45 F8 mov dword ptr [rbp-8],eax 0000000000000050: 85 C0 test eax,eax 0000000000000052: 79 04 jns 0000000000000058 0000000000000054: 01 CD add ebp,ecx 0000000000000056: EB 08 jmp 0000000000000060 0000000000000058: 83 7D F8 3C cmp dword ptr [rbp-8],3Ch 000000000000005C: 7C 02 jl 0000000000000060 000000000000005E: 29 CD sub ebp,ecx 0000000000000060: 8A 55 F8 mov dl,byte ptr [rbp-8] 0000000000000063: 48 8B 4D 10 mov rcx,qword ptr [rbp+10h] 0000000000000067: 88 11 mov byte ptr [rcx],dl 0000000000000069: 5B pop rbx 000000000000006A: 48 8D 65 00 lea rsp,[rbp] 000000000000006E: 5D pop rbp 000000000000006F: C3 ret Notice that the add/sub at offsets 54/5e write to ebp, but the variable is in [rbp-8]. Exchanging "value %= 60;" with "value = value % 60;" fixes the problem.
Comment #1
by bugzilla — 2013-07-15T02:14:32Z
https://github.com/D-Programming-Language/dmd/pull/2347
Comment #2
by github-bugzilla — 2013-07-16T10:47:57Z
Commits pushed to master at
https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/2f74f0243c3c730c67c6c610d5922008f1121684
fix Issue 10633 - Win64: wrong codegen with %=
https://github.com/D-Programming-Language/dmd/commit/70cc17d2132d7dbf7d569ddf0fcbbea58a6c7d76
Merge pull request #2347 from WalterBright/fix10633 fix Issue 10633 - Win64: wrong codegen with %=
Comment #3
by github-bugzilla — 2013-07-16T11:17:29Z
Commit pushed to dmd-1.x at
https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/500e1d110dff1c69ee14b671b199f4c44915de86
Merge pull request #2347 from WalterBright/fix10633 fix Issue 10633 - Win64: wrong codegen with %=