Skip to content

[cxx-interop] Rewrite missing RETURNS_RETAINED diagnostics#87752

Draft
j-hui wants to merge 6 commits intoswiftlang:mainfrom
j-hui:missing-returns-retained-diagnostics-boogaloo
Draft

[cxx-interop] Rewrite missing RETURNS_RETAINED diagnostics#87752
j-hui wants to merge 6 commits intoswiftlang:mainfrom
j-hui:missing-returns-retained-diagnostics-boogaloo

Conversation

@j-hui
Copy link
Contributor

@j-hui j-hui commented Mar 9, 2026

No description provided.

j-hui added 2 commits March 9, 2026 13:01
Moving this here gives us access to ClangImporter's internal APIs for
future improvements. It also keeps changes to interop-specific
diagnostics localized to the interop-specific part of the compiler.
@j-hui
Copy link
Contributor Author

j-hui commented Mar 9, 2026

@swift-ci please smoke test

@j-hui j-hui force-pushed the missing-returns-retained-diagnostics-boogaloo branch 2 times, most recently from bb9a82b to 04a3672 Compare March 10, 2026 01:26
j-hui added 3 commits March 9, 2026 18:51
We shouldn't need to be defensive about calling things that aren't
functions or ObjC methods (technically distinct from functions), or
about calling deduction guides and destructors (technically functions,
but not imported into Swift).

Also, move around the checking logic a little so that it flows more
intuitively---check whether the warning should apply to the function
decl in the first place, *then* look at its return type and determine
whether the called function is missing annotations.

Note that clang::FunctionTemplateDecls are also exempt from this
annotation. Previously, it was implicitly exempted because the logic for
extracting the return type from a function decl simply did not account
for function templates. Now, the exemption is made explicit.
Rename getCxxRefConventionWithAttrs() to getOwnershipOfReturnedFRT()
(since this isn't specific to C++)

Move it to ClangAnalysis.cpp and reuse some helper functions in there
rather than duplicating code.
This helper function is barely doing anything. Inline it for more
clarity about control flow.
@j-hui j-hui force-pushed the missing-returns-retained-diagnostics-boogaloo branch from 04a3672 to dcb3dca Compare March 10, 2026 01:59
Note that this actually tightens the default ownership checking a little
bit; it was too permissive before.

Tests to come.

rdar://170130742
@j-hui j-hui force-pushed the missing-returns-retained-diagnostics-boogaloo branch from dcb3dca to 776f573 Compare March 10, 2026 02:15
@j-hui
Copy link
Contributor Author

j-hui commented Mar 10, 2026

@swift-ci please smoke test

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.

1 participant