8423 – Wrong code for bool parameter in 5th integer register.

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8423 - Wrong code for bool parameter in 5th integer register.
Summary: Wrong code for bool parameter in 5th integer register.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 All
: P2 regression
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2012年07月24日 02:53 UTC by David Nadlinger
Modified: 2015年06月09日 05:14 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description David Nadlinger 2012年07月24日 02:53:06 UTC
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.
Comment 1 David Nadlinger 2012年07月24日 03:02:59 UTC
Hm, seems like the same problem already existed in DMD 2.059 with enforce(bool, int, int, int, int) - what triggers it in 2.060 is the fact that arrays are passed as structs (i.e. in registers) now.
Comment 2 github-bugzilla 2012年07月28日 00:32:22 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/672de5c508ce377ac6241519f48c65d8bfec7539
fix Issue 8423 - Wrong code for bool parameter in 5th integer register.
Comment 3 github-bugzilla 2012年07月28日 00:32:49 UTC
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/035700b6e2505cbd7f140bce307fbfe40e42a4c9
fix Issue 8423 - Wrong code for bool parameter in 5th integer register.
Comment 4 Walter Bright 2012年07月28日 00:33:18 UTC
Not really a regression, this bug was always there. Fixed anyway.


AltStyle によって変換されたページ (->オリジナル) /