Merge remote-tracking branch 'origin/GP-2568_PtrsubZeroResolve'

(Closes #4508)
This commit is contained in:
Ryan Kurtz 2022-09-20 02:12:17 -04:00
commit 947de197d2
5 changed files with 26 additions and 38 deletions

View file

@ -2436,7 +2436,7 @@ int4 ActionSetCasts::castOutput(PcodeOp *op,Funcdata &data,CastStrategy *castStr
if (tokenct->needsResolution()) if (tokenct->needsResolution())
data.forceFacingType(tokenct, -1, newop, 0); data.forceFacingType(tokenct, -1, newop, 0);
if (outHighType->needsResolution()) if (outHighType->needsResolution())
data.inheritWriteResolution(outHighType, newop, op); data.inheritResolution(outHighType, newop, -1, op, -1); // Inherit write resolution
return 1; return 1;
} }
@ -2510,7 +2510,9 @@ int4 ActionSetCasts::castInput(PcodeOp *op,int4 slot,Funcdata &data,CastStrategy
} }
else if (testStructOffset0(vn, op, ct, castStrategy)) { else if (testStructOffset0(vn, op, ct, castStrategy)) {
// Insert a PTRSUB(vn,#0) instead of a CAST // Insert a PTRSUB(vn,#0) instead of a CAST
insertPtrsubZero(op, slot, ct, data); newop = insertPtrsubZero(op, slot, ct, data);
if (vn->getHigh()->getType()->needsResolution())
data.inheritResolution(vn->getHigh()->getType(),newop, 0, op, slot);
return 1; return 1;
} }
else if (tryResolutionAdjustment(op, slot, data)) { else if (tryResolutionAdjustment(op, slot, data)) {
@ -2531,7 +2533,7 @@ int4 ActionSetCasts::castInput(PcodeOp *op,int4 slot,Funcdata &data,CastStrategy
data.forceFacingType(ct, -1, newop, -1); data.forceFacingType(ct, -1, newop, -1);
} }
if (vn->getHigh()->getType()->needsResolution()) { if (vn->getHigh()->getType()->needsResolution()) {
data.inheritReadResolution(newop, 0, op, slot); data.inheritResolution(vn->getHigh()->getType(),newop, 0, op, slot);
} }
return 1; return 1;
} }

View file

@ -909,39 +909,22 @@ void Funcdata::forceFacingType(Datatype *parent,int4 fieldNum,PcodeOp *op,int4 s
setUnionField(parent, op, slot, resolve); setUnionField(parent, op, slot, resolve);
} }
/// \brief Copy a Varnode's read facing resolve to another PcodeOp /// \brief Copy a read/write facing resolution for a specific data-type from one PcodeOp to another
///
/// \param op is the new PcodeOp reading the Varnode
/// \param slot is the new read slot
/// \param oldOp is the PcodeOp to inherit the resolve from
/// \param oldSlot is the old read slot
void Funcdata::inheritReadResolution(const PcodeOp *op,int4 slot,PcodeOp *oldOp,int4 oldSlot)
{
Datatype *ct = op->getIn(slot)->getType();
if (!ct->needsResolution()) return;
map<ResolveEdge,ResolvedUnion>::const_iterator iter;
ResolveEdge edge(ct,oldOp,oldSlot);
iter = unionMap.find(edge);
if (iter == unionMap.end()) return;
setUnionField(ct,op,slot,(*iter).second);
}
/// \brief Copy any write facing for a specific data-type from one PcodeOp to another
/// ///
/// \param parent is the data-type that needs resolution /// \param parent is the data-type that needs resolution
/// \param op is the destination PcodeOp /// \param op is the new reading PcodeOp
/// \param oldOp is the source PcodeOp /// \param slot is the new slot (-1 for write, >=0 for read)
/// \return the resolution index that was copied or -1 if there was no resolution /// \param oldOp is the PcodeOp to inherit the resolution from
int4 Funcdata::inheritWriteResolution(Datatype *parent,const PcodeOp *op,PcodeOp *oldOp) /// \param oldSlot is the old slot (-1 for write, >=0 for read)
int4 Funcdata::inheritResolution(Datatype *parent,const PcodeOp *op,int4 slot,PcodeOp *oldOp,int4 oldSlot)
{ {
map<ResolveEdge,ResolvedUnion>::const_iterator iter; map<ResolveEdge,ResolvedUnion>::const_iterator iter;
ResolveEdge edge(parent,oldOp,-1); ResolveEdge edge(parent,oldOp,oldSlot);
iter = unionMap.find(edge); iter = unionMap.find(edge);
if (iter == unionMap.end()) if (iter == unionMap.end())
return -1; return -1;
setUnionField(parent,op,-1,(*iter).second); setUnionField(parent,op,slot,(*iter).second);
return (*iter).second.getFieldNum(); return (*iter).second.getFieldNum();
} }

