File: old_runtime_crash_without_fixed_layout.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (50 lines) | stat: -rw-r--r-- 1,592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// RUN: %empty-directory(%t)

// RUN: %target-build-swift-dylib(%t/%target-library-name(resilient_struct)) -enable-library-evolution %S/../../test/Inputs/resilient_struct.swift -emit-module -emit-module-path %t/resilient_struct.swiftmodule -module-name resilient_struct
// RUN: %target-codesign %t/%target-library-name(resilient_struct)

// RUN: %target-build-swift %s -L %t -I %t -lresilient_struct -o %t/main %target-rpath(%t) -target %target-stable-abi-triple
// RUN: %target-codesign %t/main

// RUN: %target-run %t/main %t/%target-library-name(resilient_struct)


// REQUIRES: executable_test
// REQUIRES: objc_interop
// REQUIRES: OS=macosx
// REQUIRES: CPU=x86_64

// Test that on an old Objective-C runtime we crash if attempting to use a
// class that requires the update callback and does not have a fragile layout.

import StdlibUnittest
import resilient_struct

var ClassTestSuite = TestSuite("Update callback")

public class ClassWithResilientField {
  var x = ResilientInt(i: 0)
}

@_optimize(none) func blackHole<T>(_: T) {}

@_optimize(none) func forceMetadata() {
  blackHole(ClassWithResilientField())
}

if #available(macOS 10.14.4, iOS 12.2, tvOS 12.2, watchOS 5.2, *) {
  ClassTestSuite.test("RealizeResilientClass") {  
    print("Nothing to test. We have the new Objective-C runtime.")
    forceMetadata()
  }
} else {
  ClassTestSuite.test("RealizeResilientClass")
    .crashOutputMatches("class ClassWithResilientField does not have a fragile layout")
    .code {
      expectCrashLater()
      print("About to crash...")
      forceMetadata()
    }
}

runAllTests()