Merge remote-tracking branch 'origin/GP-6957_caheckman_RelBranchToNextInst'

This commit is contained in:
Ryan Kurtz
2026-06-17 10:50:26 -04:00
3 changed files with 21 additions and 5 deletions

View File

@@ -159,11 +159,10 @@ PcodeOp *FlowInfo::findRelTarget(PcodeOp *op,Address &res) const
if (retop != (PcodeOp *)0) // Is this a "properly" internal branch
return retop;
// Now we check if the relative branch is really to the next instruction
SeqNum seqnum1(op->getAddr(),id-1);
retop = obank.findOp(seqnum1); // We go back one sequence number
if (retop != (PcodeOp *)0) {
// If the PcodeOp exists here then branch was indeed to next instruction
// Check if the relative branch is to the next instruction
retop = obank.findLastOp(op->getAddr()); // Find the last op at this address
if (retop != (PcodeOp *)0 && retop->getTime() < id) {
// Branch is beyond the last op. Treat as branch to next instruction.
map<Address,VisitStat>::const_iterator miter;
miter = visited.upper_bound(retop->getAddr());
if (miter != visited.begin()) {

View File

@@ -1134,6 +1134,22 @@ PcodeOp *PcodeOpBank::findOp(const SeqNum &num) const
return (*iter).second;
}
/// If PcodeOps exist at the address, the one with the biggest getTime() is returned.
/// \param addr is the given address
/// \return the last PcodeOp at the address (or NULL)
PcodeOp *PcodeOpBank::findLastOp(const Address &addr) const
{
PcodeOpTree::const_iterator iter = optree.upper_bound(SeqNum(addr,~((uintm)0)));
if (iter != optree.begin()) {
--iter;
PcodeOp *op = (*iter).second;
if (op->getAddr() == addr)
return op;
}
return (PcodeOp *)0;
}
/// The term \e fallthru in this context refers to p-code \e not assembly instructions.
/// \param op is the given PcodeOp
/// \return the fallthru PcodeOp

View File

@@ -321,6 +321,7 @@ public:
bool empty(void) const { return optree.empty(); } ///< Return \b true if there are no PcodeOps in \b this container
PcodeOp *target(const Address &addr) const; ///< Find the first executing PcodeOp for a target address
PcodeOp *findOp(const SeqNum &num) const; ///< Find a PcodeOp by sequence number
PcodeOp *findLastOp(const Address &addr) const; ///< Find the last PcodeOp in sequence for the given address
PcodeOp *fallthru(const PcodeOp *op) const; ///< Find the PcodeOp considered a \e fallthru of the given PcodeOp
/// \brief Start of all PcodeOps in sequence number order