[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
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
@@ -57,3 +57,7 @@ module Templates {
|
||||
module SwiftImportAs {
|
||||
header "SwiftImportAs.h"
|
||||
}
|
||||
|
||||
module SwiftReturnOwnershipForObjC {
|
||||
header "SwiftReturnOwnershipForObjC.h"
|
||||
}
|
||||
|
||||
11
clang/test/APINotes/swift-return-ownership.m
Normal file
11
clang/test/APINotes/swift-return-ownership.m
Normal file
@@ -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);
|
||||
Reference in New Issue
Block a user