[swift-dev] Is there an ABI conflict between Swift and C++ regarding multiple return values?

Bryan Chan bryan.chan at ca.ibm.com
Tue Mar 8 04:17:49 CST 2016

I have observed that swiftc on Linux assumes it can return tuples of at
most three integer-type elements in registers (rax, rdx and rcx, in that
order), while clang++ supports returning at most two integer-type values in
registers (rax and rdx), in accordance to the System V ABI. Doesn't this
cause a problem when a Swift function calls a C++ function that returns a
three-word struct indirectly while expecting the return values in

I ran into this issue when porting Swift to Linux s390x, in the
ManagedBufferPointer constructor which calls a runtime function written in
C++, and they follow conflicting ABIs. I worked around it by setting
target.MaxScalarsForDirectResult to 1 in SwiftTargetInfo, but I wonder if
this affects other architectures as well. Can any one shed some light on

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160308/16002111/attachment.html>

More information about the swift-dev mailing list