[Issue 10633] New: Win64: wrong codegen with %=
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jul 13 09:36:34 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10633
Summary: Win64: wrong codegen with %=
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: r.sagitario at gmx.de
--- Comment #0 from Rainer Schuetze <r.sagitario at gmx.de> 2013-07-13 09:36:33 PDT ---
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.
--
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