diff --git a/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll b/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll --- a/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll +++ b/llvm/test/Reduce/remove-bbs-ret-nonvoid.ll @@ -13,10 +13,7 @@ ; CHECK-NEXT: br label %interesting2 ; CHECK-LABEL: interesting2: -; CHECK-NEXT: br label %uninteresting1 - -; CHECK-LABEL: uninteresting1: -; CHECK-NEXT: ret i32 10 +; CHECK-NEXT: ret i32 undef interesting: br label %interesting2 diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp @@ -45,7 +45,10 @@ Term->eraseFromParent(); if (ChunkSucessors.empty()) { - ReturnInst::Create(BB.getContext(), nullptr, &BB); + auto *FnRetTy = BB.getParent()->getReturnType(); + ReturnInst::Create(BB.getContext(), + FnRetTy->isVoidTy() ? nullptr : UndefValue::get(FnRetTy), + &BB); return; } @@ -66,7 +69,10 @@ static void removeUninterestingBBsFromSwitch(SwitchInst &SwInst, std::set BBsToKeep) { if (!BBsToKeep.count(SwInst.getDefaultDest())) { - ReturnInst::Create(SwInst.getContext(), nullptr, SwInst.getParent()); + auto *FnRetTy = SwInst.getParent()->getParent()->getReturnType(); + ReturnInst::Create(SwInst.getContext(), + FnRetTy->isVoidTy() ? nullptr : UndefValue::get(FnRetTy), + SwInst.getParent()); SwInst.eraseFromParent(); } else for (int I = 0, E = SwInst.getNumCases(); I != E; ++I) {