[llvm] [CodeExtractor] Terminate callsite blocks to new `noreturn` functions with `unreachable` (PR #84682)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 00:47:05 PDT 2024
================
@@ -1390,12 +1402,16 @@ CallInst *CodeExtractor::emitCallAndSwitchStatement(Function *newFunction,
Type *OldFnRetTy = TheSwitch->getParent()->getParent()->getReturnType();
switch (NumExitBlocks) {
case 0:
+ // If fn is no return, end with an unreachable terminator.
+ if (newFunction->doesNotReturn()) {
+ (void)new UnreachableInst(Context, TheSwitch->getIterator());
+ }
// There are no successors (the block containing the switch itself), which
// means that previously this was the last part of the function, and hence
// this should be rewritten as a `ret'
// Check if the function should return a value
- if (OldFnRetTy->isVoidTy()) {
+ else if (OldFnRetTy->isVoidTy()) {
----------------
arsenm wrote:
I think this formatting is extremely misleading. The else needs to be on the same line as the closing brace. Can you move the comment before the whole chain?
https://github.com/llvm/llvm-project/pull/84682
More information about the llvm-commits
mailing list