integer promotion checks for right shift, division, remainder

This commit is contained in:
caheckman 2020-03-02 12:32:46 -05:00
parent cf4a4e825e
commit 037745b823

View file

@ -1161,8 +1161,12 @@ Datatype *TypeOpIntRight::getInputCast(const PcodeOp *op,int4 slot,const CastStr
{ {
if (slot == 0) { if (slot == 0) {
const Varnode *vn = op->getIn(0);
Datatype *reqtype = op->inputTypeLocal(slot); Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType(); Datatype *curtype = vn->getHigh()->getType();
int4 promoType = castStrategy->intPromotionType(vn);
if (promoType != CastStrategy::NO_PROMOTION && ((promoType & CastStrategy::UNSIGNED_EXTENSION)==0))
return reqtype;
return castStrategy->castStandard(reqtype,curtype,true,true); return castStrategy->castStandard(reqtype,curtype,true,true);
} }
return TypeOpBinary::getInputCast(op,slot,castStrategy); return TypeOpBinary::getInputCast(op,slot,castStrategy);
@ -1199,8 +1203,12 @@ Datatype *TypeOpIntSright::getInputCast(const PcodeOp *op,int4 slot,const CastSt
{ {
if (slot == 0) { if (slot == 0) {
const Varnode *vn = op->getIn(0);
Datatype *reqtype = op->inputTypeLocal(slot); Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType(); Datatype *curtype = vn->getHigh()->getType();
int4 promoType = castStrategy->intPromotionType(vn);
if (promoType != CastStrategy::NO_PROMOTION && ((promoType & CastStrategy::SIGNED_EXTENSION)==0))
return reqtype;
return castStrategy->castStandard(reqtype,curtype,true,true); return castStrategy->castStandard(reqtype,curtype,true,true);
} }
return TypeOpBinary::getInputCast(op,slot,castStrategy); return TypeOpBinary::getInputCast(op,slot,castStrategy);
@ -1248,8 +1256,12 @@ TypeOpIntDiv::TypeOpIntDiv(TypeFactory *t)
Datatype *TypeOpIntDiv::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const Datatype *TypeOpIntDiv::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const
{ {
const Varnode *vn = op->getIn(slot);
Datatype *reqtype = op->inputTypeLocal(slot); Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType(); Datatype *curtype = vn->getHigh()->getType();
int4 promoType = castStrategy->intPromotionType(vn);
if (promoType != CastStrategy::NO_PROMOTION && ((promoType & CastStrategy::UNSIGNED_EXTENSION)==0))
return reqtype;
return castStrategy->castStandard(reqtype,curtype,true,true); return castStrategy->castStandard(reqtype,curtype,true,true);
} }
@ -1264,8 +1276,12 @@ TypeOpIntSdiv::TypeOpIntSdiv(TypeFactory *t)
Datatype *TypeOpIntSdiv::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const Datatype *TypeOpIntSdiv::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const
{ {
const Varnode *vn = op->getIn(slot);
Datatype *reqtype = op->inputTypeLocal(slot); Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType(); Datatype *curtype = vn->getHigh()->getType();
int4 promoType = castStrategy->intPromotionType(vn);
if (promoType != CastStrategy::NO_PROMOTION && ((promoType & CastStrategy::SIGNED_EXTENSION)==0))
return reqtype;
return castStrategy->castStandard(reqtype,curtype,true,true); return castStrategy->castStandard(reqtype,curtype,true,true);
} }
@ -1280,13 +1296,14 @@ TypeOpIntRem::TypeOpIntRem(TypeFactory *t)
Datatype *TypeOpIntRem::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const Datatype *TypeOpIntRem::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const
{ {
if (slot == 0) { const Varnode *vn = op->getIn(slot);
Datatype *reqtype = op->inputTypeLocal(slot); Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType(); Datatype *curtype = vn->getHigh()->getType();
int4 promoType = castStrategy->intPromotionType(vn);
if (promoType != CastStrategy::NO_PROMOTION && ((promoType & CastStrategy::UNSIGNED_EXTENSION)==0))
return reqtype;
return castStrategy->castStandard(reqtype,curtype,true,true); return castStrategy->castStandard(reqtype,curtype,true,true);
} }
return TypeOpBinary::getInputCast(op,slot,castStrategy);
}
TypeOpIntSrem::TypeOpIntSrem(TypeFactory *t) TypeOpIntSrem::TypeOpIntSrem(TypeFactory *t)
: TypeOpBinary(t,CPUI_INT_SREM,"%",TYPE_INT,TYPE_INT) : TypeOpBinary(t,CPUI_INT_SREM,"%",TYPE_INT,TYPE_INT)
@ -1299,13 +1316,14 @@ TypeOpIntSrem::TypeOpIntSrem(TypeFactory *t)
Datatype *TypeOpIntSrem::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const Datatype *TypeOpIntSrem::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const
{ {
if (slot == 0) { const Varnode *vn = op->getIn(slot);
Datatype *reqtype = op->inputTypeLocal(slot); Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType(); Datatype *curtype = vn->getHigh()->getType();
int4 promoType = castStrategy->intPromotionType(vn);
if (promoType != CastStrategy::NO_PROMOTION && ((promoType & CastStrategy::SIGNED_EXTENSION)==0))
return reqtype;
return castStrategy->castStandard(reqtype,curtype,true,true); return castStrategy->castStandard(reqtype,curtype,true,true);
} }
return TypeOpBinary::getInputCast(op,slot,castStrategy);
}
TypeOpBoolNegate::TypeOpBoolNegate(TypeFactory *t) TypeOpBoolNegate::TypeOpBoolNegate(TypeFactory *t)
: TypeOpUnary(t,CPUI_BOOL_NEGATE,"!",TYPE_BOOL,TYPE_BOOL) : TypeOpUnary(t,CPUI_BOOL_NEGATE,"!",TYPE_BOOL,TYPE_BOOL)