[PATCH] D69751: [AsmWritter] Fixed "null check after dereferencing" warning

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 2 10:11:50 PDT 2019


xbolva00 created this revision.
xbolva00 added a reviewer: jyknight.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
xbolva00 added a reviewer: RKSimon.

The 'BB->getParent()' pointer was utilized before it was verified against nullptr. Check lines: 3567, 3581.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69751

Files:
  llvm/lib/IR/AsmWriter.cpp


Index: llvm/lib/IR/AsmWriter.cpp
===================================================================
--- llvm/lib/IR/AsmWriter.cpp
+++ llvm/lib/IR/AsmWriter.cpp
@@ -3564,6 +3564,7 @@
 
 /// printBasicBlock - This member is called for each basic block in a method.
 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
+  assert(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 @@
       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 << ";";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69751.227582.patch
Type: text/x-patch
Size: 836 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191102/4f542396/attachment.bin>


More information about the llvm-commits mailing list