JVM_IR: Support 'CHECK_NOT_NULL' intrinsic
TODO: migrate to changes related to KT-22275
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.PromisedValue
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.org.objectweb.asm.Label
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
object IrCheckNotNull : IntrinsicMethod() {
|
||||
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue? {
|
||||
val arg0 = expression.getValueArgument(0)!!.accept(codegen, data)
|
||||
if (AsmUtil.isPrimitive(arg0.type)) return arg0
|
||||
|
||||
return object : PromisedValue(codegen, arg0.type, expression.type) {
|
||||
override fun materialize() {
|
||||
arg0.materialize()
|
||||
mv.dup()
|
||||
val ifNonNullLabel = Label()
|
||||
mv.ifnonnull(ifNonNullLabel)
|
||||
mv.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "throwNpe", Type.getMethodDescriptor(Type.VOID_TYPE), false)
|
||||
mv.mark(ifNonNullLabel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -96,7 +96,7 @@ class IrIntrinsicMethods(val irBuiltIns: IrBuiltIns, val symbols: JvmSymbols) {
|
||||
irBuiltIns.enumValueOfSymbol.toKey()!! to IrEnumValueOf,
|
||||
irBuiltIns.noWhenBranchMatchedExceptionSymbol.toKey()!! to IrNoWhenBranchMatchedException,
|
||||
irBuiltIns.illegalArgumentExceptionSymbol.toKey()!! to IrIllegalArgumentException,
|
||||
// irBuiltIns.throwNpeSymbol.toKey()!! to ThrowNPE, -- TODO checkNotNullSymbol
|
||||
irBuiltIns.checkNotNullSymbol.toKey()!! to IrCheckNotNull,
|
||||
irBuiltIns.andandSymbol.toKey()!! to AndAnd,
|
||||
irBuiltIns.ororSymbol.toKey()!! to OrOr,
|
||||
symbols.unsafeCoerceIntrinsicSymbol.toKey()!! to UnsafeCoerce
|
||||
|
||||
Vendored
-1
@@ -1,5 +1,4 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,5 +1,4 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
// FILE: utils.kt
|
||||
|
||||
|
||||
@@ -8,4 +8,4 @@ fun stubPreventBoxingOptimization(s: Int?) {
|
||||
s
|
||||
}
|
||||
|
||||
//0 CHECKCAST java/lang/Number
|
||||
// 0 CHECKCAST java/lang/Number
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: j/J.java
|
||||
|
||||
package j;
|
||||
|
||||
Reference in New Issue
Block a user