Skip to content

Commit c590d72

Browse files
committed
Steal files from other branch
1 parent 3a317b3 commit c590d72

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int counter = 0;
2+
3+
int count() {
4+
return ++counter;
5+
}
6+
7+
namespace Namespaced {
8+
int counter = 0;
9+
10+
int count() {
11+
return ++counter;
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extern int counter;
2+
3+
int count();
4+
5+
namespace Namespaced {
6+
extern int counter;
7+
8+
int count();
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test that global variables are handled properly by the ClangImporter.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-build-swift %s -I %S/Inputs -emit-ir -o %t/global-var.ir -Xfrontend -enable-cxx-interop
5+
// RUN: %FileCheck < %t/global-var.ir %s
6+
7+
// CHECK: @counter = external global i32, align 4
8+
// CHECK: @_ZN10Namespaced7counterE = external global i32, align 4
9+
10+
import GlobalVar
11+
12+
func getCounter() -> CInt {
13+
return counter
14+
}
15+
16+
func getNamespacedCounter() -> CInt {
17+
return Namespaced.counter
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Test that global variables are handled properly by the ClangImporter.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-build-swift %s -I %S/Inputs -emit-sil -o %t/global-var.sil -Xfrontend -enable-cxx-interop
5+
// RUN: %FileCheck < %t/global-var.sil %s
6+
7+
// CHECK: %0 = global_addr @counter : $*Int32
8+
// CHECK: %0 = global_addr @_ZN10Namespaced7counterE : $*Int32
9+
10+
import GlobalVar
11+
12+
func getCounter() -> CInt {
13+
return counter
14+
}
15+
16+
func getNamespacedCounter() -> CInt {
17+
return Namespaced.counter
18+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Test that global variables are handled properly by the ClangImporter.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-clang -c %S/Inputs/global-var.cc -I %S/Inputs -fPIC -o %t/global-var.o
5+
// RUN: %target-build-swift %s -I %S/Inputs -o %t/global-var %t/global-var.o -Xfrontend -enable-cxx-interop
6+
// RUN: %target-codesign %t/global-var
7+
// RUN: %target-run %t/global-var
8+
//
9+
// REQUIRES: executable_test
10+
11+
import GlobalVar
12+
import StdlibUnittest
13+
14+
var StaticsTestSuite = TestSuite("global-var")
15+
16+
StaticsTestSuite.test("global-var") {
17+
expectEqual(counter, 0)
18+
expectEqual(count(), 1)
19+
expectEqual(counter, 1)
20+
counter = 42
21+
expectEqual(counter, 42)
22+
expectEqual(count(), 43)
23+
}
24+
25+
StaticsTestSuite.test("namespaced-global-var") {
26+
expectEqual(Namespaced.counter, 0)
27+
expectEqual(Namespaced.count(), 1)
28+
expectEqual(Namespaced.counter, 1)
29+
Namespaced.counter = 42
30+
expectEqual(Namespaced.counter, 42)
31+
expectEqual(Namespaced.count(), 43)
32+
}
33+
34+
runAllTests()

0 commit comments

Comments
 (0)