Skip to content

Commit 7316318

Browse files
committed
SILGen: Add test for @cdecl testing generated code and C name
1 parent d9566c6 commit 7316318

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

test/SILGen/cdecl-official.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-emit-silgen %s -module-name cdecl \
4+
// RUN: -enable-experimental-feature CDecl > %t/out.sil
5+
// RUN: %FileCheck %s -input-file %t/out.sil
6+
7+
// REQUIRES: swift_feature_CDecl
8+
9+
// CHECK-LABEL: sil hidden [thunk] [ossa] @pear : $@convention(c)
10+
// CHECK: function_ref @$s5cdecl5apple{{[_0-9a-zA-Z]*}}F
11+
// CHECK-LABEL: sil hidden [ossa] @$s5cdecl5apple{{[_0-9a-zA-Z]*}}F
12+
@cdecl(pear)
13+
func apple(_ f: @convention(c) (Int) -> Int) { }
14+
15+
// CHECK-LABEL: sil hidden [ossa] @$s5cdecl16forceCEntryPoint{{[_0-9a-zA-Z]*}}F
16+
// CHECK: function_ref @grapefruit : $@convention(c) (Int) -> Int
17+
// CHECK: function_ref apple(_:)
18+
// CHECK: function_ref @$s5cdecl5appleyyS2iXCF : $@convention(thin) (@convention(c) (Int) -> Int) -> ()
19+
// FIXME should it be function_ref @apple?
20+
func forceCEntryPoint() {
21+
apple(orange)
22+
}
23+
24+
// CHECK-LABEL: sil hidden [thunk] [ossa] @grapefruit : $@convention(c)
25+
// CHECK: function_ref @$s5cdecl6orange{{[_0-9a-zA-Z]*}}F
26+
// CHECK-LABEL: sil hidden [ossa] @$s5cdecl6orange{{[_0-9a-zA-Z]*}}F
27+
@cdecl(grapefruit)
28+
func orange(_ x: Int) -> Int {
29+
return x
30+
}
31+
32+
// CHECK-LABEL: sil [serialized] [thunk] [ossa] @cauliflower : $@convention(c)
33+
// CHECK: function_ref @$s5cdecl8broccoli{{[_0-9a-zA-Z]*}}F
34+
// CHECK-LABEL: sil [ossa] @$s5cdecl8broccoli{{[_0-9a-zA-Z]*}}F
35+
// FIXME should it be `sil hidden`?
36+
@cdecl(cauliflower)
37+
public func broccoli(_ x: Int) -> Int {
38+
return x
39+
}
40+
41+
// CHECK-LABEL: sil private [thunk] [ossa] @collard_greens : $@convention(c)
42+
// CHECK: function_ref @$s5cdecl4kale[[PRIVATE:.*]]
43+
// CHECK: sil private [ossa] @$s5cdecl4kale[[PRIVATE:.*]]
44+
@cdecl(collard_greens)
45+
private func kale(_ x: Int) -> Int {
46+
return x
47+
}
48+
49+
// CHECK-LABEL: sil private [thunk] [ossa] @defaultName : $@convention(c)
50+
// CHECK: function_ref @$s5cdecl11defaultName[[PRIVATE:.*]]
51+
// CHECK: sil private [ossa] @$s5cdecl11defaultName[[PRIVATE:.*]]
52+
@cdecl
53+
private func defaultName(_ x: Int) -> Int {
54+
return x
55+
}

0 commit comments

Comments
 (0)