Skip to content

Commit 6321392

Browse files
committed
Interleave code and checks
1 parent fdcb330 commit 6321392

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

test/Interop/Cxx/extern-var/extern-var-irgen.swift

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,50 @@
22
// RUN: %target-build-swift %s -I %S/Inputs -emit-ir -o %t/extern-var.ir -Xfrontend -enable-cxx-interop
33
// RUN: %FileCheck < %t/extern-var.ir %s
44

5-
// CHECK: @counter = external global i32, align 4
6-
7-
// CHECK: define hidden swiftcc i32 @"$s4main10getCounters5Int32VyF"() #0
8-
// CHECK: [[LOAD:%.*]] = load i32, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @counter to %Ts5Int32V*), i32 0, i32 0), align 4
9-
// CHECK: ret i32 [[LOAD]]
10-
11-
// CHECK: define hidden swiftcc void @"$s4main10setCounteryys5Int32VF"(i32 %0) #0
12-
// CHECK: store i32 %0, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @counter to %Ts5Int32V*), i32 0, i32 0), align 4
13-
14-
// CHECK: define hidden swiftcc i32 @"$s4main20getNamespacedCounters5Int32VyF"() #0
15-
//FIXME mangle non-top-level var names to prevent name collisions and check:
16-
// load i32, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @Namespaced.counter to %Ts5Int32V*), i32 0, i32 0), align 4
17-
// CHECK: ret i32 %1
18-
19-
// CHECK: define hidden swiftcc void @"$s4main20setNamespacedCounteryys5Int32VF"(i32 %0) #0
20-
//FIXME mangle non-top-level var names to prevent name collisions and check:
21-
// store i32 %0, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @Namespaced.counter to %Ts5Int32V*), i32 0, i32 0), align 4
22-
23-
// CHECK: define hidden swiftcc void @"$s4main17passingVarAsInoutyyF"() #0
24-
// CHECK: call swiftcc void @"$s4main11modifyInoutyys5Int32VzF"(%Ts5Int32V* nocapture dereferenceable(4) bitcast (i32* @counter to %Ts5Int32V*))
25-
265
import ExternVar
276

287
func getCounter() -> CInt {
298
return counter
309
}
3110

11+
// CHECK: @counter = external global i32, align 4
12+
13+
// CHECK: define hidden swiftcc i32 @"$s4main10getCounters5Int32VyF"() #0
14+
// CHECK: [[LOAD:%.*]] = load i32, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @counter to %Ts5Int32V*), i32 0, i32 0), align 4
15+
// CHECK: ret i32 [[LOAD]]
16+
3217
func setCounter(_ c: CInt) {
3318
counter = c
3419
}
3520

21+
// CHECK: define hidden swiftcc void @"$s4main10setCounteryys5Int32VF"(i32 %0) #0
22+
// CHECK: store i32 %0, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @counter to %Ts5Int32V*), i32 0, i32 0), align 4
23+
3624
func getNamespacedCounter() -> CInt {
3725
return Namespaced.counter
3826
}
3927

28+
// CHECK: define hidden swiftcc i32 @"$s4main20getNamespacedCounters5Int32VyF"() #0
29+
//FIXME mangle non-top-level var names to prevent name collisions and check:
30+
// load i32, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @Namespaced.counter to %Ts5Int32V*), i32 0, i32 0), align 4
31+
// CHECK: ret i32 %1
32+
4033
func setNamespacedCounter(_ c: CInt) {
4134
Namespaced.counter = c
4235
}
4336

37+
// CHECK: define hidden swiftcc void @"$s4main20setNamespacedCounteryys5Int32VF"(i32 %0) #0
38+
//FIXME mangle non-top-level var names to prevent name collisions and check:
39+
// store i32 %0, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @Namespaced.counter to %Ts5Int32V*), i32 0, i32 0), align 4
40+
4441
func modifyInout(_ c: inout CInt) {
4542
c = 42
4643
}
4744

4845
func passingVarAsInout() {
4946
modifyInout(&counter)
5047
}
48+
49+
// CHECK: define hidden swiftcc void @"$s4main17passingVarAsInoutyyF"() #0
50+
// CHECK: call swiftcc void @"$s4main11modifyInoutyys5Int32VzF"(%Ts5Int32V* nocapture dereferenceable(4) bitcast (i32* @counter to %Ts5Int32V*))
51+

