[PATCH] D62507: [Dominators] PR42041: Skip nullpointer successors
Kristóf Umann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 27 17:34:16 PDT 2019
Szelethus created this revision.
Szelethus added reviewers: NoQ, MaskRay, xazax.hun, NutshellySima, asbirlea, kuhar.
Szelethus added projects: clang, LLVM.
Herald added subscribers: llvm-commits, gamesh411, kristina, dkrupp, rnkovacs.
https://bugs.llvm.org/show_bug.cgi?id=42041
In Clang's CFG, we use nullpointers to represent unreachable nodes, for
example, in the included testfile, block `B0` is unreachable from block
`B1`, resulting in a nullpointer dereference somewhere in
`llvm::DominatorTreeBase<clang::CFGBlock, false>::recalculate`.
This patch fixes this issue simply by skipping such successors.
Repository:
rL LLVM
https://reviews.llvm.org/D62507
Files:
clang/test/Analysis/domtest.cpp
llvm/include/llvm/Support/GenericDomTreeConstruction.h
Index: llvm/include/llvm/Support/GenericDomTreeConstruction.h
===================================================================
--- llvm/include/llvm/Support/GenericDomTreeConstruction.h
+++ llvm/include/llvm/Support/GenericDomTreeConstruction.h
@@ -235,6 +235,13 @@
constexpr bool Direction = IsReverse != IsPostDom; // XOR.
for (const NodePtr Succ :
ChildrenGetter<Direction>::Get(BB, BatchUpdates)) {
+
+ // The clang's CFG contains nullpointers for unreachable successors (eg.
+ // an if statement's condition is always false, the 'then' branch is
+ // unreachable), skip them.
+ if (!Succ)
+ continue;
+
const auto SIT = NodeToInfo.find(Succ);
// Don't visit nodes more than once but remember to collect
// ReverseChildren.
Index: clang/test/Analysis/domtest.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/domtest.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN: -analyzer-checker=debug.DumpCFG \
+// RUN: -analyzer-checker=debug.DumpDominators \
+// RUN: 2>&1 | FileCheck %s
+
+namespace pr42041_unreachable_cfg_successor {
+enum Kind {
+ A
+};
+
+void f() {
+ switch(Kind{}) {
+ case A:
+ break;
+ }
+}
+} // end of namespace pr42041_unreachable_cfg_successor
+
+// CHECK: void f()
+// CHECK-NEXT: [B3 (ENTRY)]
+// CHECK-NEXT: Succs (1): B1
+//
+// CHECK: [B1]
+// CHECK-NEXT: 1: {}
+// CHECK-NEXT: 2: pr42041_unreachable_cfg_successor::Kind[B1.1]
+// CHECK-SAME: (CXXFunctionalCastExpr, NoOp,
+// CHECK-SAME: enum pr42041_unreachable_cfg_successor::Kind)
+// CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, IntegralCast, int)
+// CHECK-NEXT: T: switch [B1.3]
+// CHECK-NEXT: Preds (1): B3
+// CHECK-NEXT: Succs (2): B2 B0(Unreachable)
+//
+// CHECK: [B2]
+// CHECK-NEXT: case A:
+// CHECK-NEXT: T: break;
+// CHECK-NEXT: Preds (1): B1
+// CHECK-NEXT: Succs (1): B0
+//
+// CHECK: [B0 (EXIT)]
+// CHECK-NEXT: Preds (2): B2 B1(Unreachable)
+//
+// CHECK: Immediate dominance tree (Node#,IDom#):
+// CHECK-NEXT: (0,2)
+// CHECK-NEXT: (1,3)
+// CHECK-NEXT: (2,1)
+// CHECK-NEXT: (3,3)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62507.201600.patch
Type: text/x-patch
Size: 2269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190528/d1969a2e/attachment.bin>
More information about the llvm-commits
mailing list