diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt index 7ca0df21e11..63d2df89378 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/ContextUtils.kt @@ -92,13 +92,15 @@ internal interface ContextUtils { /** * Returns pointer to first element of given array. * + * Note: this function doesn't depend on the context + * * @param arrayPtr pointer to array */ private fun getPtrToFirstElem(arrayPtr: CompileTimeValue): CompileTimeValue { val indices = longArrayOf(0, 0).map { LLVMConstInt(LLVMInt32Type(), it, 0) }.toTypedArray() val indicesNativeArrayPtr = mallocNativeArrayOf(LLVMOpaqueValue, *indices)[0] // TODO: dispose - return compileTimeValue(LLVMBuildGEP(context.llvmBuilder, arrayPtr.getLlvmValue(), indicesNativeArrayPtr, indices.size, "")) + return compileTimeValue(LLVMConstGEP(arrayPtr.getLlvmValue(), indicesNativeArrayPtr, indices.size)) } /** diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt index 70338199966..bcc8a661229 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/llvm/LlvmUtils.kt @@ -8,9 +8,9 @@ import org.jetbrains.kotlin.utils.singletonOrEmptyList /** * Represents the value which can be emitted as bitcode const value */ -internal abstract class CompileTimeValue { +internal interface CompileTimeValue { - abstract fun getLlvmValue(): LLVMOpaqueValue? + fun getLlvmValue(): LLVMOpaqueValue? fun getLlvmType(): LLVMOpaqueType? { return LLVMTypeOf(getLlvmValue()) @@ -18,7 +18,7 @@ internal abstract class CompileTimeValue { } -internal class ConstArray(val elemType: LLVMOpaqueType?, val elements: List) : CompileTimeValue() { +internal class ConstArray(val elemType: LLVMOpaqueType?, val elements: List) : CompileTimeValue { override fun getLlvmValue(): LLVMOpaqueValue? { val values = elements.map { it.getLlvmValue() }.toTypedArray() @@ -28,7 +28,7 @@ internal class ConstArray(val elemType: LLVMOpaqueType?, val elements: List) : CompileTimeValue() { +internal open class Struct(val type: LLVMOpaqueType?, val elements: List) : CompileTimeValue { constructor(type: LLVMOpaqueType?, vararg elements: CompileTimeValue) : this(type, elements.toList()) @@ -39,23 +39,23 @@ internal open class Struct(val type: LLVMOpaqueType?, val elements: List