IR: Make stripDebugInfo robust against (invalid) empty basic blocks

Since stripDebugInfo runs before the verifier when reading IR, we can
end up in a situation where we read some invalid IR but don't know its
invalid yet. Before this patch we would crash in stripDebugInfo when
given IR with a completely empty basic block, and after we get a nice
error from the verifier instead.

llvm-svn: 311202
This commit is contained in:
Justin Bogner 2017-08-18 21:38:03 +00:00
parent a2faf7b60f
commit b29bebe47b
1 changed files with 3 additions and 0 deletions

View File

@ -311,6 +311,9 @@ bool llvm::stripDebugInfo(Function &F) {
}
auto *TermInst = BB.getTerminator();
if (!TermInst)
// This is invalid IR, but we may not have run the verifier yet
continue;
if (auto *LoopID = TermInst->getMetadata(LLVMContext::MD_loop)) {
auto *NewLoopID = LoopIDsMap.lookup(LoopID);
if (!NewLoopID)