Fix empty vararg processing in intrinsics
This commit is contained in:
+43
-6
@@ -19,16 +19,39 @@ package org.jetbrains.kotlin.backend.jvm.intrinsics
|
|||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||||
|
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||||
import org.jetbrains.kotlin.codegen.Callable
|
import org.jetbrains.kotlin.codegen.Callable
|
||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
private class IrEmptyVarargExpression(
|
||||||
|
override val type: KotlinType,
|
||||||
|
override val startOffset: Int,
|
||||||
|
override val endOffset: Int
|
||||||
|
) : IrExpression {
|
||||||
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
||||||
|
TODO("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
TODO("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
|
TODO("not implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open class IrIntrinsicFunction(
|
open class IrIntrinsicFunction(
|
||||||
val expression: IrMemberAccessExpression,
|
val expression: IrMemberAccessExpression,
|
||||||
@@ -60,12 +83,26 @@ open class IrIntrinsicFunction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
open fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo):StackValue {
|
open fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo):StackValue {
|
||||||
val args = mutableListOf(expression.dispatchReceiver, expression.extensionReceiver)
|
val args = listOfNotNull(expression.dispatchReceiver, expression.extensionReceiver) +
|
||||||
args.addAll(expression.descriptor.valueParameters.mapIndexed {
|
expression.descriptor.valueParameters.mapIndexed { i, descriptor ->
|
||||||
i, _ ->
|
expression.getValueArgument(i) ?:
|
||||||
expression.getValueArgument(i)
|
if (descriptor.isVararg)
|
||||||
})
|
IrEmptyVarargExpression(descriptor.type, UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
||||||
args.filterNotNull().forEachIndexed { i, irExpression -> genArg(irExpression, codegen, i, data) }
|
else error("Unknown parameter: $descriptor in $expression")
|
||||||
|
}
|
||||||
|
|
||||||
|
args.forEachIndexed { i, irExpression ->
|
||||||
|
if (irExpression is IrEmptyVarargExpression) {
|
||||||
|
val parameterType = codegen.typeMapper.mapType(irExpression.type)
|
||||||
|
StackValue.operation(parameterType) {
|
||||||
|
it.aconst(0)
|
||||||
|
it.newarray(AsmUtil.correctElementType(parameterType))
|
||||||
|
}.put(parameterType, codegen.mv)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
genArg(irExpression, codegen, i, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
genInvokeInstruction(v)
|
genInvokeInstruction(v)
|
||||||
return StackValue.onStack(returnType)
|
return StackValue.onStack(returnType)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user