Thread overview
[Issue 16274] The curses of debugging: short argument passed in 16-bit register, against ABI
Jul 13, 2016
Luís Marques
Jul 13, 2016
ag0aep6g@gmail.com
Aug 29, 2020
Walter Bright
Aug 29, 2020
Walter Bright
Aug 29, 2020
Walter Bright
Aug 29, 2020
Walter Bright
Aug 30, 2020
Dlang Bot
Sep 10, 2020
Dlang Bot
May 30, 2021
Dlang Bot
July 13, 2016
https://issues.dlang.org/show_bug.cgi?id=16274

Luís Marques <luis@luismarques.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |x86_64
           Severity|enhancement                 |major

--- Comment #1 from Luís Marques <luis@luismarques.eu> ---
(I'm using the latest DMD, v2.071.1, although this problem has existed for
quite a while)

--
July 13, 2016
https://issues.dlang.org/show_bug.cgi?id=16274

ag0aep6g@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |ag0aep6g@gmail.com

--
August 29, 2020
https://issues.dlang.org/show_bug.cgi?id=16274

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend
                 CC|                            |bugzilla@digitalmars.com

--
August 29, 2020
https://issues.dlang.org/show_bug.cgi?id=16274

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
A smaller version:

  extern(C) int init_pair(short pair, short f, short b);
  void test() { init_pair(1, 2, 3); }

which generates:

  _D4testQfFZv:
        push    RBP
        mov     RBP,RSP
        mov     8D,3
        mov     DX,2
        mov     CX,1
        sub     RSP,020h
        call    init_pair
        add     RSP,020h
        pop     RBP
        ret

Indeed, you are correct in that the upper 16 bits of the register is not set. But I believe this correct code generation. The problem may be in the implementation of init_pair(), which is assuming the upper 16 bits are zero.

--
August 29, 2020
https://issues.dlang.org/show_bug.cgi?id=16274

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
gcc, however, does indeed set the upper 16 bits to zero. I suppose dmd should behave the same way, regardless of the spec.

--
August 29, 2020
https://issues.dlang.org/show_bug.cgi?id=16274

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
Curiously, I implemented init_pair() and it turns out that gcc sign extends each parameter before using it.

So this problem does depend on what's going on with init_pair's implementation.

--
August 30, 2020
https://issues.dlang.org/show_bug.cgi?id=16274

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #11651 "fix Issue 16274 - The curses of debugging: short argument passed in 1…" fixing this issue:

- fix Issue 16274 - The curses of debugging: short argument passed in 16-bit register, against ABI

https://github.com/dlang/dmd/pull/11651

--
September 10, 2020
https://issues.dlang.org/show_bug.cgi?id=16274

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@ibuclaw created dlang/dmd pull request #11719 "fix Issue 16274 - short argument passed in 16 bit register" fixing this issue:

- fix Issue 16274 - short argument passed in 16 bit register

https://github.com/dlang/dmd/pull/11719

--
May 30, 2021
https://issues.dlang.org/show_bug.cgi?id=16274

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #11651 "fix Issue 16274 - short argument passed in 16 bit register" was merged into master:

- 00271210bfe8fe9dc4d4bfe17045b17b1621df59 by Walter Bright:
  fix Issue 16274 - short argument passed in 16-bit register, against ABI

https://github.com/dlang/dmd/pull/11651

--