Ghidra is a software reverse engineering (SRE) framework
integer promotion checks for right shift, division, remainder
caheckman037745b8230b
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.ccindex b67dc33eed..1db2c08607 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/typeop.cc@@ -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);@@ -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);@@ -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);}@@ -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);}@@ -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)@@ -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)