From 5feb287d19c070d9a496a9e17fca95887e4a9cb9 Mon Sep 17 00:00:00 2001 From: Arnold Schwaighofer Date: Wed, 19 Mar 2025 09:26:20 -0700 Subject: [PATCH] LoadableByAddress: Add missing BranchInst in a switch rdar://146980802 --- lib/IRGen/LoadableByAddress.cpp | 5 +++++ test/IRGen/loadable_by_address.sil | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/IRGen/LoadableByAddress.cpp b/lib/IRGen/LoadableByAddress.cpp index 9c08dbbee6b..750c5985b80 100644 --- a/lib/IRGen/LoadableByAddress.cpp +++ b/lib/IRGen/LoadableByAddress.cpp @@ -3100,10 +3100,15 @@ void LoadableByAddress::run() { builtinInstrs.insert(instr); break; } + case SILInstructionKind::BranchInst: case SILInstructionKind::StructInst: case SILInstructionKind::DebugValueInst: break; default: +#ifndef NDEBUG + currInstr->dump(); + currInstr->getFunction()->dump(); +#endif llvm_unreachable("Unhandled use of FunctionRefInst"); } } diff --git a/test/IRGen/loadable_by_address.sil b/test/IRGen/loadable_by_address.sil index fa29655e459..1ff85f37ab3 100644 --- a/test/IRGen/loadable_by_address.sil +++ b/test/IRGen/loadable_by_address.sil @@ -53,3 +53,27 @@ entry(%x : $X): %retval = tuple () return %retval : $() } + +sil @branch_inst_f : $@convention(thin) (@owned X, UInt8) -> () +sil @branch_inst_f2 : $@convention(thin) (@owned X, UInt8) -> () + +sil @trigger : $@convention(thin) (@owned X) -> () + +// This used to crash. +sil @branch_inst_test : $@convention(thin) (Builtin.Int1, @owned X) -> (@convention(thin) (@owned X, UInt8) -> ()) { +entry(%1 : $Builtin.Int1, %t: $X): + %f = function_ref @trigger : $@convention(thin) (@owned X) -> () + %x = apply %f(%t) : $@convention(thin) (@owned X) -> () + cond_br %1, bb1, bb2 + +bb1: + %2 = function_ref @branch_inst_f : $@convention(thin) (@owned X, UInt8) -> () + br bb3(%2) + +bb2: + %3 = function_ref @branch_inst_f2 : $@convention(thin) (@owned X, UInt8) -> () + br bb3(%3) + +bb3(%r : $@convention(thin) (@owned X, UInt8) -> ()): + return %r : $@convention(thin) (@owned X, UInt8) -> () +}