From 1e9163c73dab2c740d9673d97667ea4cd65cbdcc Mon Sep 17 00:00:00 2001 From: Alessandro Di Federico Date: Thu, 2 Mar 2017 11:16:32 +0100 Subject: [PATCH] Anticipate `cpu_loop_exit` removal Fix of another bug showing up only with LLVM in debug mode: splitting a malformed basic block is not allowed, and we had a function call after a `ret` instruction. --- codegenerator.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/codegenerator.cpp b/codegenerator.cpp index d9dcc7300..d31bf7baa 100644 --- a/codegenerator.cpp +++ b/codegenerator.cpp @@ -427,8 +427,13 @@ bool CpuLoopExitPass::runOnModule(llvm::Module& M) { assert(CpuLoop != nullptr); - for (User *TheUser : CpuLoopExit->users()) { - auto *Call = cast(TheUser); + std::queue CpuLoopExitUsers; + for (User *TheUser : CpuLoopExit->users()) + CpuLoopExitUsers.push(TheUser); + + while (!CpuLoopExitUsers.empty()) { + auto *Call = cast(CpuLoopExitUsers.front()); + CpuLoopExitUsers.pop(); assert(Call->getCalledFunction() == CpuLoopExit); // Call cpu_loop @@ -444,9 +449,11 @@ bool CpuLoopExitPass::runOnModule(llvm::Module& M) { auto *Unreach = cast(&*++Call->getIterator()); Unreach->eraseFromParent(); - // Remove the call to cpu_loop_exit Function *Caller = Call->getParent()->getParent(); + // Remove the call to cpu_loop_exit + Call->eraseFromParent(); + if (FixedCallers.find(Caller) == FixedCallers.end()) { FixedCallers.insert(Caller); @@ -518,9 +525,6 @@ bool CpuLoopExitPass::runOnModule(llvm::Module& M) { } } - for (User *TheUser : CpuLoopExit->users()) - cast(TheUser)->eraseFromParent(); - return true; }