Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
Name: SwiftImportAsForObjC
Classes:
- Name: MethodTest
Methods:
- Selector: getUnowned
MethodKind: Instance
SwiftReturnOwnership: unretained
- Selector: getOwned
MethodKind: Instance
SwiftReturnOwnership: retained

Functions:
- Name: getObjCUnowned
SwiftReturnOwnership: unretained
- Name: getObjCOwned
SwiftReturnOwnership: retained
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct RefCountedType { int value; };

@interface MethodTest
- (struct RefCountedType *)getUnowned;
- (struct RefCountedType *)getOwned;
@end

struct RefCountedType * getObjCUnowned(void);
struct RefCountedType * getObjCOwned(void);
4 changes: 4 additions & 0 deletions clang/test/APINotes/Inputs/Headers/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ module Templates {
module SwiftImportAs {
header "SwiftImportAs.h"
}

module SwiftReturnOwnershipForObjC {
header "SwiftReturnOwnershipForObjC.h"
}
11 changes: 11 additions & 0 deletions clang/test/APINotes/swift-return-ownership.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: rm -rf %t && mkdir -p %t
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers %s
// RUN: %clang_cc1 -ast-print %t/ModulesCache/SwiftReturnOwnershipForObjC.pcm | FileCheck %s
#import <SwiftReturnOwnershipForObjC.h>

// CHECK: @interface MethodTest
// CHECK: - (struct RefCountedType *)getUnowned __attribute__((swift_attr("returns_unretained")));
// CHECK: - (struct RefCountedType *)getOwned __attribute__((swift_attr("returns_retained")));
// CHECK: @end
// CHECK: __attribute__((swift_attr("returns_unretained"))) struct RefCountedType *getObjCUnowned(void);
// CHECK: __attribute__((swift_attr("returns_retained"))) struct RefCountedType *getObjCOwned(void);
Loading