@@ -45,29 +45,36 @@ export class ForStatementGenerator implements NodeGenerateInterface<ts.ForStatem
4545 builder . setInsertionPoint ( bodyBlock ) ;
4646 }
4747
48- ctx . scope . breakBlock = next ;
49- ctx . scope . continueBlock = startBlock ;
50-
51- builder . setInsertionPoint ( bodyBlock ) ;
52- passStatement ( node . statement , ctx , builder ) ;
48+ /**
49+ * Continue block can be incrementer block: for (i = 0; i < 100; i++)
50+ * or next block: for (i = 0; i < 100; )
51+ */
52+ let continueBlock : llvm . BasicBlock = startBlock ;
5353
5454 if ( node . incrementor ) {
5555 const incrementer = llvm . BasicBlock . create ( ctx . llvmContext , "for.inc" ) ;
5656 ctx . scope . enclosureFunction . llvmFunction . addBasicBlock ( incrementer ) ;
5757
58- // jump from bodyBlock to incrementer
59- builder . createBr ( incrementer ) ;
6058 builder . setInsertionPoint ( incrementer ) ;
61-
6259 passStatement ( < any > node . incrementor , ctx , builder ) ;
60+
61+ builder . createBr ( startBlock ) ;
62+
63+ continueBlock = incrementer ;
6364 }
6465
66+ ctx . scope . breakBlock = next ;
67+ ctx . scope . continueBlock = continueBlock ;
68+
69+ builder . setInsertionPoint ( bodyBlock ) ;
70+ passStatement ( node . statement , ctx , builder ) ;
71+
6572 // next iteration of cycle
66- builder . createBr ( startBlock ) ;
73+ builder . createBr ( continueBlock ) ;
6774
6875 ctx . scope . breakBlock = null ;
6976 ctx . scope . continueBlock = null ;
7077
7178 builder . setInsertionPoint ( next ) ;
7279 }
73- }
80+ }
0 commit comments