[llvm] r311202 - IR: Make stripDebugInfo robust against (invalid) empty basic blocks

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 18 14:38:03 PDT 2017


Author: bogner
Date: Fri Aug 18 14:38:03 2017
New Revision: 311202

URL: http://llvm.org/viewvc/llvm-project?rev=311202&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/IR/DebugInfo.cpp

Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=311202&r1=311201&r2=311202&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Fri Aug 18 14:38:03 2017
@@ -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)




More information about the llvm-commits mailing list