Skip to content

Commit 43e663d

Browse files
authored
[APINotes] [NFC] Add tests for SWIFT_RETURNS_(UN)RETAINED for ObjC APIs (#122167)
Adding test case to verify that SwiftReturnOwnership works correctly for ObjC functions and methods as well. rdar://142504115
1 parent 8ac6a6b commit 43e663d

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
Name: SwiftImportAsForObjC
3+
Classes:
4+
- Name: MethodTest
5+
Methods:
6+
- Selector: getUnowned
7+
MethodKind: Instance
8+
SwiftReturnOwnership: unretained
9+
- Selector: getOwned
10+
MethodKind: Instance
11+
SwiftReturnOwnership: retained
12+
13+
Functions:
14+
- Name: getObjCUnowned
15+
SwiftReturnOwnership: unretained
16+
- Name: getObjCOwned
17+
SwiftReturnOwnership: retained
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct RefCountedType { int value; };
2+
3+
@interface MethodTest
4+
- (struct RefCountedType *)getUnowned;
5+
- (struct RefCountedType *)getOwned;
6+
@end
7+
8+
struct RefCountedType * getObjCUnowned(void);
9+
struct RefCountedType * getObjCOwned(void);

clang/test/APINotes/Inputs/Headers/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ module Templates {
5757
module SwiftImportAs {
5858
header "SwiftImportAs.h"
5959
}
60+
61+
module SwiftReturnOwnershipForObjC {
62+
header "SwiftReturnOwnershipForObjC.h"
63+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// 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
3+
// RUN: %clang_cc1 -ast-print %t/ModulesCache/SwiftReturnOwnershipForObjC.pcm | FileCheck %s
4+
#import <SwiftReturnOwnershipForObjC.h>
5+
6+
// CHECK: @interface MethodTest
7+
// CHECK: - (struct RefCountedType *)getUnowned __attribute__((swift_attr("returns_unretained")));
8+
// CHECK: - (struct RefCountedType *)getOwned __attribute__((swift_attr("returns_retained")));
9+
// CHECK: @end
10+
// CHECK: __attribute__((swift_attr("returns_unretained"))) struct RefCountedType *getObjCUnowned(void);
11+
// CHECK: __attribute__((swift_attr("returns_retained"))) struct RefCountedType *getObjCOwned(void);

0 commit comments

Comments
 (0)