File: class_resilience_thunks.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 (59 lines) | stat: -rw-r--r-- 2,682 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
51
52
53
54
55
56
57
58
59
// RUN: %empty-directory(%t)

// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_class_thunks.swiftmodule -module-name=resilient_class_thunks %S/../Inputs/resilient_class_thunks.swift
// RUN: %target-swift-frontend -I %t -emit-ir %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -I %t -emit-ir -O %s

import resilient_class_thunks

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s23class_resilience_thunks21testDispatchThunkBase1b1ty010resilient_a1_C00G0CyxG_xtlF"(ptr %0, ptr noalias %1)
public func testDispatchThunkBase<T>(b: Base<T>, t: T) {

  // CHECK: call swiftcc void @"$s22resilient_class_thunks4BaseC6takesTyyxFTj"(ptr noalias {{%.*}}, ptr swiftself %0)
  b.takesT(t)

  // CHECK: call swiftcc void @"$s22resilient_class_thunks4BaseC8takesIntyySiFTj"([[INT]] 0, ptr swiftself %0)
  b.takesInt(0)

  // CHECK: call swiftcc void @"$s22resilient_class_thunks4BaseC14takesReferenceyyAA6ObjectCFTj"(ptr {{%.*}}, ptr swiftself %0)
  b.takesReference(Object())

  // CHECK: ret void
}

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s23class_resilience_thunks24testDispatchThunkDerived1dy010resilient_a1_C00G0C_tF"(ptr %0)
public func testDispatchThunkDerived(d: Derived) {

  // CHECK: call swiftcc void @"$s22resilient_class_thunks4BaseC6takesTyyxFTj"(ptr noalias {{%.*}}, ptr swiftself {{%.*}})
  d.takesT(0)

  // CHECK: call swiftcc void @"$s22resilient_class_thunks7DerivedC8takesIntyySiSgFTj"([[INT]] 0, i8 1, ptr swiftself %0)
  d.takesInt(nil)

  // CHECK: call swiftcc void @"$s22resilient_class_thunks4BaseC14takesReferenceyyAA6ObjectCFTj"(ptr null, ptr swiftself {{%.*}})
  d.takesReference(nil)

  // CHECK: ret void
}

// We had a bug where if a non-resilient class overrides a method from a
// resilient class, calling the override would directly access the vtable
// entry of the resilient class, instead of going through the dispatch
// thunk.

open class MyDerived : Base<Int> {
  // Override has different formal type but is ABI-compatible
  open override func takesReference(_: Object) {}
}

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$s23class_resilience_thunks27testDispatchThunkMyOverride1d1oyAA0G7DerivedC_010resilient_a1_C06ObjectCtF"(ptr %0, ptr %1)
public func testDispatchThunkMyOverride(d: MyDerived, o: Object) {
  // CHECK: call swiftcc void @"$s22resilient_class_thunks4BaseC14takesReferenceyyAA6ObjectCFTj"
  d.takesReference(o)

  // CHECK: ret void
}

public func testDispatchThunkCast(d: Derived) {
  _ = d.returnsSuperclass()
}