Skip to content

Commit 4becd80

Browse files
committed
SIL: Pick default ARC convention for witness thunks based on the kind of the original decl.
Enum constructors take their arguments +1 by default, but they can now be used to satisfy protocol static member requirements, which take arguments +0 by default. Type lowering would accidentally use the kind of the witness to determine the conventions for the witness thunk, leading to a miscompile when the requirement is called through the protocol. Fixes rdar://74117738.
1 parent 2cfa57d commit 4becd80

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ static CanSILFunctionType getNativeSILFunctionType(
24862486
case SILFunctionType::Representation::Method:
24872487
case SILFunctionType::Representation::Closure:
24882488
case SILFunctionType::Representation::WitnessMethod: {
2489-
switch (constant ? constant->kind : SILDeclRef::Kind::Func) {
2489+
switch (origConstant ? origConstant->kind : SILDeclRef::Kind::Func) {
24902490
case SILDeclRef::Kind::Initializer:
24912491
case SILDeclRef::Kind::EnumElement:
24922492
return getSILFunctionTypeForConventions(DefaultInitializerConventions());

test/SILGen/enum_witness_thunks.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
class C {}
4+
5+
protocol P {
6+
static func c(_: C) -> Self
7+
}
8+
9+
enum E: P {
10+
case c(C)
11+
}
12+
13+
// CHECK-LABEL: sil {{.*}} @$s19enum_witness_thunks1EOAA1PA2aDP1cyxAA1CCFZTW : $@convention(witness_method: P) (@guaranteed C, @thick E.Type) -> @out E
14+
// CHECK: [[COPY:%.*]] = copy_value
15+
// CHECK: apply {{.*}}([[COPY]]

0 commit comments

Comments
 (0)