Files
swift-mirror/test/Interop/Cxx/foreign-reference/inheritance-irgen.swift
Egor Zhdan ba8ba57c77 [cxx-interop] Layout reference types that use tail padding of their bases correctly
This is a follow-up to d3e43bbe which resolved the issue for value types, but not for foreign reference types.

This change teaches IRGen that a base type of a C++ type might occupy less memory than its `sizeof`, specifically, it might only use `dsize` amount of memory.

rdar://147527755
2025-03-27 16:03:51 +00:00

43 lines
1.4 KiB
Swift

// RUN: %target-swift-emit-ir -Onone %s -I %S/Inputs -cxx-interoperability-mode=default -validate-tbd-against-ir=none -disable-llvm-verify -Xcc -fignore-exceptions -disable-availability-checking | %FileCheck %s
// This ensured we do not crash during IRGen for inherited C++ foreign reference types.
import Inheritance
@inline(never)
public func blackHole<T>(_ _: T) {}
let x = DerivedOutOfOrder.getInstance()
blackHole(x.baseField)
blackHole(x.derivedField)
blackHole(x.leafField)
let y = DerivedUsesBaseTailPadding.getInstance()
blackHole(y.field2)
blackHole(y.field4)
// CHECK: call ptr @{{.*}}returnValueType{{.*}}
// CHECK-NOT: call void @{{.*}}RCRetain@{{.*}}ValueType(ptr @{{.*}})
var x1 = BasicInheritanceExample.returnValueType()
// CHECK: call ptr @{{.*}}returnRefType{{.*}}
// CHECK: call void @{{.*}}RCRetain{{.*}}RefType{{.*}}(ptr {{.*}})
var x2 = BasicInheritanceExample.returnRefType()
// CHECK: call ptr @{{.*}}returnDerivedFromRefType{{.*}}
// CHECK: call void @{{.*}}RCRetain{{.*}}RefType{{.*}}(ptr {{.*}})
var x3 = BasicInheritanceExample.returnDerivedFromRefType()
func foo(
x1: BasicInheritanceExample.ValueType, x2: BasicInheritanceExample.RefType,
x3: BasicInheritanceExample.DerivedFromRefType
) {
}
foo(x1: x1.pointee, x2: x2, x3: x3)
// CHECK: call void @{{.*}}RCRelease{{.*}}RefType{{.*}}(ptr {{.*}})
// CHECK: call void @{{.*}}RCRelease{{.*}}RefType{{.*}}(ptr {{.*}})