Commit e383ced8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix asserts to not break refcounting

They were handled as a "assert 0; jump to loop that doesn't return".
Instead, just allow "assert 0" to be a block terminator.
parent 1da11c84
...@@ -1996,6 +1996,9 @@ private: ...@@ -1996,6 +1996,9 @@ private:
} }
llvm::CallSite call = emitter.createCall(unw_info, g.funcs.assertFail, llvm_args); llvm::CallSite call = emitter.createCall(unw_info, g.funcs.assertFail, llvm_args);
call.setDoesNotReturn(); call.setDoesNotReturn();
emitter.getBuilder()->CreateUnreachable();
endBlock(DEAD);
} }
void doAssign(AST_Assign* node, const UnwindInfo& unw_info) { void doAssign(AST_Assign* node, const UnwindInfo& unw_info) {
......
...@@ -361,6 +361,19 @@ static std::vector<llvm::BasicBlock*> computeTraversalOrder(llvm::Function* f) { ...@@ -361,6 +361,19 @@ static std::vector<llvm::BasicBlock*> computeTraversalOrder(llvm::Function* f) {
} }
} }
#ifndef NDEBUG
// This can currently get tripped if we generate an LLVM IR that has an infinite loop in it.
// This could definitely be supported, but I don't think we should be generating those cases anyway.
if (!best) {
for (auto& BB : ordering) {
llvm::outs() << "added to " << BB->getName() << '\n';
}
for (auto& BB : *f) {
if (added.count(&BB) == 0)
llvm::outs() << "never got to " << BB.getName() << '\n';
}
}
#endif
assert(best); assert(best);
ordering.push_back(best); ordering.push_back(best);
added.insert(best); added.insert(best);
......
...@@ -1673,13 +1673,6 @@ public: ...@@ -1673,13 +1673,6 @@ public:
remapped->col_offset = node->col_offset; remapped->col_offset = node->col_offset;
push_back(remapped); push_back(remapped);
CFGBlock* unreachable = cfg->addBlock();
unreachable->info = "unreachable";
pushJump(unreachable);
curblock = unreachable;
pushJump(unreachable, true);
curblock = iftrue; curblock = iftrue;
return true; return true;
...@@ -2742,7 +2735,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) { ...@@ -2742,7 +2735,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
if (b->successors.size() == 0) { if (b->successors.size() == 0) {
AST_stmt* terminator = b->body.back(); AST_stmt* terminator = b->body.back();
assert(terminator->type == AST_TYPE::Return || terminator->type == AST_TYPE::Raise assert(terminator->type == AST_TYPE::Return || terminator->type == AST_TYPE::Raise
|| terminator->type == AST_TYPE::Raise); || terminator->type == AST_TYPE::Raise || terminator->type == AST_TYPE::Assert);
} }
if (b->predecessors.size() == 0) { if (b->predecessors.size() == 0) {
......
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