diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt index 44de7247377..3694dea13ff 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/CodeGenerator.kt @@ -402,17 +402,17 @@ internal class FunctionGenerationContext(val function: LLVMValueRef, } } - fun allocInstance(typeInfo: LLVMValueRef, lifetime: Lifetime): LLVMValueRef { - return call(context.llvm.allocInstanceFunction, listOf(typeInfo), lifetime) - } + fun allocInstance(typeInfo: LLVMValueRef, lifetime: Lifetime): LLVMValueRef = + call(context.llvm.allocInstanceFunction, listOf(typeInfo), lifetime) fun allocInstance(irClass: IrClass, lifetime: Lifetime): LLVMValueRef = allocInstance(codegen.typeInfoForAllocation(irClass), lifetime) - fun allocArray( - typeInfo: LLVMValueRef, count: LLVMValueRef, lifetime: Lifetime): LLVMValueRef { - return call(context.llvm.allocArrayFunction, listOf(typeInfo, count), lifetime) - } + fun allocArray(typeInfo: LLVMValueRef, + count: LLVMValueRef, + lifetime: Lifetime, + exceptionHandler: ExceptionHandler): LLVMValueRef = + call(context.llvm.allocArrayFunction, listOf(typeInfo, count), lifetime, exceptionHandler) fun unreachable(): LLVMValueRef? { val res = LLVMBuildUnreachable(builder) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 8efecf6684b..5695fbc2750 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -2062,12 +2062,12 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map { + val a = Array(-2) { "nope" } + println(a) + } + assertFailsWith { + val a = ByteArray(-2) + println(a) + } + assertFailsWith { + val a = UByteArray(-2) + println(a) + } + assertFailsWith { + val a = ShortArray(-2) + println(a) + } + assertFailsWith { + val a = UShortArray(-2) + println(a) + } + assertFailsWith { + val a = IntArray(-2) + println(a) + } + assertFailsWith { + val a = UIntArray(-2) + println(a) + } + assertFailsWith { + val a = LongArray(-2) + println(a) + } + assertFailsWith { + val a = ULongArray(-2) + println(a) + } + assertFailsWith { + val a = FloatArray(-2) + println(a) + } + assertFailsWith { + val a = DoubleArray(-2) + println(a) + } + assertFailsWith { + val a = BooleanArray(-2) + println(a) + } + assertFailsWith { + val a = CharArray(-2) + println(a) + } + println("OK") +} \ No newline at end of file diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index 6a1cfede7ad..4cbc1e3cbb3 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -1282,8 +1282,9 @@ OBJ_GETTER(AllocInstance, const TypeInfo* type_info) { RETURN_OBJ(ObjectContainer(type_info).GetPlace()); } -OBJ_GETTER(AllocArrayInstance, const TypeInfo* type_info, uint32_t elements) { +OBJ_GETTER(AllocArrayInstance, const TypeInfo* type_info, int32_t elements) { RuntimeAssert(type_info->instanceSize_ < 0, "must be an array"); + if (elements < 0) ThrowIllegalArgumentException(); if (isArenaSlot(OBJ_RESULT)) { auto arena = initedArena(asArenaSlot(OBJ_RESULT)); auto result = arena->PlaceArray(type_info, elements)->obj(); diff --git a/runtime/src/main/cpp/Memory.h b/runtime/src/main/cpp/Memory.h index e80c37ada40..c876d32261c 100644 --- a/runtime/src/main/cpp/Memory.h +++ b/runtime/src/main/cpp/Memory.h @@ -477,7 +477,7 @@ void ResumeMemory(MemoryState* state); // selection, and comes from upper bound esteemation of object lifetime. // OBJ_GETTER(AllocInstance, const TypeInfo* type_info) RUNTIME_NOTHROW; -OBJ_GETTER(AllocArrayInstance, const TypeInfo* type_info, uint32_t elements) RUNTIME_NOTHROW; +OBJ_GETTER(AllocArrayInstance, const TypeInfo* type_info, int32_t elements); void DeinitInstanceBody(const TypeInfo* typeInfo, void* body); OBJ_GETTER(InitInstance, ObjHeader** location, const TypeInfo* type_info, void (*ctor)(ObjHeader*)); diff --git a/runtime/src/main/kotlin/kotlin/Any.kt b/runtime/src/main/kotlin/kotlin/Any.kt index 60c6383f373..5af7b7a9941 100644 --- a/runtime/src/main/kotlin/kotlin/Any.kt +++ b/runtime/src/main/kotlin/kotlin/Any.kt @@ -50,4 +50,4 @@ public open class Any { @PublishedApi @SymbolName("Kotlin_Any_hashCode") -external internal fun Any.identityHashCode(): Int \ No newline at end of file +external internal fun Any.identityHashCode(): Int