Ensure type of a stack value is coerced to the expected return type after the binary operation instruction with the different return type.

This commit is contained in:
Ilya Gorbunov
2015-07-11 16:09:22 +03:00
parent f7ccb3819e
commit 4ad6a8e301
6 changed files with 55 additions and 9 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen.intrinsics
import org.jetbrains.kotlin.codegen.AsmUtil.numberFunctionOperandType
import org.jetbrains.kotlin.codegen.Callable
import org.jetbrains.kotlin.codegen.CallableMethod
import org.jetbrains.kotlin.codegen.StackValue
import org.jetbrains.org.objectweb.asm.Opcodes.ISHL
import org.jetbrains.org.objectweb.asm.Opcodes.ISHR
import org.jetbrains.org.objectweb.asm.Opcodes.IUSHR
@@ -35,7 +36,10 @@ public class BinaryOp(private val opcode: Int) : IntrinsicMethod() {
val paramType = if (shift()) Type.INT_TYPE else operandType
return createBinaryIntrinsicCallable(returnType, paramType, operandType) {
v -> v.visitInsn(returnType.getOpcode(opcode))
v ->
v.visitInsn(returnType.getOpcode(opcode));
if (operandType != returnType)
StackValue.coerce(operandType, returnType, v)
}
}
}