From 22045d8394fe8136cb866ec123dbd980c9f098a5 Mon Sep 17 00:00:00 2001 From: bjjwwang Date: Wed, 11 Dec 2024 12:37:54 +1100 Subject: [PATCH] fix saber --- svf-llvm/include/SVF-LLVM/SVFIRBuilder.h | 2 +- svf/lib/MemoryModel/PointerAnalysis.cpp | 15 +++++++++++---- svf/lib/SABER/SaberCondAllocator.cpp | 20 ++++++++++++++------ svf/lib/SABER/SaberSVFGBuilder.cpp | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h index fe67316be..fc964a673 100644 --- a/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h +++ b/svf-llvm/include/SVF-LLVM/SVFIRBuilder.h @@ -272,7 +272,7 @@ class SVFIRBuilder: public llvm::InstVisitor { LLVMContext& cxt = llvmModuleSet()->getContext(); ConstantPointerNull* constNull = ConstantPointerNull::get(PointerType::getUnqual(cxt)); - NodeID nullPtr = pag->addValNode(llvmModuleSet()->getSVFValue(constNull),pag->getNullPtr(), nullptr); + NodeID nullPtr = pag->addConstantNullPtrValNode(llvmModuleSet()->getSVFValue(constNull),pag->getNullPtr(), nullptr); setCurrentLocation(constNull, nullptr); addBlackHoleAddrEdge(pag->getBlkPtr()); return nullPtr; diff --git a/svf/lib/MemoryModel/PointerAnalysis.cpp b/svf/lib/MemoryModel/PointerAnalysis.cpp index 3d292fba5..e8b3b1467 100644 --- a/svf/lib/MemoryModel/PointerAnalysis.cpp +++ b/svf/lib/MemoryModel/PointerAnalysis.cpp @@ -446,10 +446,17 @@ void PointerAnalysis::getVFnsFromPts(const CallICFGNode* cs, const PointsTo &tar const PAGNode *ptdnode = pag->getGNode(*it); if (ptdnode->hasValue()) { - if (const SVFGlobalValue *vtbl = SVFUtil::dyn_cast(ptdnode->getValue())) - { - if (chaVtbls.find(vtbl) != chaVtbls.end()) - vtbls.insert(vtbl); + // ptd is global obj var or ptd's base is global obj var + if (const GlobalValueObjVar *global_vtbl = SVFUtil::dyn_cast(ptdnode)) { + const SVFGlobalValue* globalValue = SVFUtil::dyn_cast(global_vtbl->getValue()); + if (chaVtbls.find(globalValue) != chaVtbls.end()) + vtbls.insert(globalValue); + } else if (const GepObjVar *gep_vtbl = SVFUtil::dyn_cast(ptdnode)) { + if (SVFUtil::isa(pag->getGNode(gep_vtbl->getBaseNode()))) { + const SVFGlobalValue* globalValue = SVFUtil::dyn_cast(gep_vtbl->getValue()); + if (chaVtbls.find(globalValue) != chaVtbls.end()) + vtbls.insert(globalValue); + } } } } diff --git a/svf/lib/SABER/SaberCondAllocator.cpp b/svf/lib/SABER/SaberCondAllocator.cpp index 082d7a52b..ef074ce90 100644 --- a/svf/lib/SABER/SaberCondAllocator.cpp +++ b/svf/lib/SABER/SaberCondAllocator.cpp @@ -399,9 +399,17 @@ bool SaberCondAllocator::isTestNotNullExpr(const ICFGNode* test) const bool SaberCondAllocator::isTestContainsNullAndTheValue(const CmpStmt *cmp) const { - const SVFValue* op0 = cmp->getOpVar(0)->getValue(); - const SVFValue* op1 = cmp->getOpVar(1)->getValue(); - if (SVFUtil::isa(op1)) + const SVFVar* op0 = cmp->getOpVar(0); + const SVFVar* op1 = cmp->getOpVar(1); + bool a = SVFUtil::dyn_cast(op0) || + SVFUtil::dyn_cast(op0); + bool b = SVFUtil::dyn_cast(op1) || + SVFUtil::dyn_cast(op1); + bool c = SVFUtil::dyn_cast(op0->getValue()); + bool d = SVFUtil::dyn_cast(op1->getValue()); + assert(a == c); + assert(b == d); + if (SVFUtil::isa(op1)) { Set inDirVal; inDirVal.insert(getCurEvalSVFGNode()->getValue()); @@ -409,9 +417,9 @@ bool SaberCondAllocator::isTestContainsNullAndTheValue(const CmpStmt *cmp) const { inDirVal.insert(it->getDstNode()->getValue()); } - return inDirVal.find(op0) != inDirVal.end(); + return inDirVal.find(op0->getValue()) != inDirVal.end(); } - else if (SVFUtil::isa(op0)) + else if (SVFUtil::isa(op0)) { Set inDirVal; inDirVal.insert(getCurEvalSVFGNode()->getValue()); @@ -419,7 +427,7 @@ bool SaberCondAllocator::isTestContainsNullAndTheValue(const CmpStmt *cmp) const { inDirVal.insert(it->getDstNode()->getValue()); } - return inDirVal.find(op1) != inDirVal.end(); + return inDirVal.find(op1->getValue()) != inDirVal.end(); } return false; } diff --git a/svf/lib/SABER/SaberSVFGBuilder.cpp b/svf/lib/SABER/SaberSVFGBuilder.cpp index f90d86e36..766f4616f 100644 --- a/svf/lib/SABER/SaberSVFGBuilder.cpp +++ b/svf/lib/SABER/SaberSVFGBuilder.cpp @@ -82,7 +82,7 @@ void SaberSVFGBuilder::collectGlobals(BVDataPTAImpl* pta) if(SVFUtil::isa(pag->getGNode(gepobj->getBaseNode()))) continue; } - if(pagNode->hasValue() && SVFUtil::isa(pagNode->getValue())) + if(pagNode->hasValue() && SVFUtil::isa(pagNode)) worklist.push_back(it->first); }