Skip to content

[cxx-interop] Disabling should be annotated with SWIFT_RETURNS_(UN)RETAINED warning #81411

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

fahadnayyar
Copy link
Contributor

In Swift 6.1, we introduced warnings for C++ APIs returning SWIFT_SHARED_REFERENCE types that lack the SWIFT_RETURNS_(UN)RETAINED annotations. These warnings serve as a reminder to annotate APIs, as the absence of these annotations can lead to arbitrary assumptions about the ownership of returned SWIFT_SHARED_REFERENCE values. This could result in both use-after-free (memory safety) bugs and memory leaks.

We have received feedback from a few adopters indicating potential false positive cases where these warnings are triggered. Consequently, we have decided to disable these warnings in Swift 6.2 and re-qualify the warnings on larger projects to ensure their effectiveness and eliminate false positives. Our intention is to re-enable the warnings in later beta releases of Swift 6.2 once we have stronger evidence of their effectiveness on large codebases and proof that there are no false positives.

rdar://150937617
rdar://150800115

@fahadnayyar
Copy link
Contributor Author

@swift-ci please smoke test

@fahadnayyar fahadnayyar self-assigned this May 9, 2025
@fahadnayyar fahadnayyar added the c++ interop Feature: Interoperability with C++ label May 9, 2025
@fahadnayyar fahadnayyar marked this pull request as ready for review May 9, 2025 18:05
@fahadnayyar fahadnayyar merged commit 49aea31 into swiftlang:main May 10, 2025
3 checks passed
@ADKaster
Copy link
Contributor

fwiw I was seeing this on Ladybird as well: https://gist.github.com/ADKaster/0fb9a20076718fee3ad11305635075b8

Swift version 6.2-dev (LLVM 978186dad468cc4, Swift 2d7b7a73f8f1a84)
Target: x86_64-unknown-linux-gnu
Build config: +assertions

(swiftly main-snapshot-2025-04-30)

None of my types are actually SWIFT_SHARED_REFERENCE: They are all (or should be all, due to an ancestor base class being) SWIFT_UNSAFE_REFERENCE. In theory this means 'memory not managed by swift, but by my custom GC/memory strategy', so the 32k lines of diagnostics suggesting to add the SWIFT_RETURNS_(UN)RETAINED annotations is unwelcome.

Catfish-Man pushed a commit that referenced this pull request May 15, 2025
…TAINED warning (#81411)

In Swift 6.1, we introduced warnings for C++ APIs returning
SWIFT_SHARED_REFERENCE types that lack the SWIFT_RETURNS_(UN)RETAINED
annotations. These warnings serve as a reminder to annotate APIs, as the
absence of these annotations can lead to arbitrary assumptions about the
ownership of returned SWIFT_SHARED_REFERENCE values. This could result
in both use-after-free (memory safety) bugs and memory leaks.

We have received feedback from a few adopters indicating potential false
positive cases where these warnings are triggered. Consequently, we have
decided to disable these warnings in Swift 6.2 and re-qualify the
warnings on larger projects to ensure their effectiveness and eliminate
false positives. Our intention is to re-enable the warnings in later
beta releases of Swift 6.2 once we have stronger evidence of their
effectiveness on large codebases and proof that there are no false
positives.

rdar://150937617
rdar://150800115
fahadnayyar added a commit to fahadnayyar/swift that referenced this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants