From 7d12a573ba47f73d8f699657d3cc2613d715e1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Bolvansk=C3=BD?= Date: Wed, 6 Nov 2019 19:20:48 +0100 Subject: [PATCH] [AsmWritter] Fixed "null check after dereferencing" warning 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 --- lib/IR/AsmWriter.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index f811c842cf5..9ae15f49da8 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -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 << ":"; } - 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 << ";";