translator: fix null return from classes
This commit is contained in:
@@ -1064,7 +1064,8 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
|
|
||||||
when (type) {
|
when (type) {
|
||||||
is LLVMReferenceType -> genReferenceReturn(retVar!!)
|
is LLVMReferenceType -> genReferenceReturn(retVar!!)
|
||||||
is LLVMVoidType -> {
|
is LLVMVoidType,
|
||||||
|
is LLVMNullType -> {
|
||||||
codeBuilder.addAnyReturn(LLVMVoidType())
|
codeBuilder.addAnyReturn(LLVMVoidType())
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class LLVMBuilder(val arm: Boolean = false) {
|
|||||||
"declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)",
|
"declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1)",
|
||||||
"declare i8* @malloc_static(i32)",
|
"declare i8* @malloc_static(i32)",
|
||||||
"declare i32 @printf(i8*, ...)",
|
"declare i32 @printf(i8*, ...)",
|
||||||
|
"%class.Nothing = type { }",
|
||||||
"declare void @abort()")
|
"declare void @abort()")
|
||||||
|
|
||||||
declares.forEach { globalCode.appendln(it) }
|
declares.forEach { globalCode.appendln(it) }
|
||||||
@@ -77,8 +78,8 @@ class LLVMBuilder(val arm: Boolean = false) {
|
|||||||
localCode.appendln("ret ${llvmVariable.type} $llvmVariable")
|
localCode.appendln("ret ${llvmVariable.type} $llvmVariable")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addAnyReturn(type: LLVMType, value: String = type.defaultValue) {
|
fun addAnyReturn(type: LLVMType, value: String = type.defaultValue, pointer: Int = 0) {
|
||||||
localCode.appendln("ret $type $value")
|
localCode.appendln("ret $type${"*".repeat(pointer)} $value")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeString(string: String): LLVMVariable {
|
private fun initializeString(string: String): LLVMVariable {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
nullable_1_test_Int(1) == 1
|
nullable_1_test_Int(1) == 1
|
||||||
nullable_1_test_2_Int(4) == 5
|
nullable_1_test_2_Int(4) == 5
|
||||||
nullable_1_test_2_npe_operator_Int(23) == 578
|
nullable_1_test_2_npe_operator_Int(23) == 578
|
||||||
|
nullable_1_test_null_return() == 11
|
||||||
|
|||||||
@@ -18,4 +18,13 @@ fun nullable_1_test_2_npe_operator(i: Int): Int {
|
|||||||
val x: nullable_1_MyAwesomeClass? = nullable_1_MyAwesomeClass(i)
|
val x: nullable_1_MyAwesomeClass? = nullable_1_MyAwesomeClass(i)
|
||||||
x!!
|
x!!
|
||||||
return x.i + 555
|
return x.i + 555
|
||||||
|
}
|
||||||
|
|
||||||
|
fun nullable_1_test_null_return_slave():nullable_1_MyAwesomeClass?{
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun nullable_1_test_null_return():Int{
|
||||||
|
return 11
|
||||||
|
//return if (nullable_1_test_null_return_slave() == null) 11 else -24
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user