[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:
fahadnayyar
2025-01-09 09:42:24 -08:00
committed by GitHub
parent 8ac6a6b816
commit 43e663d0fd
4 changed files with 41 additions and 0 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -57,3 +57,7 @@ module Templates {
module SwiftImportAs {
header "SwiftImportAs.h"
}
module SwiftReturnOwnershipForObjC {
header "SwiftReturnOwnershipForObjC.h"
}

View 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);