Issue 16987 - ABI error wrt. COM interfaces returning structs
Summary: ABI error wrt. COM interfaces returning structs
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P1 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-19 23:07 UTC by kinke
Modified: 2018-06-25 18:44 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kinke 2016-12-19 23:07:14 UTC
From http://forum.dlang.org/post/tiyttpodenppvlfxixcw@forum.dlang.org, relevant wrt. interfacing with DirectX libraries:

COM classes/interfaces are apparently subject to a separate ABI. Unfortunately, googling it hasn't turned up any official (and not even some inofficial) documentation so far. Based on the first few tests on Win64, integers are returned in RAX, floats (and I guess doubles too) in XMM0, and structs (incl. 2x int32 and 2x float) via hidden sret pointer, with `this` pointer in RCX (1st arg) and `sret` in RDX (2nd arg). Compared to the normal Win64 C++ ABI it just seems more conservative by always returning structs via hidden pointer.

While at it, please also fix https://issues.dlang.org/show_bug.cgi?id=16527 by simply swapping the order of `this` and `sret` pointer arguments on Windows (32-bit: extern(C++) methods only, 64-bit: always; LDC already does so).
Comment 1 kinke 2018-06-25 18:44:50 UTC
This was fixed by https://github.com/dlang/dmd/pull/8330, for Win32 and Win64, and apparently wasn't COM-specific, but a Visual C++ ABI quirk.