View file

@ -506,8 +506,7 @@ public:
const ResolvedUnion *getUnionField(const Datatype *parent,const PcodeOp *op,int4 slot) const; const ResolvedUnion *getUnionField(const Datatype *parent,const PcodeOp *op,int4 slot) const;
bool setUnionField(const Datatype *parent,const PcodeOp *op,int4 slot,const ResolvedUnion &resolve); bool setUnionField(const Datatype *parent,const PcodeOp *op,int4 slot,const ResolvedUnion &resolve);
void forceFacingType(Datatype *parent,int4 fieldNum,PcodeOp *op,int4 slot); void forceFacingType(Datatype *parent,int4 fieldNum,PcodeOp *op,int4 slot);
void inheritReadResolution(const PcodeOp *op,int4 slot,PcodeOp *oldOp,int4 oldSlot); int4 inheritResolution(Datatype *parent,const PcodeOp *op,int4 slot,PcodeOp *oldOp,int4 oldSlot);
int4 inheritWriteResolution(Datatype *parent,const PcodeOp *op,PcodeOp *oldOp);
// Jumptable routines // Jumptable routines
JumpTable *linkJumpTable(PcodeOp *op); ///< Link jump-table with a given BRANCHIND JumpTable *linkJumpTable(PcodeOp *op); ///< Link jump-table with a given BRANCHIND

View file

