Merge pull request #13063 from gottesmm/pr-63b16f490049e1de640a8ee021599e3c5d014d1d
diff --git a/lib/SIL/SILFunctionType.cpp b/lib/SIL/SILFunctionType.cpp
index e371b0f..7da238d 100644
--- a/lib/SIL/SILFunctionType.cpp
+++ b/lib/SIL/SILFunctionType.cpp
@@ -1130,6 +1130,23 @@
}
};
+/// The convention used for allocating inits. Allocating inits take their normal
+/// parameters at +1 and do not have a self parameter.
+struct DefaultAllocatorConventions : DefaultConventions {
+ DefaultAllocatorConventions()
+ : DefaultConventions(NormalParameterConvention::Owned) {}
+
+ ParameterConvention
+ getDirectSelfParameter(const AbstractionPattern &type) const override {
+ llvm_unreachable("Allocating inits do not have self parameters");
+ }
+
+ ParameterConvention
+ getIndirectSelfParameter(const AbstractionPattern &type) const override {
+ llvm_unreachable("Allocating inits do not have self parameters");
+ }
+};
+
/// The default conventions for Swift setter acccessors.
///
/// These take self at +0, but all other parameters at +1. This is because we
@@ -1220,7 +1237,10 @@
return getSILFunctionType(M, origType, substInterfaceType, extInfo,
DefaultInitializerConventions(), ForeignInfo(),
constant, witnessMethodConformance);
-
+ case SILDeclRef::Kind::Allocator:
+ return getSILFunctionType(M, origType, substInterfaceType, extInfo,
+ DefaultAllocatorConventions(), ForeignInfo(),
+ constant, witnessMethodConformance);
case SILDeclRef::Kind::Func:
// If we have a setter, use the special setter convention. This ensures
// that we take normal parameters at +1.
@@ -1230,7 +1250,6 @@
constant, witnessMethodConformance);
}
LLVM_FALLTHROUGH;
- case SILDeclRef::Kind::Allocator:
case SILDeclRef::Kind::Destroyer:
case SILDeclRef::Kind::GlobalAccessor:
case SILDeclRef::Kind::GlobalGetter:
diff --git a/test/SILGen/guaranteed_normal_args.swift b/test/SILGen/guaranteed_normal_args.swift
index 1b619f5..3a433f2 100644
--- a/test/SILGen/guaranteed_normal_args.swift
+++ b/test/SILGen/guaranteed_normal_args.swift
@@ -35,8 +35,15 @@
class KlassWithBuffer {
var buffer: Buffer
- init() {
- buffer = Buffer(inK: Klass())
+
+ // Make sure that the allocating init forwards into the initializing init at +1.
+ // CHECK-LABEL: sil hidden @_T0s15KlassWithBufferCABs0A0C3inK_tcfC : $@convention(method) (@owned Klass, @thick KlassWithBuffer.Type) -> @owned KlassWithBuffer {
+ // CHECK: bb0([[ARG:%.*]] : @owned $Klass,
+ // CHECK: [[INITIALIZING_INIT:%.*]] = function_ref @_T0s15KlassWithBufferCABs0A0C3inK_tcfc : $@convention(method) (@owned Klass, @owned KlassWithBuffer) -> @owned KlassWithBuffer
+ // CHECK: apply [[INITIALIZING_INIT]]([[ARG]],
+ // CHECK: } // end sil function '_T0s15KlassWithBufferCABs0A0C3inK_tcfC'
+ init(inK: Klass = Klass()) {
+ buffer = Buffer(inK: inK)
}
// This test makes sure that we:
@@ -68,9 +75,10 @@
struct StructContainingBridgeObject {
var rawValue: Builtin.BridgeObject
- // CHECK-LABEL: sil hidden @_T0s28StructContainingBridgeObjectVAByXl8swiftObj_tcfC : $@convention(method) (@guaranteed AnyObject, @thin StructContainingBridgeObject.Type) -> @owned StructContainingBridgeObject {
- // CHECK: bb0([[ARG:%.*]] : @guaranteed $AnyObject,
- // CHECK: [[CASTED_ARG:%.*]] = unchecked_ref_cast [[ARG]] : $AnyObject to $Builtin.BridgeObject
+ // CHECK-LABEL: sil hidden @_T0s28StructContainingBridgeObjectVAByXl8swiftObj_tcfC : $@convention(method) (@owned AnyObject, @thin StructContainingBridgeObject.Type) -> @owned StructContainingBridgeObject {
+ // CHECK: bb0([[ARG:%.*]] : @owned $AnyObject,
+ // CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
+ // CHECK: [[CASTED_ARG:%.*]] = unchecked_ref_cast [[BORROWED_ARG]] : $AnyObject to $Builtin.BridgeObject
// CHECK: [[COPY_CASTED_ARG:%.*]] = copy_value [[CASTED_ARG]]
// CHECK: assign [[COPY_CASTED_ARG]] to
// CHECK: } // end sil function '_T0s28StructContainingBridgeObjectVAByXl8swiftObj_tcfC'