Skip to content

Commit cacb399

Browse files
jckartertkremenek
authored andcommitted
Relax verifier check for InitBlockStorageHeader instructions. (#2873)
Correctly handle secondary substitutions using the existing verification logic for apply instructions. Fixes rdar://problem/26623854.
1 parent 50b8348 commit cacb399

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,18 +2809,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
28092809
invokeTy->getExtInfo().isPseudogeneric(),
28102810
"invoke function must not take reified generic parameters");
28112811

2812-
if (auto sig = invokeTy->getGenericSignature()) {
2813-
require(sig->getGenericParams().size() ==
2814-
IBSHI->getSubstitutions().size(),
2815-
"instruction must provide substitutions matching invoke "
2816-
"function");
2817-
invokeTy = invokeTy->substGenericArgs(F.getModule(), M,
2818-
IBSHI->getSubstitutions());
2819-
} else {
2820-
require(IBSHI->getSubstitutions().empty(),
2821-
"instruction must not provide substitutions for non-polymorphic "
2822-
"invoke fn");
2823-
}
2812+
invokeTy = checkApplySubstitutions(IBSHI->getSubstitutions(),
2813+
SILType::getPrimitiveObjectType(invokeTy));
28242814

28252815
auto storageParam = invokeTy->getParameters()[0];
28262816
require(storageParam.getConvention() ==

test/SILGen/objc_imported_generic.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public func genericPropertyOnAnyObject(o: AnyObject, b: Bool) -> AnyObject?? {
4141
// CHECK: dynamic_method_br %4 : $@opened([[TAG:.*]]) AnyObject, #GenericClass.propertyThing!getter.1.foreign, bb1
4242
// CHECK: bb1({{%.*}} : $@convention(objc_method) @pseudogeneric (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>):
4343

44-
protocol ThingHolder {
44+
public protocol ThingHolder {
4545
associatedtype Thing
4646

4747
init!(thing: Thing!)
@@ -56,16 +56,20 @@ protocol ThingHolder {
5656

5757
extension GenericClass: ThingHolder {}
5858

59-
public func genericBlockBridging<T: AnyObject>(x: GenericClass<T>) {
59+
public protocol Ansible: class {
60+
associatedtype Anser: ThingHolder
61+
}
62+
63+
public func genericBlockBridging<T: Ansible>(x: GenericClass<T>) {
6064
let block = x.blockForPerformingOnThings()
6165
x.performBlock(onThings: block)
6266
}
6367

6468
// CHECK-LABEL: sil @_TF21objc_imported_generic20genericBlockBridging
65-
// CHECK: [[BLOCK_TO_FUNC:%.*]] = function_ref @_TTRGRxs9AnyObjectrXFdCb_dx_ax_XFo_ox_ox_
66-
// CHECK: partial_apply [[BLOCK_TO_FUNC]]<T>
67-
// CHECK: [[FUNC_TO_BLOCK:%.*]] = function_ref @_TTRGRxs9AnyObjectrXFo_ox_ox_XFdCb_dx_ax_
68-
// CHECK: init_block_storage_header {{.*}} invoke [[FUNC_TO_BLOCK]]<T>
69+
// CHECK: [[BLOCK_TO_FUNC:%.*]] = function_ref @_TTRGRxs9AnyObjectx21objc_imported_generic7AnsiblerXFdCb_dx_ax_XFo_ox_ox_
70+
// CHECK: partial_apply [[BLOCK_TO_FUNC]]<T, {{.*}}>
71+
// CHECK: [[FUNC_TO_BLOCK:%.*]] = function_ref @_TTRGRxs9AnyObjectx21objc_imported_generic7AnsiblerXFo_ox_ox_XFdCb_dx_ax_
72+
// CHECK: init_block_storage_header {{.*}} invoke [[FUNC_TO_BLOCK]]<T,{{.*}}>
6973

7074
// CHECK-LABEL: sil @_TF21objc_imported_generic20arraysOfGenericParam
7175
public func arraysOfGenericParam<T: AnyObject>(y: Array<T>) {

0 commit comments

Comments
 (0)