[all-commits] [llvm/llvm-project] 62a2f0: [APINotes] Add support for SWIFT_RETURED_AS_UNRETA...

fahadnayyar via All-commits all-commits at lists.llvm.org
Wed May 7 13:43:01 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 62a2f0fdc74f086c875833eefe9099bd30f41957
      https://github.com/llvm/llvm-project/commit/62a2f0fdc74f086c875833eefe9099bd30f41957
  Author: fahadnayyar <30953967+fahadnayyar at users.noreply.github.com>
  Date:   2025-05-07 (Wed, 07 May 2025)

  Changed paths:
    M clang/include/clang/APINotes/Types.h
    M clang/lib/APINotes/APINotesFormat.h
    M clang/lib/APINotes/APINotesReader.cpp
    M clang/lib/APINotes/APINotesWriter.cpp
    M clang/lib/APINotes/APINotesYAMLCompiler.cpp
    M clang/lib/Sema/SemaAPINotes.cpp
    M clang/test/APINotes/Inputs/Headers/SwiftImportAs.apinotes
    M clang/test/APINotes/Inputs/Headers/SwiftImportAs.h
    M clang/test/APINotes/swift-import-as.cpp

  Log Message:
  -----------
  [APINotes] Add support for SWIFT_RETURED_AS_UNRETAINED_BY_DEFAULT (#138699)

This patch adds support in APINotes for annotating C++ user-defined
types with: `swift_attr("returned_as_unretained_by_default")`
This attribute allows to specify a default ownership convention for
return values of `SWIFT_SHARED_REFERENCE` c++ types. Specifically, it
marks all unannotated return values of this type as `unretained` (`+0`)
by default, unless explicitly overridden at the API level using
`swift_attr("returns_retained")` or `swift_attr("returns_unretained")`.

The corresponding Swift compiler support for this annotation enables
developers to suppress warnings about unannotated return ownership in
large codebases while maintaining safe and predictable ownership
semantics. By enabling this in APINotes, library authors can define this
behavior externally without needing to modify C++ source headers
directly.

### Example usage in APINotes:
```
- Name: RefCountedTypeWithDefaultConvention
  SwiftImportAs: reference
  SwiftDefaultOwnership: unretained

```
rdar://150764491



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list