@ -355,7 +355,7 @@ PcodeOp *Merge::allocateCopyTrim(Varnode *inVn,const Address &addr,PcodeOp *trim
Datatype *ct = inVn->getType(); Datatype *ct = inVn->getType();
if (ct->needsResolution()) { // If the data-type needs resolution if (ct->needsResolution()) { // If the data-type needs resolution
if (inVn->isWritten()) { if (inVn->isWritten()) {
int4 fieldNum = data.inheritWriteResolution(ct, copyOp, inVn->getDef()); int4 fieldNum = data.inheritResolution(ct, copyOp, -1, inVn->getDef(), -1);
data.forceFacingType(ct, fieldNum, copyOp, 0); data.forceFacingType(ct, fieldNum, copyOp, 0);
} }
else { else {
@ -575,7 +575,7 @@ void Merge::trimOpOutput(PcodeOp *op)
Datatype *ct = vn->getType(); Datatype *ct = vn->getType();
copyop = data.newOp(1,op->getAddr()); copyop = data.newOp(1,op->getAddr());
if (ct->needsResolution()) { if (ct->needsResolution()) {
int4 fieldNum = data.inheritWriteResolution(ct, copyop, op); int4 fieldNum = data.inheritResolution(ct, copyop, -1, op, -1);
data.forceFacingType(ct, fieldNum, copyop, 0); data.forceFacingType(ct, fieldNum, copyop, 0);
if (ct->getMetatype() == TYPE_PARTIALUNION) if (ct->getMetatype() == TYPE_PARTIALUNION)
ct = vn->getTypeDefFacing(); ct = vn->getTypeDefFacing();
@ -806,7 +806,7 @@ void Merge::mergeIndirect(PcodeOp *indop)
newop = allocateCopyTrim(invn0, indop->getAddr(), indop); newop = allocateCopyTrim(invn0, indop->getAddr(), indop);
SymbolEntry *entry = outvn->getSymbolEntry(); SymbolEntry *entry = outvn->getSymbolEntry();
if (entry != (SymbolEntry *)0 && entry->getSymbol()->getType()->needsResolution()) { if (entry != (SymbolEntry *)0 && entry->getSymbol()->getType()->needsResolution()) {
data.inheritWriteResolution(entry->getSymbol()->getType(), newop, indop); data.inheritResolution(entry->getSymbol()->getType(), newop, -1, indop, -1);
} }
data.opSetInput(indop,newop->getOut(),0); data.opSetInput(indop,newop->getOut(),0);
data.opInsertBefore(newop,indop); data.opInsertBefore(newop,indop);

View file

@ -6150,7 +6150,8 @@ void AddTreeState::buildTree(void)
// Create PTRADD portion of operation // Create PTRADD portion of operation
if (multNode != (Varnode *)0) { if (multNode != (Varnode *)0) {
newop = data.newOpBefore(baseOp,CPUI_PTRADD,ptr,multNode,data.newConstant(ptrsize,size)); newop = data.newOpBefore(baseOp,CPUI_PTRADD,ptr,multNode,data.newConstant(ptrsize,size));
data.inheritReadResolution(newop, 0, baseOp, baseSlot); if (ptr->getType()->needsResolution())
data.inheritResolution(ptr->getType(),newop, 0, baseOp, baseSlot);
multNode = newop->getOut(); multNode = newop->getOut();
} }
else else
@ -6159,7 +6160,8 @@ void AddTreeState::buildTree(void)
// Create PTRSUB portion of operation // Create PTRSUB portion of operation
if (isSubtype) { if (isSubtype) {
newop = data.newOpBefore(baseOp,CPUI_PTRSUB,multNode,data.newConstant(ptrsize,offset)); newop = data.newOpBefore(baseOp,CPUI_PTRSUB,multNode,data.newConstant(ptrsize,offset));
data.inheritReadResolution(newop, 0, baseOp, baseSlot); if (multNode->getType()->needsResolution())
data.inheritResolution(multNode->getType(),newop, 0, baseOp, baseSlot);
if (size != 0) if (size != 0)
newop->setStopTypePropagation(); newop->setStopTypePropagation();
multNode = newop->getOut(); multNode = newop->getOut();
@ -6334,7 +6336,8 @@ int4 RuleStructOffset0::applyOp(PcodeOp *op,Funcdata &data)
else else
return 0; return 0;
Datatype *ct = op->getIn(1)->getTypeReadFacing(op); Varnode *ptrVn = op->getIn(1);
Datatype *ct = ptrVn->getTypeReadFacing(op);
if (ct->getMetatype() != TYPE_PTR) return 0; if (ct->getMetatype() != TYPE_PTR) return 0;
Datatype *baseType = ((TypePointer *)ct)->getPtrTo(); Datatype *baseType = ((TypePointer *)ct)->getPtrTo();
uintb offset = 0; uintb offset = 0;
@ -6372,8 +6375,9 @@ int4 RuleStructOffset0::applyOp(PcodeOp *op,Funcdata &data)
else else
return 0; return 0;
PcodeOp *newop = data.newOpBefore(op,CPUI_PTRSUB,op->getIn(1),data.newConstant(op->getIn(1)->getSize(),0)); PcodeOp *newop = data.newOpBefore(op,CPUI_PTRSUB,ptrVn,data.newConstant(ptrVn->getSize(),0));
data.inheritReadResolution(newop, 0, op, 1); if (ptrVn->getType()->needsResolution())
data.inheritResolution(ptrVn->getType(),newop, 0, op, 1);
newop->setStopTypePropagation(); newop->setStopTypePropagation();
data.opSetInput(op,newop->getOut(),1); data.opSetInput(op,newop->getOut(),1);
return 1; return 1;