From 21ad85216f8837221f8ba856c0cb8a1801e82427 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 24 May 2017 14:52:52 +0300 Subject: [PATCH] Fixed bug with name clash for package level properties --- .../kotlin/backend/konan/llvm/LlvmDeclarations.kt | 7 ++++--- .../org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt | 5 +++-- .../jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt index 47d0f43046e..ae02071e75b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmDeclarations.kt @@ -287,13 +287,14 @@ private class DeclarationsGeneratorVisitor(override val context: Context) : return null } - val symbolName = if (descriptor.isExported()) { + val isExported = descriptor.isExported() + val symbolName = if (isExported) { descriptor.objectInstanceFieldSymbolName } else { "kobjref:" + qualifyInternalName(descriptor) } val instanceFieldRef = addGlobal( - symbolName, getLLVMType(descriptor.defaultType), threadLocal = true) + symbolName, getLLVMType(descriptor.defaultType), isExported = isExported, threadLocal = true) return SingletonLlvmDeclarations(instanceFieldRef) } @@ -320,7 +321,7 @@ private class DeclarationsGeneratorVisitor(override val context: Context) : val name = "kvar:" + qualifyInternalName(descriptor) val storage = addGlobal( - name, getLLVMType(descriptor.type), threadLocal = true) + name, getLLVMType(descriptor.type), isExported = false, threadLocal = true) this.staticFields[descriptor] = StaticFieldLlvmDeclarations(storage) } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt index 935c2b5b88f..6b709b963ba 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt @@ -182,9 +182,10 @@ internal fun getGlobalType(ptrToGlobal: LLVMValueRef): LLVMTypeRef { return LLVMGetElementType(ptrToGlobal.type)!! } -internal fun ContextUtils.addGlobal(name: String, type: LLVMTypeRef, +internal fun ContextUtils.addGlobal(name: String, type: LLVMTypeRef, isExported: Boolean, threadLocal: Boolean = false): LLVMValueRef { - assert(LLVMGetNamedGlobal(context.llvmModule, name) == null) + if (isExported) + assert(LLVMGetNamedGlobal(context.llvmModule, name) == null) val result = LLVMAddGlobal(context.llvmModule, type, name)!! if (threadLocal) LLVMSetThreadLocalMode(result, runtime.tlsMode) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt index e0c667bbb8d..61b28dac633 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt @@ -71,7 +71,7 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils { if (annot != null) { val nameValue = annot.allValueArguments.values.single() as StringValue // TODO: use LLVMAddAlias? - val global = addGlobal(nameValue.value, pointerType(runtime.typeInfoType)) + val global = addGlobal(nameValue.value, pointerType(runtime.typeInfoType), isExported = true) LLVMSetInitializer(global, typeInfoGlobal) } }