www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8423] New: Wrong code for lazy parameters.

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: code klickverbot.at



---
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: -------
Jul 24 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8423




---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8423


klickverbot <code klickverbot.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8423




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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8423




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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8423


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



00:33:18 PDT ---
Not really a regression, this bug was always there. Fixed anyway.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2012