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
4 days ago
ZombineDev
4 days ago
Walter Bright
4 days ago
Walter Bright
4 days ago
Dlang Bot
4 days ago
Walter Bright
4 days ago
Walter Bright
4 days ago
Walter Bright
3 days ago
kinke
4 days ago
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

--
4 days ago
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.

--
4 days ago
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       |

--
4 days ago
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

--
4 days ago
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

--
4 days ago
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/

--
4 days ago
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).

--
3 days ago
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

--