Skip to content

Commit b6db2f0

Browse files
aschwaighofernkcsgexi
authored andcommitted
CapturePropagation: Can't forward to a function if it is not swift co… (#14640)
* CapturePropagation: Can't forward to a function if it is not swift convention compatible This causes breakage in check-swift-optimize_size on a release stdlib bot. Test case to follow. * Test case for capture propagation involving a c function
1 parent 7772415 commit b6db2f0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/SILOptimizer/IPO/CapturePropagation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ static SILFunction *getSpecializedWithDeadParams(
397397
return nullptr;
398398
}
399399

400+
auto Rep = Specialized->getLoweredFunctionType()->getRepresentation();
401+
if (getSILFunctionLanguage(Rep) != SILFunctionLanguage::Swift)
402+
return nullptr;
403+
400404
GenericSpecialized = std::make_pair(nullptr, nullptr);
401405

402406
if (PAI->hasSubstitutions()) {

test/SILOptimizer/capture_propagation.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,23 @@ bb0:
450450
%2 = partial_apply %1<Int32>(%0) : $@convention(method) <T>(@in T, @in T, @thin T.Type) -> Bool
451451
return %2 : $@callee_owned (@in Int32, @in Int32) -> Bool
452452
}
453+
454+
sil @cfunc : $@convention(c) (Int32, Int32) -> Bool
455+
456+
sil @call_cfunc : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool {
457+
bb0(%0 : $Int32, %1 : $Int32, %2 : $@thin Int32.Type):
458+
%3 = function_ref @cfunc : $@convention(c) (Int32, Int32) -> Bool
459+
%4 = apply %3(%0, %1) : $@convention(c) (Int32, Int32) -> Bool
460+
return %4 : $Bool
461+
}
462+
// CHECK-LABEL: sil @test_cfunc
463+
// CHECK: function_ref
464+
// CHECK: partial_apply
465+
// CHECK: return
466+
sil @test_cfunc : $@convention(thin) () -> @owned @callee_owned (Int32, Int32) -> Bool {
467+
bb0:
468+
%0 = metatype $@thin Int32.Type
469+
%1 = function_ref @call_cfunc : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool
470+
%2 = partial_apply %1(%0) : $@convention(method) (Int32, Int32, @thin Int32.Type) -> Bool
471+
return %2 : $@callee_owned (Int32, Int32) -> Bool
472+
}

0 commit comments

Comments
 (0)