diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/processUninitializedStores.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/processUninitializedStores.kt index 45f27bef086..ed42bb30407 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/processUninitializedStores.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/processUninitializedStores.kt @@ -75,6 +75,11 @@ class UninitializedStoresProcessor( private val methodNode: MethodNode, private val shouldPreserveClassInitialization: Boolean ) { + companion object { + val AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR = + "Lkotlin/internal/annotations/AvoidUninitializedObjectCopyingCheck;" + } + // method is "special", because it will invoke from this class or from a base class for #0 // // method is "special", because for singleton objects is generated as: @@ -83,7 +88,11 @@ class UninitializedStoresProcessor( // and the newly created value is dropped. private val isInSpecialMethod = methodNode.name == "" || methodNode.name == "" + private val shouldCheckUninitializedObjectCopy = !methodNode.invisibleAnnotations.orEmpty() + .any { it.desc == AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR } + fun run() { + if (!shouldCheckUninitializedObjectCopy) return val interpreter = UninitializedNewValueMarkerInterpreter(methodNode.instructions) val frames = CustomFramesMethodAnalyzer( @@ -174,7 +183,7 @@ class UninitializedStoresProcessor( assert(insn.opcode == Opcodes.INVOKESPECIAL) { "Expected opcode Opcodes.INVOKESPECIAL for , but ${insn.opcode} found" } val paramsCountIncludingReceiver = Type.getArgumentTypes((insn as MethodInsnNode).desc).size + 1 val newValue = peek(paramsCountIncludingReceiver) as? UninitializedNewValue ?: - if (isInSpecialMethod) + if (isInSpecialMethod || !shouldCheckUninitializedObjectCopy) return null else error("Expected value generated with NEW") diff --git a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableCodegenExtension.kt b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableCodegenExtension.kt index 79ef44569b2..66c2f4e6739 100644 --- a/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableCodegenExtension.kt +++ b/plugins/android-extensions/android-extensions-compiler/src/org/jetbrains/kotlin/android/parcel/ParcelableCodegenExtension.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature import org.jetbrains.kotlin.codegen.FunctionGenerationStrategy.CodegenBased import org.jetbrains.kotlin.codegen.OwnerKind import org.jetbrains.kotlin.codegen.context.ClassContext +import org.jetbrains.kotlin.codegen.coroutines.UninitializedStoresProcessor import org.jetbrains.kotlin.codegen.writeSyntheticClassMetadata import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl import org.jetbrains.kotlin.incremental.components.NoLookupLocation @@ -100,6 +101,8 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension { val containerAsmType = codegen.typeMapper.mapType(this.defaultType) return findFunction(WRITE_TO_PARCEL)?.write(codegen) { + v.visitAnnotation(UninitializedStoresProcessor.AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR, false) + if (parcelerObject != null) { val (companionAsmType, companionFieldName) = getCompanionClassType(containerAsmType, parcelerObject) @@ -178,6 +181,8 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension { val containerAsmType = codegen.typeMapper.mapType(parcelableClass) createMethod(creatorClass, CREATE_FROM_PARCEL, parcelableClass.builtIns.anyType, "in" to parcelClassType).write(codegen) { + v.visitAnnotation(UninitializedStoresProcessor.AVOID_UNINITIALIZED_OBJECT_COPYING_CHECK_ANNOTATION_DESCRIPTOR, false) + if (parcelerObject != null) { val (companionAsmType, companionFieldName) = getCompanionClassType(containerAsmType, parcelerObject)