Skip to content

Commit 19360db

Browse files
committed
IRGen: Add tests for @cdecl @implementation
1 parent a654df7 commit 19360db

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

test/IRGen/Inputs/objc_implementation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if __OBJC__
12
#import <Foundation/Foundation.h>
23

34
@interface ImplClass: NSObject <NSCopying>
@@ -31,11 +32,13 @@
3132
- (void)category2Method:(int)param;
3233

3334
@end
35+
#endif
3436

3537
extern void implFunc(int param);
3638
extern void implFuncCName(int param) __asm__("_implFuncAsmName");
39+
extern void implFuncRenamed_C(int param) __attribute__((swift_name("implFuncRenamed_Swift(param:)")));
3740

38-
41+
#if __OBJC__
3942
@interface NoImplClass
4043

4144
- (void)noImplMethod:(int)param;
@@ -57,3 +60,4 @@ extern void implFuncCName(int param) __asm__("_implFuncAsmName");
5760
@property (assign) int afterInt;
5861

5962
@end
63+
#endif

test/IRGen/cdecl_implementation.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
2+
// RUN: -enable-experimental-feature CImplementation \
3+
// RUN: -enable-experimental-feature CDecl \
4+
// RUN: -disable-objc-interop \
5+
// RUN: -F %clang-importer-sdk-path/frameworks %s \
6+
// RUN: -import-objc-header %S/Inputs/objc_implementation.h -emit-ir \
7+
// RUN: -target %target-future-triple > %t.ir
8+
// RUN: %FileCheck --input-file %t.ir %s
9+
10+
// REQUIRES: swift_feature_CImplementation
11+
// REQUIRES: swift_feature_CDecl
12+
13+
@implementation @cdecl
14+
public func implFunc(_ param: Int32) {}
15+
16+
@implementation @cdecl
17+
public func implFuncCName(_ param: Int32) {}
18+
19+
@implementation @cdecl(implFuncRenamed_C)
20+
public func implFuncRenamed_Swift(param: Int32) {}
21+
22+
public func fn() {
23+
implFunc(2)
24+
implFuncCName(3)
25+
implFuncRenamed_Swift(param: 4)
26+
}
27+
28+
/// implFunc(_:)
29+
// CHECK-LABEL: define{{.*}} void @implFunc
30+
31+
// FIXME: We'd like this to be internal or hidden, not public.
32+
// CHECK: define{{.*}} swiftcc void @"$s20cdecl_implementation8implFuncyys5Int32VF"
33+
34+
/// inplFuncCName(_:)
35+
// CHECK-LABEL: define{{.*}} void @"\01_implFuncAsmName"
36+
37+
// FIXME: We'd like this to be internal or hidden, not public.
38+
// CHECK: define{{.*}} swiftcc void @"$s20cdecl_implementation13implFuncCNameyys5Int32VF"
39+
40+
/// fn()
41+
// CHECK-LABEL: define{{.*}} swiftcc void @"$s20cdecl_implementation2fnyyF"
42+
// CHECK: call void @implFunc
43+
// CHECK: call void @"\01_implFuncAsmName"
44+
// CHECK: call void @implFuncRenamed_C
45+
// CHECK: ret void
46+
// CHECK: }
47+

test/IRGen/objc_implementation.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ public func implFunc(_ param: Int32) {}
185185
@_objcImplementation @_cdecl("implFuncCName")
186186
public func implFuncCName(_ param: Int32) {}
187187

188+
@implementation @_cdecl("implFuncRenamed_C")
189+
public func implFuncRenamed_Swift(param: Int32) {}
190+
188191
public func fn(impl: ImplClass, swiftSub: SwiftSubclass) {
189192
impl.mainMethod(0)
190193
swiftSub.mainMethod(1)
191194
implFunc(2)
192195
implFuncCName(3)
196+
implFuncRenamed_Swift(param: 4)
193197
}
194198

195199
// Swift calling convention -[ImplClass init]
@@ -329,12 +333,12 @@ public func fn(impl: ImplClass, swiftSub: SwiftSubclass) {
329333
// Swift calling convention SwiftSubclass.deinit (deallocating)
330334
// CHECK-LABEL: define swiftcc void @"$s19objc_implementation13SwiftSubclassCfD"
331335

332-
// inplFunc(_:)
336+
// implFunc(_:)
333337
// CHECK-LABEL: define void @implFunc
334338
// FIXME: We'd like this to be internal or hidden, not public.
335339
// CHECK: define swiftcc void @"$s19objc_implementation8implFuncyys5Int32VF"
336340

337-
// inplFuncCName(_:)
341+
// implFuncCName(_:)
338342
// CHECK-LABEL: define void @"\01_implFuncAsmName"
339343
// FIXME: We'd like this to be internal or hidden, not public.
340344
// CHECK: define swiftcc void @"$s19objc_implementation13implFuncCNameyys5Int32VF"
@@ -346,6 +350,7 @@ public func fn(impl: ImplClass, swiftSub: SwiftSubclass) {
346350
// CHECK: [[SEL_2:%[^ ]+]] = load ptr, ptr @"\01L_selector(mainMethod:)", align 8
347351
// CHECK: call void @objc_msgSend(ptr {{.*}}, ptr [[SEL_2]], i32 1)
348352
// CHECK: call void @implFunc
353+
// CHECK: call void @"\01_implFuncAsmName"
349354
// CHECK: ret void
350355
// CHECK: }
351356

0 commit comments

Comments
 (0)