|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend %s %S/Inputs/print.swift -enable-experimental-feature Embedded -enable-builtin-module -c -o %t/main.o |
| 3 | +// RUN: %target-clang -x c -c %S/Inputs/tiny-runtime-dummy-refcounting.c -o %t/runtime.o |
| 4 | +// RUN: %target-clang %t/main.o %t/runtime.o -o %t/a.out -dead_strip |
| 5 | +// RUN: %target-run %t/a.out | %FileCheck %s |
| 6 | + |
| 7 | +// REQUIRES: executable_test |
| 8 | +// REQUIRES: optimized_stdlib |
| 9 | +// REQUIRES: VENDOR=apple |
| 10 | +// REQUIRES: OS=macosx |
| 11 | + |
| 12 | +import Builtin |
| 13 | + |
| 14 | +var NoisyLifeCount = 0 |
| 15 | +var NoisyDeathCount = 0 |
| 16 | + |
| 17 | +protocol P {} |
| 18 | + |
| 19 | +class Noisy : P { |
| 20 | + init() { NoisyLifeCount += 1 } |
| 21 | + deinit { NoisyDeathCount += 1 } |
| 22 | +} |
| 23 | + |
| 24 | +struct Large : P { |
| 25 | + var a, b, c, d: Noisy |
| 26 | + |
| 27 | + init() { |
| 28 | + self.a = Noisy() |
| 29 | + self.b = Noisy() |
| 30 | + self.c = Noisy() |
| 31 | + self.d = Noisy() |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func exerciseArrayValueWitnesses<T>(_ value: T) { |
| 36 | + let buf = UnsafeMutablePointer<T>.allocate(capacity: 5) |
| 37 | + |
| 38 | + (buf + 0).initialize(to: value) |
| 39 | + (buf + 1).initialize(to: value) |
| 40 | + |
| 41 | + Builtin.copyArray(T.self, (buf + 2)._rawValue, buf._rawValue, 2._builtinWordValue) |
| 42 | + Builtin.takeArrayBackToFront(T.self, (buf + 1)._rawValue, buf._rawValue, 4._builtinWordValue) |
| 43 | + Builtin.takeArrayFrontToBack(T.self, buf._rawValue, (buf + 1)._rawValue, 4._builtinWordValue) |
| 44 | + Builtin.destroyArray(T.self, buf._rawValue, 4._builtinWordValue) |
| 45 | + |
| 46 | + buf.deallocate() |
| 47 | +} |
| 48 | + |
| 49 | +func test() { |
| 50 | + NoisyLifeCount = 0 |
| 51 | + NoisyDeathCount = 0 |
| 52 | + do { |
| 53 | + exerciseArrayValueWitnesses(44) |
| 54 | + exerciseArrayValueWitnesses(Noisy()) |
| 55 | + exerciseArrayValueWitnesses(Large()) |
| 56 | + } |
| 57 | + precondition(NoisyLifeCount == NoisyDeathCount) |
| 58 | + print("Checks out") |
| 59 | + // CHECK: Checks out |
| 60 | +} |
| 61 | + |
| 62 | +@main struct Main { static func main() { test() } } |
0 commit comments