From ec9e31483a698ebd861b7eb7f6413639a835e4db Mon Sep 17 00:00:00 2001 From: caheckman <48068198+caheckman@users.noreply.github.com> Date: Fri, 26 Apr 2019 15:34:11 -0400 Subject: [PATCH] Fine tuning test for redundant COPY pair --- .../Decompiler/src/decompile/cpp/merge.cc | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc index 2507e77eea..1720ad8aec 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/merge.cc @@ -938,32 +938,20 @@ bool Merge::checkCopyPair(HighVariable *high,PcodeOp *domOp,PcodeOp *subOp) FlowBlock *subBlock = subOp->getParent(); if (!domBlock->dominates(subBlock)) return false; - int4 domId = domBlock->getIndex(); - int4 subId = subBlock->getIndex(); + Cover range; + range.addDefPoint(domOp->getOut()); + range.addRefPoint(subOp,subOp->getIn(0)); + Varnode *inVn = domOp->getIn(0); + // Look for high Varnodes in the range for(int4 i=0;inumInstances();++i) { Varnode *vn = high->getInstance(i); if (!vn->isWritten()) continue; PcodeOp *op = vn->getDef(); - if (op == domOp) continue; - if (op == subOp) continue; - int4 index = op->getParent()->getIndex(); - if (index == domId) { // Assignment same block as domOp - if (op->getSeqNum().getOrder() > domOp->getSeqNum().getOrder()) - return false; + if (op->code() == CPUI_COPY) { // If the write is not a COPY + if (op->getIn(0) == inVn) continue; // from the same Varnode as domOp and subOp } - if (index == subId) { // Assignment same block as subOp - if (op->getSeqNum().getOrder() < subOp->getSeqNum().getOrder()) - return false; - } - } - // All cover blocks in between domOp and subOp must be empty - if (subBlock != domBlock) { - high->updateCover(); - subBlock = subBlock->getImmedDom(); // Don't need to check first block - while(subBlock != domBlock) { // Don't need to check last block - if (!high->wholecover.getCoverBlock(subBlock->getIndex()).empty()) - return false; - subBlock = subBlock->getImmedDom(); + if (range.contain(op, 1)) { // and if write is contained in range between domOp and subOp + return false; // it is intervening and subOp is not redundant } } return true;