From c6a0c7328721caa7ad253dd7a93d21df1ad466e2 Mon Sep 17 00:00:00 2001 From: Vladislav Abrosimov Date: Wed, 4 Jun 2025 09:18:24 +0300 Subject: [PATCH] fix UB in dom tree builder --- src/CFGraph/CFGraph.h | 8 +------- src/CFGraph/IR_domTree.cpp | 4 +++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/CFGraph/CFGraph.h b/src/CFGraph/CFGraph.h index f0308fd..8dfeb6a 100644 --- a/src/CFGraph/CFGraph.h +++ b/src/CFGraph/CFGraph.h @@ -73,13 +73,7 @@ namespace SAPFOR const std::vector& getNext() const { return next; } const std::vector& getPrev() const { return prev; } BasicBlock* getDom() const - { - if (!directDominator) - { - __spf_print(1, "%s\n", "the dominator tree was built with an error or was not built at all"); - printInternalError(convertFileName(__FILE__).c_str(), __LINE__); - } - + { return directDominator; } diff --git a/src/CFGraph/IR_domTree.cpp b/src/CFGraph/IR_domTree.cpp index cfab670..067cc7c 100644 --- a/src/CFGraph/IR_domTree.cpp +++ b/src/CFGraph/IR_domTree.cpp @@ -64,6 +64,8 @@ namespace SAPFOR { int w = vertex[i]; for (BasicBlock* v : vertices[w]->getPrev()) { + if (dfs_num[v] == -1) + continue; int u = Eval(dfs_num[v]); if (semi[u] < semi[w]) @@ -97,4 +99,4 @@ namespace SAPFOR { void buildDominatorTree(std::vector& blocks) { DominatorFinder finder(blocks); } -} \ No newline at end of file +}