|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %{python} %utils/split_file.py -o %t %s |
| 3 | + |
| 4 | +// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library |
| 5 | +// RUN: %target-swift-frontend -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o |
| 6 | +// RUN: %target-clang -x c -c %S/Inputs/tiny-runtime-dummy-refcounting.c -o %t/runtime.o |
| 7 | +// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o |
| 8 | +// RUN: %target-clang %t/a.o %t/print.o %t/runtime.o -o %t/a.out |
| 9 | +// RUN: %target-run %t/a.out | %FileCheck %s |
| 10 | + |
| 11 | +// REQUIRES: executable_test |
| 12 | +// REQUIRES: VENDOR=apple |
| 13 | +// REQUIRES: OS=macosx |
| 14 | + |
| 15 | +// BEGIN MyModule.swift |
| 16 | + |
| 17 | +public var global_in_module_used_in_module = 0 |
| 18 | +public var global_in_module_unused_in_module = 0 |
| 19 | + |
| 20 | +public func foo() { |
| 21 | + global_in_module_used_in_module += 1 |
| 22 | +} |
| 23 | + |
| 24 | +// BEGIN Main.swift |
| 25 | + |
| 26 | +import MyModule |
| 27 | + |
| 28 | +@_silgen_name("putchar") |
| 29 | +func putchar(_: UInt8) |
| 30 | + |
| 31 | +public func print(_ s: StaticString, terminator: StaticString = "\n") { |
| 32 | + var p = s.utf8Start |
| 33 | + while p.pointee != 0 { |
| 34 | + putchar(p.pointee) |
| 35 | + p += 1 |
| 36 | + } |
| 37 | + p = terminator.utf8Start |
| 38 | + while p.pointee != 0 { |
| 39 | + putchar(p.pointee) |
| 40 | + p += 1 |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +@_silgen_name("print_long") |
| 45 | +func print_long(_: Int) |
| 46 | + |
| 47 | +public func print(_ n: Int, terminator: StaticString = "\n") { |
| 48 | + print_long(n) |
| 49 | + print("", terminator: terminator) |
| 50 | +} |
| 51 | + |
| 52 | +func test() { |
| 53 | + print("Testing globals...") // CHECK: Testing globals... |
| 54 | + print(global_in_module_used_in_module) // CHECK-NEXT: 0 |
| 55 | + print(global_in_module_unused_in_module) // CHECK-NEXT: 0 |
| 56 | + foo() |
| 57 | + print(global_in_module_used_in_module) // CHECK-NEXT: 1 |
| 58 | + print(global_in_module_unused_in_module) // CHECK-NEXT: 0 |
| 59 | +} |
| 60 | + |
| 61 | +test() |
0 commit comments