Cast int to byte/short/char in for loop generation
Similar to the previous commit, don't use iinc or iadd+istore where the value can overflow the byte/short/char limits. This fixes Android tests
This commit is contained in:
@@ -930,37 +930,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
checkPostCondition(loopExit);
|
checkPostCondition(loopExit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sort = asmElementType.getSort();
|
if (asmElementType == Type.INT_TYPE) {
|
||||||
switch (sort) {
|
v.iinc(loopParameterVar, 1);
|
||||||
case Type.INT:
|
}
|
||||||
case Type.CHAR:
|
else {
|
||||||
case Type.BYTE:
|
v.load(loopParameterVar, asmElementType);
|
||||||
case Type.SHORT:
|
genIncrement(asmElementType, 1, v);
|
||||||
v.iinc(loopParameterVar, 1);
|
v.store(loopParameterVar, asmElementType);
|
||||||
break;
|
|
||||||
|
|
||||||
case Type.LONG:
|
|
||||||
v.load(loopParameterVar, asmElementType);
|
|
||||||
v.lconst(1);
|
|
||||||
v.add(asmElementType);
|
|
||||||
v.store(loopParameterVar, asmElementType);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Type.FLOAT:
|
|
||||||
case Type.DOUBLE:
|
|
||||||
v.load(loopParameterVar, asmElementType);
|
|
||||||
if (sort == Type.DOUBLE) {
|
|
||||||
v.dconst(1.0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
v.fconst(1.0f);
|
|
||||||
}
|
|
||||||
v.add(asmElementType);
|
|
||||||
v.store(loopParameterVar, asmElementType);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected range element type: " + asmElementType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1149,6 +1125,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
v.load(incrementVar, asmElementType);
|
v.load(incrementVar, asmElementType);
|
||||||
v.add(asmElementType);
|
v.add(asmElementType);
|
||||||
|
|
||||||
|
if (asmElementType == Type.BYTE_TYPE || asmElementType == Type.SHORT_TYPE || asmElementType == Type.CHAR_TYPE) {
|
||||||
|
StackValue.coerce(Type.INT_TYPE, asmElementType, v);
|
||||||
|
}
|
||||||
|
|
||||||
v.store(loopParameterVar, asmElementType);
|
v.store(loopParameterVar, asmElementType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user