Skip to content

Commit 175dad1

Browse files
committed
Fix LoadableByAddress assert: missing case.
Pattern: %f = function_ref @invocationClosure : $@convention(thin) (BigStruct) -> () %s = struct $InvocationWrapper (%f : $@convention(thin) (BigStruct) -> ()) Error: Unhandled use of FunctionRefInst UNREACHABLE executed at /Users/atrick/s/sfix/swift/lib/IRGen/LoadableByAddress.cpp:3057! This fix simply adds the unrecognized case. Rewriting a function_ref does not change its value, so I'm not sure why the assert exists in the first place.
1 parent ff93822 commit 175dad1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,6 +3051,7 @@ void LoadableByAddress::run() {
30513051
builtinInstrs.insert(instr);
30523052
break;
30533053
}
3054+
case SILInstructionKind::StructInst:
30543055
case SILInstructionKind::DebugValueInst:
30553056
break;
30563057
default:

test/IRGen/big_types.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ sil @use_big_struct : $@convention(thin) (BigStruct) -> ()
2828

2929
sil @takeClosure : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> ()) -> ()
3030

31+
typealias Invocation = @convention(thin) (BigStruct) -> ()
32+
33+
struct InvocationWrapper {
34+
let invocation: Invocation
35+
}
36+
37+
sil_global hidden [let] @invocation : $InvocationWrapper
38+
39+
sil @invocationClosure : $@convention(thin) (BigStruct) -> ()
40+
3141
// CHECK-LABEL: sil_global @globalWithClosureInStruct : $ContainsClosure = {
3242
// CHECK: %0 = function_ref @make_big_struct : $@convention(thin) () -> @out BigStruct
3343
// CHECK-NEXT: %1 = thin_to_thick_function %0 : $@convention(thin) () -> @out BigStruct to $@callee_guaranteed () -> @out BigStruct
@@ -158,3 +168,18 @@ bb0(%0 : @closureCapture $BigStruct):
158168
%2 = tuple ()
159169
return %2 : $()
160170
}
171+
172+
// Test a rewritten function_ref stored in a struct property.
173+
// CHECK-LABEL: sil [global_init_once_fn] @test_invocation : $@convention(c) (Builtin.RawPointer) -> () {
174+
// CHECK: [[F:%[0-9]+]] = function_ref @invocationClosure : $@convention(thin) (@in_guaranteed BigStruct) -> ()
175+
// CHECK: = struct $InvocationWrapper ([[F]] : $@convention(thin) (@in_guaranteed BigStruct) -> ())
176+
sil [global_init_once_fn] @test_invocation : $@convention(c) (Builtin.RawPointer) -> () {
177+
bb0(%0 : $Builtin.RawPointer):
178+
alloc_global @invocation
179+
%g = global_addr @invocation : $*InvocationWrapper
180+
%f = function_ref @invocationClosure : $@convention(thin) (BigStruct) -> ()
181+
%s = struct $InvocationWrapper (%f : $@convention(thin) (BigStruct) -> ())
182+
store %s to %g : $*InvocationWrapper
183+
%r = tuple ()
184+
return %r : $()
185+
}

0 commit comments

Comments
 (0)