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()
                      << ","


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()
                      << ","
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to