@@ -3780,21 +3780,40 @@ class Traverser(
37803780 private fun TraversalContext.intOverflowCheck (op : BinopExpr , leftRaw : PrimitiveValue , rightRaw : PrimitiveValue ) {
37813781 // cast to the bigger type
37823782 val sort = simpleMaxSort(leftRaw, rightRaw) as UtPrimitiveSort
3783- val left = leftRaw.expr.toPrimitiveValue(sort.type)
3784- val right = rightRaw.expr.toPrimitiveValue(sort.type)
3783+ val left = UtCastExpression (leftRaw, sort.type)
3784+ val right = UtCastExpression (rightRaw, sort.type)
3785+
3786+ val leftPrimValue = left.toPrimitiveValue(left.type)
3787+ val rightPrimValue = right.toPrimitiveValue(right.type)
37853788
37863789 val overflow = when (op) {
3787- is JAddExpr -> {
3788- mkNot(UtAddNoOverflowExpression (left.expr, right.expr))
3789- }
3790- is JSubExpr -> {
3791- mkNot(UtSubNoOverflowExpression (left.expr, right.expr))
3792- }
3790+ is JAddExpr -> mkNot(UtAddNoOverflowExpression (left, right))
3791+ is JSubExpr -> mkNot(UtSubNoOverflowExpression (left, right))
37933792 is JMulExpr -> when (sort.type) {
3794- is ByteType -> lowerIntMulOverflowCheck(left, right, Byte .MIN_VALUE .toInt(), Byte .MAX_VALUE .toInt())
3795- is ShortType -> lowerIntMulOverflowCheck(left, right, Short .MIN_VALUE .toInt(), Short .MAX_VALUE .toInt())
3796- is IntType -> higherIntMulOverflowCheck(left, right, Int .SIZE_BITS , Int .MIN_VALUE .toLong()) { it: UtExpression -> it.toIntValue() }
3797- is LongType -> higherIntMulOverflowCheck(left, right, Long .SIZE_BITS , Long .MIN_VALUE ) { it: UtExpression -> it.toLongValue() }
3793+ is ByteType -> lowerIntMulOverflowCheck(
3794+ leftPrimValue,
3795+ rightPrimValue,
3796+ Byte .MIN_VALUE .toInt(),
3797+ Byte .MAX_VALUE .toInt()
3798+ )
3799+ is ShortType -> lowerIntMulOverflowCheck(
3800+ leftPrimValue,
3801+ rightPrimValue,
3802+ Short .MIN_VALUE .toInt(),
3803+ Short .MAX_VALUE .toInt()
3804+ )
3805+ is IntType -> higherIntMulOverflowCheck(
3806+ leftPrimValue,
3807+ rightPrimValue,
3808+ Int .SIZE_BITS ,
3809+ Int .MIN_VALUE .toLong()
3810+ ) { it: UtExpression -> it.toIntValue() }
3811+ is LongType -> higherIntMulOverflowCheck(
3812+ leftPrimValue,
3813+ rightPrimValue,
3814+ Long .SIZE_BITS ,
3815+ Long .MIN_VALUE
3816+ ) { it: UtExpression -> it.toLongValue() }
37983817 else -> null
37993818 }
38003819 else -> null
0 commit comments