Thread overview
[Issue 23195] Win64 function ABI bug for small non-POD arguments
[Issue 23195] codegen/calling convention bug causes small non-POD arguments to be broken for extern(C++) functions
Nov 23, 2022
ZombineDev
Nov 24, 2022
Walter Bright
Nov 24, 2022
Walter Bright
Nov 24, 2022
Dlang Bot
Nov 24, 2022
Walter Bright
Nov 24, 2022
Walter Bright
Nov 24, 2022
Walter Bright
Nov 24, 2022
kinke
Dec 17, 2022
Iain Buclaw
Feb 09, 2023
Dlang Bot
November 23, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

ZombineDev <petar.p.kirov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend, C++, wrong-code
                 CC|                            |petar.p.kirov@gmail.com
           Severity|major                       |critical

--
November 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

Walter Bright <bugzilla@digitalmars.com> changed:

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

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
Compilable example:

  struct FF {
    float x, y;
    ~this();
  }

  void draw(FF min, FF max);

  void test(FF *a, FF *b) {
    draw(*a, *b);
  }

If `~this();` is commented out, the arguments are passed to draw by value.

--
November 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|codegen/calling convention  |Win64 function ABI bug for
                   |bug causes small non-POD    |small non-POD arguments
                   |arguments to be broken for  |
                   |extern(C++) functions       |

--
November 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

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

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

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #14651 "fix Issue 23195 - Win64 function ABI bug for small non-POD arguments" fixing this issue:

- fix Issue 23195 - Win64 function ABI bug for small non-POD arguments

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

--
November 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=19563

--
November 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
This problem appears to have been introduced by https://github.com/dlang/dmd/pull/9434/

--
November 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
(In reply to simon.vanbernem from comment #0)
> Microsoft states in their C++ x64 calling convention that structs with a
> maximum size of 8 bytes should be passed by value through registers (POD or
> not doesn't matter).
> [...]
> (https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-
> 170#parameter-passing)

Microsoft's documentation is doesn't match the behavior of their compiler. Having a destructor does not affect whether a struct is passed by ref or not, but having a copy constructor does (contrary to the documentation).

--
November 24, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #5 from kinke <kinke@gmx.net> ---
(In reply to Walter Bright from comment #4)
> Microsoft's documentation is doesn't match the behavior of their compiler. Having a destructor does not affect whether a struct is passed by ref or not, but having a copy constructor does (contrary to the documentation).

That's right. Note that there's another special case for the MSVC++ ABI: POD
structs with any ctor are returned via struct-return (the hidden result
pointer).
https://github.com/ldc-developers/ldc/blob/05fb6d5acaef1a97129317ce8f0dd712e03aee7f/gen/abi/win64.cpp#L59-L80

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23195

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--
February 09, 2023
https://issues.dlang.org/show_bug.cgi?id=23195

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

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

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #14651 "fix Issue 23195 - Win64 function ABI bug for small non-POD arguments" was merged into master:

- 9a6324fa38859c5ad67592f590234cbb36ccfbb2 by Walter Bright:
  fix Issue 23195 - Win64 function ABI bug for small non-POD arguments

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

--