CODEGEN: buggy fixing:

visitReturn - shouldn't emit anything, just pass execution to evaluateReturn
evaluateThrow - should ends with unreachable statement
evaluateReturn - should actually emit ret instruction only for non-Unit return type of statement

(cherry picked from commit 0221353f05fa20826c817a9195210825535193c4)
This commit is contained in:
Konstantin Anisimov
2016-11-24 18:32:56 +03:00
committed by vvlevchenko
parent c05b8c6411
commit d88ff9ac08
@@ -279,9 +279,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
override fun visitReturn(expression: IrReturn) {
logger.log("visitReturn : ${ir2string(expression)}")
val tmpVarName = codegen.newVar() // Generate new tmp name.
val value = evaluateExpression(tmpVarName, expression.value) //
codegen.ret(value)
evaluateExpression("", expression)
}
//-------------------------------------------------------------------------//
@@ -374,7 +372,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
val objPointer = evaluateExpression(codegen.newVar(), expression.value)
val objHeaderPtr = codegen.bitcast(kObjHeaderPtr, objPointer!!, codegen.newVar())
val args = listOf(objHeaderPtr) // Create arg list.
return codegen.call(context.throwExceptionFunction, args, "")
codegen.call(context.throwExceptionFunction, args, "")
return codegen.unreachable()
}
//-------------------------------------------------------------------------//
@@ -612,6 +611,8 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
private fun evaluateReturn(value: IrReturn): LLVMValueRef? {
logger.log("evaluateReturn : ${ir2string(value)}")
val ret = evaluateExpression(codegen.newVar(), value.value)
if (KotlinBuiltIns.isUnit(value.value.type))
return ret
return codegen.ret(ret)
}