[AsmWritter] Fixed "null check after dereferencing" warning
authorDávid Bolvanský <david.bolvansky@gmail.com>
Wed, 6 Nov 2019 18:20:48 +0000 (19:20 +0100)
committerDávid Bolvanský <david.bolvansky@gmail.com>
Thu, 7 Nov 2019 18:30:29 +0000 (19:30 +0100)
Summary: The 'BB->getParent()' pointer was utilized before it was verified against nullptr. Check lines: 3567, 3581.

Reviewers: jyknight, RKSimon

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D69751

llvm/lib/IR/AsmWriter.cpp

index f811c842cf569f31de5ff1b7a9ce4166c7ca388a..9ae15f49da807364d071ffb68dbb56258f9b771a 100644 (file)
@@ -3564,6 +3564,7 @@ void AssemblyWriter::printArgument(const Argument *Arg, AttributeSet Attrs) {
 
 /// printBasicBlock - This member is called for each basic block in a method.
 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
+  assert(BB && BB->getParent() && "block without parent!");
   bool IsEntryBlock = BB == &BB->getParent()->getEntryBlock();
   if (BB->hasName()) {              // Print out the label if it exists...
     Out << "\n";
@@ -3578,10 +3579,7 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
       Out << "<badref>:";
   }
 
-  if (!BB->getParent()) {
-    Out.PadToColumn(50);
-    Out << "; Error: Block without parent!";
-  } else if (!IsEntryBlock) {
+  if (!IsEntryBlock) {
     // Output predecessors for the block.
     Out.PadToColumn(50);
     Out << ";";