diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index 09c74e9cbc68c42cba3171dbd99cab1cd7e927ed..29a277a9a2e34916fef1a18361b677b0baf5cea4 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -22452,7 +22452,18 @@ void SMPFunction::EmitSPARKAdaForBlock(int CurrBlockNum, int FollowBlockNum, FIL } } else { - CurrBlock->EmitSPARKAdaForAllInsts(SPARKBodyFile); + bool StaysInLoop = this->IsNonExitingLoopBackBranch(LastInstAddr); + if (!StaysInLoop) { // just loop-back and return to EmitSPARKAdaForLoop(). + CurrBlock->EmitSPARKAdaForAllInsts(SPARKBodyFile); + } + else { + // We need to emit the fall through insts, then translate COND_BRANCH to loop header + // into if (inverted condition) then ... for the rest of the loop body. + CurrBlock->EmitSPARKAdaForFallThroughInsts(SPARKBodyFile); + // EmitSPARKAdaForConditional() will emit the if (inverted condition) then ... and + // will continue through the rest of the if-then body. + this->EmitSPARKAdaForConditional(CurrBlockNum, FollowBlockNum, SPARKBodyFile); + } } } else {