Skip to content

Commit

Permalink
integer promotion checks for right shift, division, remainder
Browse files Browse the repository at this point in the history
  • Loading branch information
caheckman committed Mar 2, 2020
1 parent cf4a4e8 commit 037745b
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,12 @@ Datatype *TypeOpIntRight::getInputCast(const PcodeOp *op,int4 slot,const CastStr

{
if (slot == 0) {
const Varnode *vn = op->getIn(0);
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 TypeOpBinary::getInputCast(op,slot,castStrategy);
Expand Down Expand Up @@ -1199,8 +1203,12 @@ Datatype *TypeOpIntSright::getInputCast(const PcodeOp *op,int4 slot,const CastSt

{
if (slot == 0) {
const Varnode *vn = op->getIn(0);
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 TypeOpBinary::getInputCast(op,slot,castStrategy);
Expand Down Expand Up @@ -1248,8 +1256,12 @@ TypeOpIntDiv::TypeOpIntDiv(TypeFactory *t)
Datatype *TypeOpIntDiv::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const

{
const Varnode *vn = op->getIn(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);
}

Expand All @@ -1264,8 +1276,12 @@ TypeOpIntSdiv::TypeOpIntSdiv(TypeFactory *t)
Datatype *TypeOpIntSdiv::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const

{
const Varnode *vn = op->getIn(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);
}

Expand All @@ -1280,12 +1296,13 @@ TypeOpIntRem::TypeOpIntRem(TypeFactory *t)
Datatype *TypeOpIntRem::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const

{
if (slot == 0) {
Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType();
return castStrategy->castStandard(reqtype,curtype,true,true);
}
return TypeOpBinary::getInputCast(op,slot,castStrategy);
const Varnode *vn = op->getIn(slot);
Datatype *reqtype = op->inputTypeLocal(slot);
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);
}

TypeOpIntSrem::TypeOpIntSrem(TypeFactory *t)
Expand All @@ -1299,12 +1316,13 @@ TypeOpIntSrem::TypeOpIntSrem(TypeFactory *t)
Datatype *TypeOpIntSrem::getInputCast(const PcodeOp *op,int4 slot,const CastStrategy *castStrategy) const

{
if (slot == 0) {
Datatype *reqtype = op->inputTypeLocal(slot);
Datatype *curtype = op->getIn(slot)->getHigh()->getType();
return castStrategy->castStandard(reqtype,curtype,true,true);
}
return TypeOpBinary::getInputCast(op,slot,castStrategy);
const Varnode *vn = op->getIn(slot);
Datatype *reqtype = op->inputTypeLocal(slot);
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);
}

TypeOpBoolNegate::TypeOpBoolNegate(TypeFactory *t)
Expand Down

0 comments on commit 037745b

Please sign in to comment.