Fixed bug with objects access in global initialisers + test
This commit is contained in:
+13
-12
@@ -394,6 +394,19 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
Int32(DEINIT_GLOBALS).llvm to bbGlobalDeinit),
|
Int32(DEINIT_GLOBALS).llvm to bbGlobalDeinit),
|
||||||
bbDefault)
|
bbDefault)
|
||||||
|
|
||||||
|
// Globals initalizers may contain accesses to objects, so visit them first.
|
||||||
|
appendingTo(bbInit) {
|
||||||
|
context.llvm.fileInitializers
|
||||||
|
.forEach {
|
||||||
|
if (it.initializer?.expression !is IrConst<*>?) {
|
||||||
|
val initialization = evaluateExpression(it.initializer!!.expression)
|
||||||
|
val address = context.llvmDeclarations.forStaticField(it).storage
|
||||||
|
storeAny(initialization, address)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret(null)
|
||||||
|
}
|
||||||
|
|
||||||
appendingTo(bbLocalDeinit) {
|
appendingTo(bbLocalDeinit) {
|
||||||
context.llvm.fileInitializers.forEach {
|
context.llvm.fileInitializers.forEach {
|
||||||
val descriptor = it
|
val descriptor = it
|
||||||
@@ -410,18 +423,6 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
context.llvm.sharedObjects.forEach { storeAny(codegen.kNullObjHeaderPtr, it) }
|
context.llvm.sharedObjects.forEach { storeAny(codegen.kNullObjHeaderPtr, it) }
|
||||||
ret(null)
|
ret(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
appendingTo(bbInit) {
|
|
||||||
context.llvm.fileInitializers
|
|
||||||
.forEach {
|
|
||||||
if (it.initializer?.expression !is IrConst<*>?) {
|
|
||||||
val initialization = evaluateExpression(it.initializer!!.expression)
|
|
||||||
val address = context.llvmDeclarations.forStaticField(it).storage
|
|
||||||
storeAny(initialization, address)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret(null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return initFunction
|
return initFunction
|
||||||
|
|||||||
@@ -266,6 +266,10 @@ task objectInitialization1(type: RunKonanTest) {
|
|||||||
source = "codegen/object/initialization1.kt"
|
source = "codegen/object/initialization1.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task object_globalInitializer(type: RunStandaloneKonanTest) {
|
||||||
|
source = "codegen/object/globalInitializer.kt"
|
||||||
|
}
|
||||||
|
|
||||||
task check_type(type: RunKonanTest) {
|
task check_type(type: RunKonanTest) {
|
||||||
goldValue = "true\nfalse\ntrue\ntrue\ntrue\ntrue\n"
|
goldValue = "true\nfalse\ntrue\ntrue\ntrue\ntrue\n"
|
||||||
source = "codegen/basics/check_type.kt"
|
source = "codegen/basics/check_type.kt"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// Does not fail with TR.
|
||||||
|
|
||||||
|
public val z: Any = Z
|
||||||
|
|
||||||
|
private object Z
|
||||||
|
|
||||||
|
fun main(args: Array<String>) { }
|
||||||
Reference in New Issue
Block a user