-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Re-enable warnings for unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types under an experimental feature flag #82488
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
base: main
Are you sure you want to change the base?
Conversation
…S_(UN)RETAINED warning (swiftlang#81411)" This reverts commit 49aea31.
… per source location
@swift-ci please smoke test |
/// Emit a warning when a C++ API returns a SWIFT_SHARED_REFERENCE type | ||
/// without being explicitly annotated with either SWIFT_RETURNS_RETAINED | ||
/// or SWIFT_RETURNS_UNRETAINED. | ||
EXPERIMENTAL_FEATURE(WarnUnannotatedReturnOfCxxFrt, false) |
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.
Why is the second argument false here? Do we want this flag to be available for production compilers?
clang::SourceLocation spellingLoc; | ||
if (loc.isMacroID()) { | ||
clang::SourceLocation expansionLoc = | ||
sourceMgr.getImmediateExpansionRange(loc).getBegin(); |
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.
Would the immediate expansion range work as intended for nested macros?
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.
In what case do we need this trick? And why wouldn't always using the spelling location work?
@@ -449,4 +449,34 @@ void bRelease(DefaultOwnershipInheritance::BaseTypeNonDefault *v) {}; | |||
void dRetain(DefaultOwnershipInheritance::DerivedTypeNonDefault *v) {}; | |||
void dRelease(DefaultOwnershipInheritance::DerivedTypeNonDefault *v) {}; | |||
|
|||
namespace SourceLocationCaching { |
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.
I don't see testing for the macro case.
This patch re-enables diagnostics for unannotated C++ functions or methods returning
SWIFT_SHARED_REFERENCE
types. These warnings now fire only once per source location, even in the presence of multiple template instantiations. This avoids diagnostic duplication that was a key source of noise in the compilation of larger codebases.These warnings were previously disabled starting in Swift 6.2 via PR-#81411 due to concerns around false positives and excessive duplication in projects adopting C++ interop. This patch addresses the duplication issue by adding source-location-based caching, which ensures that a warning is emitted only once per source location, even across template instantiations with different types.
However, the false positive issue remains to be investigated and will be addressed in a follow-up patch. Until that happens, the warnings are gated behind a new experimental feature flag:
WarnUnannotatedReturnOfCxxFrt
. This feature will be enabled by default only after thorough qualification and testing on large C++ codebases.rdar://154261051