test/Interop/Cxx/extern-var/extern-var-silgen.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
// RUN: %target-build-swift %s -I %S/Inputs -emit-sil -o %t/extern-var.sil -Xfrontend -enable-cxx-interop
33
// RUN: %FileCheck < %t/extern-var.sil %s
44

5+
import ExternVar
6+
7+
func getCounter() -> CInt {
8+
return counter
9+
}
10+
511
// CHECK: sil_global @counter : $Int32
612

713
// CHECK: sil hidden @$s4main10getCounters5Int32VyF : $@convention(thin) () -> Int32
@@ -10,52 +16,46 @@
1016
// CHECK: [[LOAD:%.*]] = load [[ACCESS]] : $*Int32
1117
// CHECK: return [[LOAD]] : $Int32
1218

19+
func setCounter(_ c: CInt) {
20+
counter = c
21+
}
22+
1323
// CHECK: sil hidden @$s4main10setCounteryys5Int32VF : $@convention(thin) (Int32) -> ()
1424
// CHECK: [[COUNTER:%.*]] = global_addr @counter : $*Int32
1525
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[COUNTER]] : $*Int32
1626
// CHECK: store %0 to [[ACCESS]] : $*Int32
1727

28+
func getNamespacedCounter() -> CInt {
29+
return Namespaced.counter
30+
}
31+
1832
// sil hidden @$s4main20getNamespacedCounters5Int32VyF : $@convention(thin) () -> Int32
1933
//FIXME mangle non-top-level var names to prevent name collisions
2034
// %0 = global_addr @Namespaced.counter : $*Int32
2135
// CHECK: [[ACCESS:%.*]] = begin_access [read] [dynamic] %0 : $*Int32
2236
// CHECK: [[LOAD:%.*]] = load [[ACCESS]] : $*Int32
2337
// CHECK: return [[LOAD]] : $Int32
2438

39+
func setNamespacedCounter(_ c: CInt) {
40+
Namespaced.counter = c
41+
}
42+
2543
// CHECK: sil hidden @$s4main20setNamespacedCounteryys5Int32VF : $@convention(thin) (Int32) -> ()
2644
//FIXME mangle non-top-level var names to prevent name collisions
2745
// %1 = global_addr @Namespaced.counter : $*Int32
2846
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [dynamic] %1 : $*Int32
2947
// CHECK: store %0 to [[ACCESS]] : $*Int32
3048

31-
// CHECK: sil hidden @$s4main17passingVarAsInoutyyF : $@convention(thin) () -> ()
32-
// CHECK: [[COUNTER:%.*]] = global_addr @counter : $*Int32
33-
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[COUNTER]] : $*Int32
34-
// CHECK: [[FUNCTION:%.*]] = function_ref @$s4main11modifyInoutyys5Int32VzF : $@convention(thin) (@inout Int32) -> ()
35-
// CHECK: apply [[FUNCTION]]([[ACCESS]]) : $@convention(thin) (@inout Int32) -> ()
36-
37-
import ExternVar
38-
39-
func getCounter() -> CInt {
40-
return counter
41-
}
42-
43-
func setCounter(_ c: CInt) {
44-
counter = c
45-
}
46-
47-
func getNamespacedCounter() -> CInt {
48-
return Namespaced.counter
49-
}
50-
51-
func setNamespacedCounter(_ c: CInt) {
52-
Namespaced.counter = c
53-
}
54-
5549
func modifyInout(_ c: inout CInt) {
5650
c = 42
5751
}
5852

5953
func passingVarAsInout() {
6054
modifyInout(&counter)
6155
}
56+
57+
// CHECK: sil hidden @$s4main17passingVarAsInoutyyF : $@convention(thin) () -> ()
58+
// CHECK: [[COUNTER:%.*]] = global_addr @counter : $*Int32
59+
// CHECK: [[ACCESS:%.*]] = begin_access [modify] [dynamic] [[COUNTER]] : $*Int32
60+
// CHECK: [[FUNCTION:%.*]] = function_ref @$s4main11modifyInoutyys5Int32VzF : $@convention(thin) (@inout Int32) -> ()
61+
// CHECK: apply [[FUNCTION]]([[ACCESS]]) : $@convention(thin) (@inout Int32) -> ()

0 commit comments

Comments
 (0)