Improve implicit widening conversion to unsigned integer
This commit is contained in:
committed by
SvyatoslavScherbina
parent
62bbfcebd8
commit
872deb205c
+2
-5
@@ -1272,8 +1272,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
private fun evaluateIntegerCoercion(value: IrTypeOperatorCall): LLVMValueRef {
|
private fun evaluateIntegerCoercion(value: IrTypeOperatorCall): LLVMValueRef {
|
||||||
context.log{"evaluateIntegerCoercion : ${ir2string(value)}"}
|
context.log{"evaluateIntegerCoercion : ${ir2string(value)}"}
|
||||||
val type = value.typeOperand
|
val type = value.typeOperand
|
||||||
val typeIsUnsigned = type.isUnsignedInteger()
|
assert(type.isPrimitiveInteger() || type.isUnsignedInteger())
|
||||||
assert(type.isPrimitiveInteger() || typeIsUnsigned)
|
|
||||||
val result = evaluateExpression(value.argument)
|
val result = evaluateExpression(value.argument)
|
||||||
assert(value.argument.type.isInt())
|
assert(value.argument.type.isInt())
|
||||||
val llvmSrcType = codegen.getLLVMType(value.argument.type)
|
val llvmSrcType = codegen.getLLVMType(value.argument.type)
|
||||||
@@ -1283,9 +1282,7 @@ internal class CodeGeneratorVisitor(val context: Context, val lifetimes: Map<IrE
|
|||||||
return when {
|
return when {
|
||||||
srcWidth == dstWidth -> result
|
srcWidth == dstWidth -> result
|
||||||
srcWidth > dstWidth -> LLVMBuildTrunc(functionGenerationContext.builder, result, llvmDstType, "")!!
|
srcWidth > dstWidth -> LLVMBuildTrunc(functionGenerationContext.builder, result, llvmDstType, "")!!
|
||||||
/* srcWidth < dstWidth */
|
else /* srcWidth < dstWidth */ -> LLVMBuildSExt(functionGenerationContext.builder, result, llvmDstType, "")!!
|
||||||
typeIsUnsigned -> LLVMBuildZExt(functionGenerationContext.builder, result, llvmDstType, "")!!
|
|
||||||
else -> LLVMBuildSExt(functionGenerationContext.builder, result, llvmDstType, "")!!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user