Skip to content

Commit ee775e6

Browse files
committed
Add more tests
1 parent aba7326 commit ee775e6

File tree

5 files changed

+89
-18
lines changed

5 files changed

+89
-18
lines changed
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
int counter = 0;
22

3-
int count() {
4-
return ++counter;
3+
int getCounterFromCxx() {
4+
return counter;
5+
}
6+
7+
void setCounterFromCxx(int c) {
8+
counter = c;
59
}
610

711
namespace Namespaced {
812
int counter = 0;
913

10-
int count() {
11-
return ++counter;
14+
int getCounterFromCxx() {
15+
return counter;
16+
}
17+
18+
void setCounterFromCxx(int c) {
19+
counter = c;
1220
}
1321
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
extern int counter;
22

3-
int count();
3+
int getCounterFromCxx();
4+
void setCounterFromCxx(int);
45

56
namespace Namespaced {
67
extern int counter;
78

8-
int count();
9+
int getCounterFromCxx();
10+
void setCounterFromCxx(int);
911
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,34 @@
33
// RUN: %FileCheck < %t/extern-var.ir %s
44

55
// CHECK: @counter = external global i32, align 4
6-
//FIXME mangle non-top-level var names to prevent name collisions
7-
// and check @_ZN10Namespaced7counterE = external global i32, align 4
6+
7+
// CHECK: define hidden swiftcc i32 @"$s4main10getCounters5Int32VyF"() #0
8+
// CHECK: load i32, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @counter to %Ts5Int32V*), i32 0, i32 0), align 4
9+
10+
// CHECK: define hidden swiftcc void @"$s4main10setCounteryys5Int32VF"(i32 %0) #0
11+
// CHECK: store i32 %0, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @counter to %Ts5Int32V*), i32 0, i32 0), align 4
12+
13+
// CHECK: define hidden swiftcc i32 @"$s4main20getNamespacedCounters5Int32VyF"() #0
14+
//FIXME mangle non-top-level var names to prevent name collisions and check:
15+
// load i32, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @Namespaced.counter to %Ts5Int32V*), i32 0, i32 0), align 4
16+
// CHECK: define hidden swiftcc void @"$s4main20setNamespacedCounteryys5Int32VF"(i32 %0) #0
17+
//FIXME mangle non-top-level var names to prevent name collisions and check:
18+
// store i32 %0, i32* getelementptr inbounds (%Ts5Int32V, %Ts5Int32V* bitcast (i32* @Namespaced.counter to %Ts5Int32V*), i32 0, i32 0), align 4
819

920
import ExternVar
1021

1122
func getCounter() -> CInt {
1223
return counter
1324
}
1425

26+
func setCounter(_ c: CInt) {
27+
counter = c
28+
}
29+
1530
func getNamespacedCounter() -> CInt {
1631
return Namespaced.counter
1732
}
33+
34+
func setNamespacedCounter(_ c: CInt) {
35+
Namespaced.counter = c
36+
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,40 @@
44
// RUN: %target-build-swift %s -I %S/Inputs -emit-sil -o %t/extern-var.sil -Xfrontend -enable-cxx-interop
55
// RUN: %FileCheck < %t/extern-var.sil %s
66

7+
// CHECK: sil_global @counter : $Int32
8+
9+
// CHECK: sil hidden @$s4main10getCounters5Int32VyF : $@convention(thin) () -> Int32
710
// CHECK: %0 = global_addr @counter : $*Int32
11+
// CHECK: begin_access [read] [dynamic] %0 : $*Int32
12+
13+
// CHECK: sil hidden @$s4main10setCounteryys5Int32VF : $@convention(thin) (Int32) -> ()
14+
// CHECK: %1 = global_addr @counter : $*Int32
15+
// CHECK: %3 = begin_access [modify] [dynamic] %1 : $*Int32
16+
17+
// sil hidden @$s4main20getNamespacedCounters5Int32VyF : $@convention(thin) () -> Int32
18+
//FIXME mangle non-top-level var names to prevent name collisions
19+
// %0 = global_addr @Namespaced.counter : $*Int32
20+
// CHECK: begin_access [read] [dynamic] %0 : $*Int32
21+
22+
// CHECK: sil hidden @$s4main20setNamespacedCounteryys5Int32VF : $@convention(thin) (Int32) -> ()
823
//FIXME mangle non-top-level var names to prevent name collisions
9-
// and check %0 = global_addr @_ZN10Namespaced7counterE : $*Int32
24+
// %1 = global_addr @Namespaced.counter : $*Int32
25+
// CHECK: %4 = begin_access [modify] [dynamic] %1 : $*Int32
1026

1127
import ExternVar
1228

1329
func getCounter() -> CInt {
1430
return counter
1531
}
1632

33+
func setCounter(_ c: CInt) {
34+
counter = c
35+
}
36+
1737
func getNamespacedCounter() -> CInt {
1838
return Namespaced.counter
1939
}
40+
41+
func setNamespacedCounter(_ c: CInt) {
42+
Namespaced.counter = c
43+
}

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,45 @@ import StdlibUnittest
1313

1414
var StaticsTestSuite = TestSuite("extern-var")
1515

16-
StaticsTestSuite.test("extern-var") {
16+
StaticsTestSuite.test("read") {
1717
expectEqual(counter, 0)
18-
expectEqual(count(), 1)
19-
expectEqual(counter, 1)
18+
expectEqual(getCounterFromCxx(), 0)
19+
}
20+
21+
StaticsTestSuite.test("write-from-swift") {
2022
counter = 42
2123
expectEqual(counter, 42)
22-
expectEqual(count(), 43)
24+
expectEqual(getCounterFromCxx(), 42)
25+
}
26+
27+
StaticsTestSuite.test("write-from-cxx") {
28+
setCounterFromCxx(84)
29+
expectEqual(counter, 84)
30+
expectEqual(getCounterFromCxx(), 84)
2331
}
2432

2533
//FIXME mangle non-top-level var names to prevent name collisions
26-
// StaticsTestSuite.test("namespaced-extern-var") {
34+
// StaticsTestSuite.test("namespaced-read") {
2735
// expectEqual(Namespaced.counter, 0)
28-
// expectEqual(Namespaced.count(), 1)
29-
// expectEqual(Namespaced.counter, 1)
36+
// expectEqual(Namespaced.getCounterFromCxx(), 0)
37+
// }
38+
39+
//FIXME mangle non-top-level var names to prevent name collisions
40+
// StaticsTestSuite.test("namespaced-write-from-swift") {
3041
// Namespaced.counter = 42
3142
// expectEqual(Namespaced.counter, 42)
32-
// expectEqual(Namespaced.count(), 43)
43+
// expectEqual(Namespaced.getCounterFromCxx(), 42)
44+
// }
45+
46+
//FIXME mangle non-top-level var names to prevent name collisions
47+
// StaticsTestSuite.test("namespaced-write-from-cxx") {
48+
// Namespaced.setCounterFromCxx(84)
49+
// expectEqual(Namespaced.counter, 84)
50+
// expectEqual(Namespaced.getCounterFromCxx(), 84)
3351
// }
3452

3553
//FIXME mangle non-top-level var names to prevent name collisions
36-
// StaticsTestSuite.test("non-colliding-extern-vars") {
54+
// StaticsTestSuite.test("no-collisions") {
3755
// counter = 12
3856
// Namespaced.counter = 42
3957
// expectEqual(counter, 12)

0 commit comments

Comments
 (0)