Fix primitive type globals initialization. (#189)

This commit is contained in:
Nikolay Igotti
2017-01-20 13:31:47 +03:00
committed by GitHub
parent 1c878e4843
commit eb6ba1cfa5
3 changed files with 6 additions and 4 deletions
@@ -597,11 +597,12 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
context.log("visitField : ${ir2string(expression)}")
val descriptor = expression.descriptor
if (descriptor.containingDeclaration is PackageFragmentDescriptor) {
val globalProperty = LLVMAddGlobal(context.llvmModule, codegen.getLLVMType(descriptor.type), descriptor.symbolName)
val type = codegen.getLLVMType(descriptor.type)
val globalProperty = LLVMAddGlobal(context.llvmModule, type, descriptor.symbolName)
if (expression.initializer!!.expression is IrConst<*>) {
LLVMSetInitializer(globalProperty, evaluateExpression(expression.initializer!!.expression))
} else {
LLVMSetInitializer(globalProperty, codegen.kNullObjHeaderPtr)
LLVMSetInitializer(globalProperty, LLVMConstNull(type))
context.llvm.fileInitializers.add(expression)
}
return
+1 -2
View File
@@ -829,8 +829,7 @@ task initializers3(type: RunKonanTest) {
}
task initializers4(type: RunKonanTest) {
disabled = true
goldValue = "fixme\n"
goldValue = "1073741824\ntrue\n"
source = "runtime/basic/initializers4.kt"
}
+2
View File
@@ -46,6 +46,8 @@ private class IteratorImpl<T>(val collection: Array<T>) : Iterator<T> {
}
}
fun <T> arrayOf(vararg elements: T) : Array<out T> = elements
public fun <T, C : MutableCollection<in T>> Array<out T>.toCollection(destination: C): C {
for (item in this) {
destination.add(item)