-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[cxx-interop] Pass foreign reference types with correct level of indirection #83850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
…rection When calling a C++ function that takes a reference to a pointer to a foreign reference type, Swift would previously pass a pointer to the foreign reference type as an argument (instead of a reference to a pointer), which resulted in invalid memory accesses. This was observed when using `std::vector<ImmortalRef*>::push_back`. rdar://150791778
5628bf4
to
0a766e5
Compare
// In Swift, values that are foreign references types will always be | ||
// pointers. Additionally, we only import functions which use foreign | ||
// reference types indirectly (as pointers), so we know in every case, if | ||
// the argument type is a foreign reference type, the types will match up | ||
// and we can simply use the input directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is no longer correct, since we now import ImmortalRef *const &
as ImmortalRef!
.
if (type.isForeignReferenceType()) | ||
return getClangType(type.getASTType() | ||
->wrapInPointer(PTK_UnsafePointer) | ||
->getCanonicalType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now handled inside of getClangTypeForIRGen
, so this logic was adding an (incorrect) extra pointer.
@swift-ci please test |
@swift-ci please test Windows |
1 similar comment
@swift-ci please test Windows |
@swift-ci please test Windows |
@@ -0,0 +1,54 @@ | |||
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xfrontend -disable-availability-checking) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@egorzhdan, all %target-run-simple-swift
tests have to include // REQUIRES: executable_test
, else they fail in host-test mode.
When calling a C++ function that takes a reference to a pointer to a foreign reference type, Swift would previously pass a pointer to the foreign reference type as an argument (instead of a reference to a pointer), which resulted in invalid memory accesses.
This was observed when using
std::vector<ImmortalRef*>::push_back
.rdar://150791778