[K/N] Fix KT-50843
Marking constants with unnamed_addr allows LLVM to merge them.
This commit is contained in:
+7
@@ -74,6 +74,13 @@ internal class StaticData(override val context: Context): ContextUtils {
|
||||
LLVMSetGlobalConstant(llvmGlobal, if (value) 1 else 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Globals that are marked with unnamed_addr might be merged by LLVM's ConstantMerge pass.
|
||||
*/
|
||||
fun setUnnamedAddr(value: Boolean) {
|
||||
LLVMSetUnnamedAddr(llvmGlobal, if (value) 1 else 0)
|
||||
}
|
||||
|
||||
fun setLinkage(value: LLVMLinkage) {
|
||||
LLVMSetLinkage(llvmGlobal, value)
|
||||
}
|
||||
|
||||
+2
@@ -56,6 +56,7 @@ internal fun StaticData.createConstKotlinArray(arrayClass: IrClass, elements: Li
|
||||
|
||||
global.setInitializer(Struct(compositeType, arrayHeader, arrayBody))
|
||||
global.setConstant(true)
|
||||
global.setUnnamedAddr(true)
|
||||
|
||||
return createRef(objHeaderPtr)
|
||||
}
|
||||
@@ -65,6 +66,7 @@ internal fun StaticData.createConstKotlinObject(type: IrClass, vararg fields: Co
|
||||
val objHeader = objHeader(typeInfo)
|
||||
|
||||
val global = this.placeGlobal("", Struct(objHeader, *fields))
|
||||
global.setUnnamedAddr(true)
|
||||
global.setConstant(true)
|
||||
|
||||
val objHeaderPtr = global.pointer.getElementPtr(0)
|
||||
|
||||
Reference in New Issue
Block a user