Skip to content

Commit ed43bef

Browse files
authored
Merge pull request #12506 from atrick/sil-noescape
2 parents 8a8fdd8 + 2874e18 commit ed43bef

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,6 +2542,10 @@ void LoadableByAddress::run() {
25422542
SILFunction *RefF = FRI->getReferencedFunction();
25432543
if (modFuncs.count(RefF) != 0) {
25442544
// Go over the uses and add them to lists to modify
2545+
//
2546+
// FIXME: Why aren't function_ref uses processed transitively? And
2547+
// why is it necessary to visit uses at all if they will be visited
2548+
// later in this loop?
25452549
for (auto *user : FRI->getUses()) {
25462550
SILInstruction *currInstr = user->getUser();
25472551
switch (currInstr->getKind()) {
@@ -2584,6 +2588,14 @@ void LoadableByAddress::run() {
25842588
if (modifiableFunction(CanSILFunctionType(fType))) {
25852589
conversionInstrs.insert(CFI);
25862590
}
2591+
} else if (auto *TTI = dyn_cast<ThinToThickFunctionInst>(&I)) {
2592+
2593+
CanType canType = TTI->getCallee()->getType().getSwiftRValueType();
2594+
auto *fType = canType->castTo<SILFunctionType>();
2595+
2596+
if (modifiableFunction(CanSILFunctionType(fType)))
2597+
conversionInstrs.insert(TTI);
2598+
25872599
} else if (auto *LI = dyn_cast<LoadInst>(&I)) {
25882600
SILType currType = LI->getType();
25892601
if (auto *fType = getInnerFunctionType(currType)) {

test/IRGen/big_types_corner_cases.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,26 @@ bb0:
259259
return %99 : $()
260260
}
261261

262+
sil @convertToThickHelper : $@convention(thin) (@owned BigStruct) -> ()
263+
264+
// CHECK-LABAL: define {{.*}} swiftcc void @convertToThick(%T22big_types_corner_cases9BigStructV* noalias nocapture dereferenceable({{.*}})) #0 {
265+
// CHECK: entry:
266+
// CHECK: [[ALLOC:%.*]] = alloca %T22big_types_corner_cases9BigStructV, align 4
267+
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
268+
// CHECK: call swiftcc void bitcast (void (%T22big_types_corner_cases9BigStructV*)* @convertToThickHelper to void (%T22big_types_corner_cases9BigStructV*, %swift.refcounted*)*)(%T22big_types_corner_cases9BigStructV* noalias nocapture dereferenceable({{.*}}) [[ALLOC]], %swift.refcounted* swiftself null)
269+
// CHECK: ret void
270+
// CHECK-LABEL: }
271+
sil @convertToThick : $@convention(thin) (@in BigStruct) -> () {
272+
bb0(%0 : $*BigStruct):
273+
%3 = function_ref @convertToThickHelper : $@convention(thin) (@owned BigStruct) -> ()
274+
%4 = convert_function %3 : $@convention(thin) (@owned BigStruct) -> () to $@convention(thin) @noescape (@owned BigStruct) -> ()
275+
%5 = thin_to_thick_function %4 : $@convention(thin) @noescape (@owned BigStruct) -> () to $@noescape @callee_owned (@owned BigStruct) -> ()
276+
%8 = load %0 : $*BigStruct
277+
%10 = apply %5(%8) : $@noescape @callee_owned (@owned BigStruct) -> ()
278+
%12 = tuple ()
279+
return %12 : $()
280+
}
281+
262282
sil_vtable SuperBase {
263283
}
264284

0 commit comments

Comments
 (0)