Don't crash if we are printing an orphaned basic block!
authorChris Lattner <sabre@nondot.org>
Thu, 20 Nov 2003 00:09:43 +0000 (00:09 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 20 Nov 2003 00:09:43 +0000 (00:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10100 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AsmWriter.cpp

index 2c36ed98cb79dec81c2b5b050e42b5533087694e..1823412755b87a484696f9472000f9802df7546d 100644 (file)
@@ -750,20 +750,24 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
     else 
       Out << "<badref>"; 
   }
-  
-  if (BB != &BB->getParent()->front()) {  // Not the entry block?
-    // Output predecessors for the block...
-    Out << "\t\t;";
-    pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
-    
-    if (PI == PE) {
-      Out << " No predecessors!";
-    } else {
-      Out << " preds =";
-      writeOperand(*PI, false, true);
-      for (++PI; PI != PE; ++PI) {
-        Out << ",";
+
+  if (BB->getParent() == 0)
+    Out << "\t\t; Error: Block without parent!";
+  else {
+    if (BB != &BB->getParent()->front()) {  // Not the entry block?
+      // Output predecessors for the block...
+      Out << "\t\t;";
+      pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
+      
+      if (PI == PE) {
+        Out << " No predecessors!";
+      } else {
+        Out << " preds =";
         writeOperand(*PI, false, true);
+        for (++PI; PI != PE; ++PI) {
+          Out << ",";
+          writeOperand(*PI, false, true);
+        }
       }
     }
   }