|
2 | 2 | // RUN: %target-build-swift %s -I %S/Inputs -emit-ir -o %t/extern-var.ir -Xfrontend -enable-cxx-interop
|
3 | 3 | // RUN: %FileCheck < %t/extern-var.ir %s
|
4 | 4 |
|
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 |
| - |
26 | 5 | import ExternVar
|
27 | 6 |
|
28 | 7 | func getCounter() -> CInt {
|
29 | 8 | return counter
|
30 | 9 | }
|
31 | 10 |
|
| 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 | + |
32 | 17 | func setCounter(_ c: CInt) {
|
33 | 18 | counter = c
|
34 | 19 | }
|
35 | 20 |
|
| 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 | + |
36 | 24 | func getNamespacedCounter() -> CInt {
|
37 | 25 | return Namespaced.counter
|
38 | 26 | }
|
39 | 27 |
|
| 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 | + |
40 | 33 | func setNamespacedCounter(_ c: CInt) {
|
41 | 34 | Namespaced.counter = c
|
42 | 35 | }
|
43 | 36 |
|
| 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 | + |
44 | 41 | func modifyInout(_ c: inout CInt) {
|
45 | 42 | c = 42
|
46 | 43 | }
|
47 | 44 |
|
48 | 45 | func passingVarAsInout() {
|
49 | 46 | modifyInout(&counter)
|
50 | 47 | }
|
| 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 | + |
0 commit comments