more robust treatment of arithmetic coercions

This commit is contained in:
Vern Paxson 2021-05-30 18:02:30 -07:00
parent e06d988bfd
commit 292bd1b671
3 changed files with 22 additions and 29 deletions

View file

@ -2075,8 +2075,13 @@ ExprPtr ArithCoerceExpr::Duplicate()
bool ArithCoerceExpr::WillTransform(Reducer* c) const
{
return op->Tag() == EXPR_CONST &&
IsArithmetic(op->AsConstExpr()->Value()->GetType()->Tag());
if ( op->Tag() != EXPR_CONST )
return false;
if ( IsArithmetic(GetType()->Tag()) )
return true;
return IsArithmetic(op->AsConstExpr()->Value()->GetType()->Tag());
}
ExprPtr ArithCoerceExpr::Reduce(Reducer* c, StmtPtr& red_stmt)
@ -2093,10 +2098,11 @@ ExprPtr ArithCoerceExpr::Reduce(Reducer* c, StmtPtr& red_stmt)
if ( op->Tag() == EXPR_CONST )
{
auto cv = op->AsConstExpr()->Value();
auto tag = cv->GetType()->Tag();
const auto& t = GetType();
auto cv = op->AsConstExpr()->ValuePtr();
const auto& ct = cv->GetType();
if ( IsArithmetic(tag) )
if ( IsArithmetic(t->Tag()) || IsArithmetic(ct->Tag()) )
return make_intrusive<ConstExpr>(FoldSingleVal(cv, t));
}