translator: fix null store in class fields
This commit is contained in:
@@ -844,12 +844,9 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
KtTokens.EQ -> {
|
KtTokens.EQ -> {
|
||||||
codeBuilder.addComment("start variable assignment")
|
codeBuilder.addComment("start variable assignment")
|
||||||
if (secondOp.type is LLVMNullType) {
|
if (secondOp.type is LLVMNullType) {
|
||||||
val result = codeBuilder.getNewVariable(firstOp.type!!, firstOp.pointer)
|
codeBuilder.storeNull(firstOp as LLVMVariable)
|
||||||
codeBuilder.allocStackVar(result)
|
codeBuilder.addComment("end null variable assignment")
|
||||||
result.pointer++
|
return firstOp
|
||||||
|
|
||||||
codeBuilder.storeNull(result)
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -991,6 +988,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun evaluateIfOperator(element: KtIfExpression, scopeDepth: Int, isExpression: Boolean = true): LLVMVariable? {
|
private fun evaluateIfOperator(element: KtIfExpression, scopeDepth: Int, isExpression: Boolean = true): LLVMVariable? {
|
||||||
|
codeBuilder.addComment("begin evaluate if")
|
||||||
val conditionResult = evaluateExpression(element.condition, scopeDepth)!!
|
val conditionResult = evaluateExpression(element.condition, scopeDepth)!!
|
||||||
val conditionNativeResult = codeBuilder.downLoadArgument(conditionResult, 0)
|
val conditionNativeResult = codeBuilder.downLoadArgument(conditionResult, 0)
|
||||||
|
|
||||||
@@ -1005,6 +1003,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
val expressionType = LLVMInstanceOfStandardType("type", kotlinType, LLVMVariableScope(), state).type
|
val expressionType = LLVMInstanceOfStandardType("type", kotlinType, LLVMVariableScope(), state).type
|
||||||
val resultVariable = codeBuilder.getNewVariable(expressionType, pointer = 1)
|
val resultVariable = codeBuilder.getNewVariable(expressionType, pointer = 1)
|
||||||
|
|
||||||
|
codeBuilder.addComment("start if expression")
|
||||||
when (resultVariable.type) {
|
when (resultVariable.type) {
|
||||||
is LLVMReferenceType -> codeBuilder.allocStaticVar(resultVariable, asValue = true)
|
is LLVMReferenceType -> codeBuilder.allocStaticVar(resultVariable, asValue = true)
|
||||||
else -> codeBuilder.allocStackVar(resultVariable, asValue = true)
|
else -> codeBuilder.allocStackVar(resultVariable, asValue = true)
|
||||||
@@ -1026,6 +1025,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
codeBuilder.storeVariable(resultVariable, elseResultNativeExpression)
|
codeBuilder.storeVariable(resultVariable, elseResultNativeExpression)
|
||||||
codeBuilder.addUnconditionalJump(endLabel)
|
codeBuilder.addUnconditionalJump(endLabel)
|
||||||
codeBuilder.markWithLabel(endLabel)
|
codeBuilder.markWithLabel(endLabel)
|
||||||
|
codeBuilder.addComment("end if expression")
|
||||||
return resultVariable
|
return resultVariable
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1034,6 +1034,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
val elseLabel = codeBuilder.getNewLabel(prefix = "if")
|
val elseLabel = codeBuilder.getNewLabel(prefix = "if")
|
||||||
val endLabel = codeBuilder.getNewLabel(prefix = "if")
|
val endLabel = codeBuilder.getNewLabel(prefix = "if")
|
||||||
|
|
||||||
|
codeBuilder.addComment("start if operator")
|
||||||
codeBuilder.addCondition(conditionResult, thenLabel, if (elseExpression != null) elseLabel else endLabel)
|
codeBuilder.addCondition(conditionResult, thenLabel, if (elseExpression != null) elseLabel else endLabel)
|
||||||
|
|
||||||
evaluateCodeBlock(thenExpression, thenLabel, endLabel, endLabel, scopeDepth + 1)
|
evaluateCodeBlock(thenExpression, thenLabel, endLabel, endLabel, scopeDepth + 1)
|
||||||
@@ -1042,7 +1043,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
}
|
}
|
||||||
|
|
||||||
codeBuilder.markWithLabel(endLabel)
|
codeBuilder.markWithLabel(endLabel)
|
||||||
|
codeBuilder.addComment("end if operator")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user