Add bytecode text tests for ForLoopsLowering.

This commit is contained in:
Mark Punzalan
2019-06-21 23:06:26 -07:00
committed by max-kammerer
parent 277cb39e3b
commit 9bb9ab67a7
18 changed files with 750 additions and 3 deletions
@@ -0,0 +1,40 @@
// TARGET_BACKEND: JVM_IR
fun box(): String {
for (i in 1..6 step 0) {
}
return "OK"
}
// For "step" progressions in JVM IR, if the step is constant and <= 0, the expression for step is replaced with an
// IllegalArgumentException. The backend can then eliminate the entire loop and the rest of the function as dead code.
//
// Expected lowered form of loop (before bytecode optimization):
//
// // Additional variables:
// val newStep = throw IllegalArgumentException("Step must be positive, was: 0.")
//
// // Standard form of loop over progression
// var inductionVar = 1
// val last = getProgressionLastElement(1, 6, newStep)
// val step = newStep
// if (inductionVar <= last) {
// // Loop is not empty
// do {
// val i = inductionVar
// inductionVar += step
// // Loop body
// } while (i != last)
// }
// 0 iterator
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// 0 getStep
// 0 INVOKESTATIC kotlin/internal/ProgressionUtilKt.getProgressionLastElement
// 1 NEW java/lang/IllegalArgumentException
// 1 ATHROW
// 0 IF
// 0 ARETURN