Skip to content

Commit 97845c0

Browse files
committed
IRGen: Don't pass metadata of not ABI accessible to outlined copy/destroy operations
Doing so will cause linkage errors and is not neccessary since we call the witness of the enclosing type as soon as its fields are not ABI accessible. rdar://40868358
1 parent dd9313c commit 97845c0

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

lib/IRGen/Outlining.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ void OutliningMetadataCollector::collectTypeMetadataForLayout(SILType type) {
3636
}
3737

3838
auto formalType = type.getASTType();
39-
if (isa<FixedTypeInfo>(IGF.IGM.getTypeInfoForLowered(formalType))) {
39+
auto &ti = IGF.IGM.getTypeInfoForLowered(formalType);
40+
41+
// We don't need the metadata for fixed size types or types that are not ABI
42+
// accessible. Outlining will call the value witness of the enclosing type of
43+
// non ABI accessible field/element types.
44+
if (isa<FixedTypeInfo>(ti) || !ti.isABIAccessible()) {
4045
return;
4146
}
4247

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
private struct Private<T> {
2+
init(_ t: T) {
3+
p = t
4+
}
5+
var p : T
6+
}
7+
8+
public struct Public<T> {
9+
init(_ t: T) {
10+
p = Private<T>(t)
11+
}
12+
private var p: Private<T>
13+
}

test/IRGen/TestABIInaccessible.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -module-name main -I %t -emit-ir -primary-file %s %S/Inputs/ABIInaccessible.swift | %FileCheck %s
2+
3+
public struct AnotherType<T> {
4+
init(_ t: T) {
5+
p = Public<T>(t)
6+
}
7+
public var p : Public<T>
8+
}
9+
10+
// Don't pass the metadata of Private<T> to AnotherType<T>'s outlined destroy.
11+
// CHECK-LABEL: define swiftcc void @"$S4main4copyyAA11AnotherTypeVyxGAElF"(%T4main11AnotherTypeV* noalias nocapture sret, %T4main11AnotherTypeV* noalias nocapture, %swift.type* %T)
12+
// CHECK: [[MD:%.*]] = call swiftcc %swift.metadata_response @"$S4main11AnotherTypeVMa"(i{{.*}} 0, %swift.type* %T) #9
13+
// CHECK: [[MD1:%.*]] = extractvalue %swift.metadata_response %3, 0
14+
// CHECK: [[MD2:%.*]] = call swiftcc %swift.metadata_response @"$S4main6PublicVMa"(i{{.*}} 0, %swift.type* %T)
15+
// CHECK: [[MD3:%.*]] = extractvalue %swift.metadata_response %10, 0
16+
// CHECK: call %T4main11AnotherTypeV* @"$S4main11AnotherTypeVyxGlWOc"(%T4main11AnotherTypeV* %1, %T4main11AnotherTypeV* {{.*}}, %swift.type* %T, %swift.type* [[MD3]], %swift.type* [[MD1]])
17+
public func copy<T>(_ a: AnotherType<T>) -> AnotherType<T> {
18+
let copy = a
19+
return copy
20+
}

0 commit comments

Comments
 (0)