JVM IR: generate call to checkNotNull in IrCheckNotNull since 1.4
#KT-22275
This commit is contained in:
+1
-1
@@ -110,7 +110,7 @@ class ExpressionCodegen(
|
|||||||
val typeMapper = context.typeMapper
|
val typeMapper = context.typeMapper
|
||||||
val methodSignatureMapper = context.methodSignatureMapper
|
val methodSignatureMapper = context.methodSignatureMapper
|
||||||
|
|
||||||
private val state = classCodegen.state
|
val state = classCodegen.state
|
||||||
|
|
||||||
private val fileEntry = classCodegen.context.psiSourceManager.getFileEntry(irFunction.fileParent)
|
private val fileEntry = classCodegen.context.psiSourceManager.getFileEntry(irFunction.fileParent)
|
||||||
|
|
||||||
|
|||||||
+10
-6
@@ -10,9 +10,9 @@ import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
|||||||
import org.jetbrains.kotlin.backend.jvm.codegen.PromisedValue
|
import org.jetbrains.kotlin.backend.jvm.codegen.PromisedValue
|
||||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
||||||
|
import org.jetbrains.kotlin.config.ApiVersion
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||||
import org.jetbrains.org.objectweb.asm.Label
|
import org.jetbrains.org.objectweb.asm.Label
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
|
||||||
|
|
||||||
object IrCheckNotNull : IntrinsicMethod() {
|
object IrCheckNotNull : IntrinsicMethod() {
|
||||||
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue? {
|
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue? {
|
||||||
@@ -23,11 +23,15 @@ object IrCheckNotNull : IntrinsicMethod() {
|
|||||||
override fun materialize() {
|
override fun materialize() {
|
||||||
arg0.materialize()
|
arg0.materialize()
|
||||||
mv.dup()
|
mv.dup()
|
||||||
val ifNonNullLabel = Label()
|
if (codegen.state.languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4) {
|
||||||
mv.ifnonnull(ifNonNullLabel)
|
mv.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "checkNotNull", "(Ljava/lang/Object;)V", false)
|
||||||
mv.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "throwNpe", Type.getMethodDescriptor(Type.VOID_TYPE), false)
|
} else {
|
||||||
mv.mark(ifNonNullLabel)
|
val ifNonNullLabel = Label()
|
||||||
|
mv.ifnonnull(ifNonNullLabel)
|
||||||
|
mv.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "throwNpe", "()V", false)
|
||||||
|
mv.mark(ifNonNullLabel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2000-2018 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.JvmBackendContext
|
|
||||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
|
||||||
|
|
||||||
object ThrowNPE : IntrinsicMethod() {
|
|
||||||
override fun toCallable(
|
|
||||||
expression: IrFunctionAccessExpression,
|
|
||||||
signature: JvmMethodSignature,
|
|
||||||
context: JvmBackendContext
|
|
||||||
): IrIntrinsicFunction {
|
|
||||||
return IrIntrinsicFunction.createWithResult(expression, signature, context) {
|
|
||||||
it.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "throwNpe", "()V", false)
|
|
||||||
Type.VOID_TYPE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// !API_VERSION: LATEST
|
// !API_VERSION: LATEST
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
val s: String? = null
|
val s: String? = null
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// !API_VERSION: LATEST
|
// !API_VERSION: LATEST
|
||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
|
|
||||||
fun test(s: String?): Int {
|
fun test(s: String?): Int {
|
||||||
s!!
|
s!!
|
||||||
|
|||||||
-1
@@ -1,5 +1,4 @@
|
|||||||
// !API_VERSION: LATEST
|
// !API_VERSION: LATEST
|
||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
|
|
||||||
fun test(s: String?): Int {
|
fun test(s: String?): Int {
|
||||||
s!!
|
s!!
|
||||||
|
|||||||
Reference in New Issue
Block a user