Commit 47be9879 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix cfg bug if for loops never exit normally

ex:

for i in xrange(5):
    pass
else:
    return 2
"unreachable here!"

We didn't prune the "unreachable here" line, which caused
some issues.  I guess we could also support compiling
trivially-unreachable blocks.
parent fa193e19
......@@ -1909,8 +1909,13 @@ public:
curblock->connectTo(end_block);
}
cfg->placeBlock(end_block);
curblock = end_block;
if (end_block->predecessors.size() == 0) {
delete end_block;
curblock = NULL;
} else {
cfg->placeBlock(end_block);
curblock = end_block;
}
return true;
}
......@@ -2436,8 +2441,13 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
|| terminator->type == AST_TYPE::Raise);
}
if (b->predecessors.size() == 0)
assert(b == rtn->getStartingBlock());
if (b->predecessors.size() == 0) {
if (b != rtn->getStartingBlock()) {
rtn->print();
printf("%s\n", source->getName().c_str());
}
ASSERT(b == rtn->getStartingBlock(), "%d", b->idx);
}
}
// We need to generate the CFG in a way that doesn't have any critical edges,
......
......@@ -34,3 +34,12 @@ else:
for i in xrange(5):
print i
break
def f():
for i in xrange(5):
if i == 10:
return 2
else:
return 5
f()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment