[Issue 8423] New: Wrong code for lazy parameters.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jul 24 02:53:10 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8423
Summary: Wrong code for lazy parameters.
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: code at klickverbot.at
--- Comment #0 from klickverbot <code at klickverbot.at> 2012-07-24 02:53:06 PDT ---
With DMD Git master (04a74bdf) on Linux x86_64, the following snippet
asserts/hlts:
---
struct Duration
{
int opCmp(Duration rhs)
{
return 1;
}
}
void enforce(bool value, string a, string b)
{
if (!value) assert(false);
}
void main()
{
auto a = Duration();
auto b = Duration();
enforce(a > b, null, null);
}
---
Here is the relevant assembly:
---
40194d: e8 0e ff ff ff call 401860
<_D4test8Duration5opCmpMFS4test8DurationZi>
401952: 49 89 c0 mov r8,rax
401955: f7 d8 neg eax
401957: 41 c1 e8 1f shr r8d,0x1f
40195b: 31 c0 xor eax,eax
40195d: 31 c9 xor ecx,ecx
40195f: 48 89 c2 mov rdx,rax
401962: 48 89 55 f0 mov QWORD PTR [rbp-0x10],rdx
401966: 48 89 ca mov rdx,rcx
401969: 48 89 c7 mov rdi,rax
40196c: 48 89 d6 mov rsi,rdx
40196f: 48 8b 55 f0 mov rdx,QWORD PTR [rbp-0x10]
401973: e8 38 ff ff ff call 4018b0
<_D4test7enforceFbAyaAyaZv>
---
I haven't checked what causes DMD to emit the »shr« instruction, but it sure
kills the opCmp return value in the register. Removing one of the additional
parameters, which leads to value being passed in one of {rsi, rdi, rdx, rcx}
due to the reverse parameter order in the D calling convention, causes the bug
to disappear.
--
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