Commit Graph

17 Commits

Author SHA1 Message Date
Gabor Horvath
e79e04c0a6 [cxx-interop] Mark C++ reference parameters @addressable
C++ code can return values that depend on the storage that backs the
references that were passed in as argument. Thus, swift should not
introdue temporary copies of that storage before invoking those
functions as they could result in lifetime issues.
2025-02-11 11:10:51 +00:00
Hiroshi Yamauchi
fcc1f6b65e Fix the IR gen for C++ method calls and refactor around CGFunctionInfo
In GenCall, fix the IR gen for C++ method calls as under MSVC as the
calling conventions for free functions and C++ methods can be
different. This also fixes the missing inreg (on sret arguments)
issues on Windows ARM64. Also refactor to use CGFunctionInfo
returnInfo isSretAfterThis to detect when to reorder the sret and the
this arguments under MSVC.

In ClagImporter, don't drop the return type for the compound
assignment operators such as operator+= when the return value is a
reference so that the CGFunctionInfo will be correctly indicate an
indirect return for the compound assignment operators.
2024-10-24 15:40:21 -07:00
Hiroshi Yamauchi
f815e1429e Ensure that BridgedTypeArray is indirectly returned
On Windows ARM64, how a struct value type is returned is sensitive to
conditions including whether a user-defined constructor exists,
etc. See

https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#return-values

That caused a calling convention mismatch between the
non-USED_IN_CPP_SOURCE (Swift) side and the USE_IN_CPP_SOURCE (C++)
side and a crash.

Add this constructor so that the calling convention matches.

This is a fix for the OnoneSimplification crash in

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579

and is a partial fix for

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579
2024-09-12 10:46:55 -07:00
Gabor Horvath
d17d17e96e [cxx-interop] Fix inadvertently renaming static method to Mutating
When we have both const and non-const version of a function, we import
the non-cont version with the "Mutating" suffix. This logic, however, is
redundant for static member functions as those can never be marked as
"const" since they don't have a "self" or "this" to mutate.

rdar://120858502
2024-06-18 16:19:23 +01:00
Alex Lorenz
15a0345857 Merge pull request #67268 from hyp/eng/windows-method-oh-no
[cxx-interop] windows methods fixes
2023-07-21 06:57:01 -07:00
zoecarver
7db669ce5b [cxx-interop] Fix a bug with explicit, nested, self-contained types (and add a test). 2023-07-18 17:42:05 -07:00
zoecarver
474a7cd834 [cxx-interop] Only mark projections of self-contained types as unsafe.
Projections of trivial types and view types aren't unsafe. This matches what was described in the vision document.
2023-07-18 17:42:05 -07:00
Alex Lorenz
c09135b8f3 [cxx-interop] Fix the windows ABI for returning indirect values out of methods
Fixes https://github.com/apple/swift/issues/66326

This allows us to reneable Windows method tests. Note that Windows still has
a broken convention for non-trivial record with non-trivial destructor but
trivial copy-constructor, so classes in the methods.swift test need an explicit
copy constructor.

Fixes rdar://88391102
2023-07-14 15:56:05 -07:00
zoecarver
4f72147279 [cxx-interop] Use "c function conventions" for static methods and ctors (not "cxx method conventions").
Otherwise we will incorrectly use the "self" type's conventions when lowering the parameters (off-by-one).
2023-02-09 17:10:16 -08:00
Egor Zhdan
168ef490af [cxx-interop] Disambiguate const and non-const methods consistently
When importing a C++ struct that contains two methods that only differ in const-ness, we append `Mutating` to the name of the non-const method to make it possible to call from Swift unambiguously.

Unfortunately that logic was dependent on the order in which we import methods of a class: the `Mutating` suffix was added when another method with the same name was already imported.

This caused lookup failures, and the behavior was incorrect when the pair of methods return instances of an unsafe type: the const overload was renamed as `Unsafe` properly, but the non-const overload was not renamed.
2022-12-19 15:03:04 +00:00
Ehud Adler
379fc1f0a4 [cxx-interop] Fix issue where multiple records in a module containing the same meth… (#60338) 2022-08-02 09:01:56 -04:00
zoecarver
6acffbbee6 [cxx-interop] Flip the switch: only import safe APIs. 2022-07-18 17:15:15 -04:00
Ehud Adler
be643437c6 Removed ping due to the const method being empty and therefore being optimizd out 2022-02-24 12:05:37 -05:00
Ehud Adler
f3f75ba26e Change order of const/mutable in class to enhance test 2022-02-10 13:00:08 -05:00
Ehud Adler
18c6bdd212 [Cxx iterop] Disambiguate between methods with the same name but different constness 2022-02-09 19:49:02 -05:00
Ehud Adler
f8f8e16864 Start with writing failing tests 2022-02-07 12:49:27 -05:00
zoecarver
1429cf3d29 [nfc][cxx-interop] Add some tests for calling C++ methods.
Finally 😅
2022-02-02 11:09:36 -08:00