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

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 2 12:20:10 PDT 2019


RKSimon added a comment.

In D69751#1731246 <https://reviews.llvm.org/D69751#1731246>, @xbolva00 wrote:

> @RKSimon , since we have quite a lot  "null check after dereferencing" warnings in LLVM, is this "pattern" ok? I mean, new assert before dereferencing the pointer..


I'm not sure what patterns you have in mind? In this case it looks like we just need to cleanup the logic (and assert that we don't have orphan BBs), other cases its more about ensuring common code isn't prematurely pulled out (which you might be referring to with IsEntryBlock?).

The patch makes sense to me but @jyknight should confirm since he touched this code most recently.



================
Comment at: llvm/lib/IR/AsmWriter.cpp:3567
 void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
+  assert(BB->getParent() && "block without parent!");
   bool IsEntryBlock = BB == &BB->getParent()->getEntryBlock();
----------------
Maybe BB && BB->getParent() ?


================
Comment at: llvm/lib/IR/AsmWriter.cpp:3583
-    Out.PadToColumn(50);
-    Out << "; Error: Block without parent!";
-  } else if (!IsEntryBlock) {
----------------
http://lab.llvm.org:8080/coverage/coverage-reports/llvm/coverage indicates this never gets called so the assert looks alright to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69751/new/

https://reviews.llvm.org/D69751





More information about the llvm-commits mailing list