fix crash in loop dot dump when unrolling is enabled
Reported by Jakub Kubik
MODIFY
ir/function.cpp
ir/function.cpp
@@ -878,6 +878,7 @@ void CFG::printDot(ostream &os) const {
// traverse the cfg in reverse postorder to build dominators.
void DomTree::buildDominators(const CFG &cfg) {
// initialization
+ // +1 for the sink BB
unsigned i = f.getBBs().size() + 1;
for (auto &b : f.getBBs()) {
doms.emplace(b, *b).first->second.order = --i;
@@ -966,7 +967,8 @@ void DomTree::printDot(ostream &os) const {
void LoopAnalysis::getDepthFirstSpanningTree() {
- unsigned bb_count = f.getBBs().size();
+ // +1 to account for the sink BB
+ unsigned bb_count = f.getBBs().size() + 1;
node.resize(bb_count, nullptr);
last.resize(bb_count, -1u);
@@ -998,7 +1000,8 @@ void LoopAnalysis::getDepthFirstSpanningTree() {
// Havlak, P. (1997). Nesting of reducible and irreducible loops.
void LoopAnalysis::run() {
getDepthFirstSpanningTree();
- unsigned bb_count = f.getBBs().size();
+ // +1 to account for the sink BB
+ unsigned bb_count = f.getBBs().size() + 1;
auto isAncestor = [this](unsigned w, unsigned v) -> bool {
return w <= v && v <= last[w];

fix crash in loop dot dump when unrolling is enabled
Reported by Jakub Kubik