From fbe25f6e733af1649fd6ab6612e00cd26b3371dd Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Sat, 5 Feb 2022 22:15:59 -0800 Subject: [PATCH] prevent overflow from triggering error in debug compiler --- src/mapleall/maple_me/src/alias_class.cpp | 2 +- src/mapleall/maple_me/src/me_ivopts.cpp | 2 +- src/mapleall/maple_me/src/me_value_range_prop.cpp | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mapleall/maple_me/src/alias_class.cpp b/src/mapleall/maple_me/src/alias_class.cpp index f1680822ef..1fe468b8e9 100644 --- a/src/mapleall/maple_me/src/alias_class.cpp +++ b/src/mapleall/maple_me/src/alias_class.cpp @@ -379,7 +379,7 @@ AliasInfo AliasClass::CreateAliasElemsExpr(BaseNode &expr) { } else { ASSERT(expr.GetOpCode() == OP_add, "Wrong operation!"); } - OffsetType newOffset = aliasInfo.offset + constVal * bitsPerByte; + OffsetType newOffset = aliasInfo.offset + static_cast(constVal) * static_cast(bitsPerByte); return AliasInfo(aliasInfo.ae, 0, newOffset); } case OP_array: { diff --git a/src/mapleall/maple_me/src/me_ivopts.cpp b/src/mapleall/maple_me/src/me_ivopts.cpp index 70e21b36db..8b72fceb32 100644 --- a/src/mapleall/maple_me/src/me_ivopts.cpp +++ b/src/mapleall/maple_me/src/me_ivopts.cpp @@ -1456,7 +1456,7 @@ MeExpr *IVOptimizer::ComputeExtraExprOfBase(MeExpr &candBase, MeExpr &groupBase, for (auto &itCand : candMap) { auto itGroup = groupMap.find(itCand.first); if (itCand.first == kInvalidExprID) { - candConst = static_cast(itCand.second.second * ratio); + candConst = static_cast(itCand.second.second) * static_cast(ratio); groupConst = itGroup == groupMap.end() ? 0 : itGroup->second.second; continue; } diff --git a/src/mapleall/maple_me/src/me_value_range_prop.cpp b/src/mapleall/maple_me/src/me_value_range_prop.cpp index 8234be1e63..816d0fbe87 100755 --- a/src/mapleall/maple_me/src/me_value_range_prop.cpp +++ b/src/mapleall/maple_me/src/me_value_range_prop.cpp @@ -1653,7 +1653,11 @@ bool ValueRangePropagation::AddOrSubWithConstant( overflowOrUnderflow = OverflowOrUnderflow(primType, lhsConstant, rhsConstant); } else { CHECK_FATAL(op == OP_sub, "must be sub"); - overflowOrUnderflow = OverflowOrUnderflow(primType, lhsConstant, -rhsConstant); + if (rhsConstant == GetMinNumber(primType)) { + overflowOrUnderflow = true; + } else { + overflowOrUnderflow = OverflowOrUnderflow(primType, lhsConstant, -rhsConstant); + } } if (!overflowOrUnderflow) { res = (op == OP_add) ? (lhsConstant + rhsConstant) : (lhsConstant - rhsConstant); -- Gitee