Skip to content

Conversation

egorzhdan
Copy link
Contributor

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

@egorzhdan
Copy link
Contributor Author

@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
@egorzhdan egorzhdan force-pushed the egorzhdan/frt-indirection branch from 5628bf4 to 0a766e5 Compare August 22, 2025 10:57
@egorzhdan egorzhdan requested a review from jckarter as a code owner August 22, 2025 10:57
Comment on lines -4551 to -4555
// 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.
Copy link
Contributor Author

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!.

Comment on lines -35 to -38
if (type.isForeignReferenceType())
return getClangType(type.getASTType()
->wrapInPointer(PTK_UnsafePointer)
->getCanonicalType());
Copy link
Contributor Author

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.

@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

1 similar comment
@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan egorzhdan enabled auto-merge August 22, 2025 21:28
@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

2 similar comments
@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan egorzhdan merged commit d1a1f70 into swiftlang:main Aug 24, 2025
5 checks passed
@@ -0,0 +1,54 @@
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xfrontend -disable-availability-checking)
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants