[PATCH] D88900: check before accessing possibly null node
    Ding Fei via Phabricator via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Tue Oct  6 07:33:27 PDT 2020
    
    
  
danix800 created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
danix800 requested review of this revision.
Testcase: (main.cpp)
  int foo(int i);
  
  int main() {
    int i = 1;
    while (i-- >= 0) {
      return 3 / foo(i);
    }
  }
run with
  clang -cc1 -analyze -analyzer-checker=debug.DumpDominators main.cpp
triggers nullptr dereference.
Repository:
  rG LLVM Github Monorepo
https://reviews.llvm.org/D88900
Files:
  clang/include/clang/Analysis/Analyses/Dominators.h
Index: clang/include/clang/Analysis/Analyses/Dominators.h
===================================================================
--- clang/include/clang/Analysis/Analyses/Dominators.h
+++ clang/include/clang/Analysis/Analyses/Dominators.h
@@ -101,7 +101,12 @@
              "LLVM's Dominator tree builder uses nullpointers to signify the "
              "virtual root!");
 
-      DomTreeNode *IDom = DT.getNode(*I)->getIDom();
+      auto *Node = DT.getNode(*I);
+      if (Node == nullptr) {
+        continue;
+      }
+
+      DomTreeNode *IDom = Node->getIDom();
       if (IDom && IDom->getBlock())
         llvm::errs() << "(" << (*I)->getBlockID()
                      << ","
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88900.296454.patch
Type: text/x-patch
Size: 682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201006/46013fb1/attachment-0001.bin>
    
    
More information about the cfe-commits
mailing list