|
| 1 | +// RUN: %target-swift-frontend -emit-ir %s | FileCheck %s |
| 2 | + |
| 3 | +sil_stage canonical |
| 4 | + |
| 5 | +import Builtin |
| 6 | +import Swift |
| 7 | +import SwiftShims |
| 8 | + |
| 9 | +public class Parent { |
| 10 | + public func foo() {} |
| 11 | +} |
| 12 | + |
| 13 | +public class Child : Parent {} |
| 14 | + |
| 15 | +public class Grandchild : Child { |
| 16 | + override public func foo() { super.foo() } |
| 17 | +} |
| 18 | + |
| 19 | +// test.Parent.foo () -> () |
| 20 | +sil @_TFC4test6Parent3foofT_T_ : $@convention(method) (@guaranteed Parent) -> () { |
| 21 | +// %0 // user: %1 |
| 22 | +bb0(%0 : $Parent): |
| 23 | + debug_value %0 : $Parent // let self // id: %1 |
| 24 | + %2 = tuple () // user: %3 |
| 25 | + return %2 : $() // id: %3 |
| 26 | +} |
| 27 | + |
| 28 | +// test.Grandchild.foo () -> () |
| 29 | +sil @_TFC4test10Grandchild3foofT_T_ : $@convention(method) (@guaranteed Grandchild) -> () { |
| 30 | +// %0 // users: %1, %2, %3 |
| 31 | +bb0(%0 : $Grandchild): |
| 32 | + debug_value %0 : $Grandchild // let self // id: %1 |
| 33 | + strong_retain %0 : $Grandchild // id: %2 |
| 34 | + %3 = upcast %0 : $Grandchild to $Child // user: %4 |
| 35 | + %4 = upcast %3 : $Child to $Parent // users: %6, %7 |
| 36 | + // function_ref test.Parent.foo () -> () |
| 37 | + %5 = super_method %0 : $Grandchild, #Parent.foo!1 : (Parent) -> () -> (), $@convention(method) (@guaranteed Parent) -> () |
| 38 | + %6 = apply %5(%4) : $@convention(method) (@guaranteed Parent) -> () |
| 39 | + strong_release %4 : $Parent // id: %7 |
| 40 | + %8 = tuple () // user: %9 |
| 41 | + return %8 : $() // id: %9 |
| 42 | +} |
| 43 | + |
| 44 | +sil_vtable Parent { |
| 45 | + #Parent.foo!1: _TFC4test6Parent3foofT_T_ // test.Parent.foo () -> () |
| 46 | +} |
| 47 | + |
| 48 | +sil_vtable Child { |
| 49 | + #Parent.foo!1: _TFC4test6Parent3foofT_T_ // test.Parent.foo () -> () |
| 50 | +} |
| 51 | + |
| 52 | +sil_vtable Grandchild { |
| 53 | + #Parent.foo!1: _TFC4test10Grandchild3foofT_T_ // test.Grandchild.foo () -> () |
| 54 | +} |
| 55 | + |
| 56 | +// CHECK: define void @_TFC4test10Grandchild3foofT_T_(%C21super_instance_method10Grandchild*) |
| 57 | +// CHECK: [[OPAQUE_GRANDCHILD:%[0-9]+]] = bitcast %C21super_instance_method10Grandchild* %0 to %swift.type** |
| 58 | +// CHECK: [[GRANDCHILD_METADATA:%\..*]] = load %swift.type*, %swift.type** [[OPAQUE_GRANDCHILD]] |
| 59 | +// CHECK: [[OPAQUE_METADATA:%[0-9]+]] = bitcast %swift.type* [[GRANDCHILD_METADATA]] to %swift.type** |
| 60 | +// CHECK: [[SUPER_METADATA_PTR:%[0-9]+]] = getelementptr inbounds %swift.type*, %swift.type** [[OPAQUE_METADATA]], i32 1 |
| 61 | +// CHECK: [[SUPER_METADATA:%[0-9]+]] = load %swift.type*, %swift.type** [[SUPER_METADATA_PTR]] |
| 62 | +// CHECK: [[FOO_VTABLE_SLOT:%[0-9]+]] = getelementptr inbounds void (%C21super_instance_method6Parent*)*, void (%C21super_instance_method6Parent*)** |
| 63 | +// CHECK: [[FOO_FNPTR:%[0-9]+]] = load void (%C21super_instance_method6Parent*)*, void (%C21super_instance_method6Parent*)** [[FOO_VTABLE_SLOT]] |
| 64 | +// CHECK: call void |
0 commit comments