From c9e7a4faed278f64727fcfbabfa6bf4cccbdc489 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Tue, 3 Jul 2018 20:16:27 +0300 Subject: [PATCH] Fixed bug with objects access in global initialisers + test --- .../kotlin/backend/konan/llvm/IrToBitcode.kt | 25 ++++++++++--------- backend.native/tests/build.gradle | 4 +++ .../tests/codegen/object/globalInitializer.kt | 7 ++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 backend.native/tests/codegen/object/globalInitializer.kt 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 6adadd41d58..e19fdfd2a13 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 @@ -394,6 +394,19 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map?) { + val initialization = evaluateExpression(it.initializer!!.expression) + val address = context.llvmDeclarations.forStaticField(it).storage + storeAny(initialization, address) + } + } + ret(null) + } + appendingTo(bbLocalDeinit) { context.llvm.fileInitializers.forEach { val descriptor = it @@ -410,18 +423,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map?) { - val initialization = evaluateExpression(it.initializer!!.expression) - val address = context.llvmDeclarations.forStaticField(it).storage - storeAny(initialization, address) - } - } - ret(null) - } } } return initFunction diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index cfaa76eba6c..cfa46aeeb2f 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -266,6 +266,10 @@ task objectInitialization1(type: RunKonanTest) { source = "codegen/object/initialization1.kt" } +task object_globalInitializer(type: RunStandaloneKonanTest) { + source = "codegen/object/globalInitializer.kt" +} + task check_type(type: RunKonanTest) { goldValue = "true\nfalse\ntrue\ntrue\ntrue\ntrue\n" source = "codegen/basics/check_type.kt" diff --git a/backend.native/tests/codegen/object/globalInitializer.kt b/backend.native/tests/codegen/object/globalInitializer.kt new file mode 100644 index 00000000000..9f9848a8491 --- /dev/null +++ b/backend.native/tests/codegen/object/globalInitializer.kt @@ -0,0 +1,7 @@ +// Does not fail with TR. + +public val z: Any = Z + +private object Z + +fun main(args: Array) { } \ No newline at end of file