From a3365f2bf27fb87b7af5edc84db34f0b4603aefc Mon Sep 17 00:00:00 2001 From: bjjwwang Date: Wed, 11 Dec 2024 12:18:56 +1100 Subject: [PATCH] fix AE + Const AccessPath --- svf/include/SVFIR/SVFVariables.h | 11 +++++++++-- svf/lib/AE/Core/AbstractState.cpp | 11 +++++------ svf/lib/MemoryModel/AccessPath.cpp | 9 ++++----- svf/lib/SVFIR/SVFIR.cpp | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/svf/include/SVFIR/SVFVariables.h b/svf/include/SVFIR/SVFVariables.h index de3d807b9..b9ea09622 100644 --- a/svf/include/SVFIR/SVFVariables.h +++ b/svf/include/SVFIR/SVFVariables.h @@ -320,6 +320,7 @@ class GepValVar: public ValVar private: AccessPath ap; // AccessPath + NodeID base; // base node id const SVFType* gepValType; /// Constructor to create empty GeValVar (for SVFIRReader/deserialization) @@ -347,9 +348,9 @@ class GepValVar: public ValVar //@} /// Constructor - GepValVar(const SVFValue* val, NodeID i, const AccessPath& ap, + GepValVar(NodeID baseID, const SVFValue* val, NodeID i, const AccessPath& ap, const SVFType* ty) - : ValVar(val, i, GepValNode), ap(ap), gepValType(ty) + : ValVar(val, i, GepValNode), ap(ap), base(baseID), gepValType(ty) { } @@ -359,6 +360,12 @@ class GepValVar: public ValVar return ap.getConstantStructFldIdx(); } + /// Return the base object from which this GEP node came from. + inline NodeID getBaseNode(void) const + { + return base; + } + /// Return name of a LLVM value inline const std::string getValueName() const { diff --git a/svf/lib/AE/Core/AbstractState.cpp b/svf/lib/AE/Core/AbstractState.cpp index 3f947988e..fe9059234 100644 --- a/svf/lib/AE/Core/AbstractState.cpp +++ b/svf/lib/AE/Core/AbstractState.cpp @@ -233,7 +233,7 @@ IntervalValue AbstractState::getElementIndex(const GepStmt* gep) for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--) { AccessPath::IdxOperandPair IdxVarAndType = gep->getOffsetVarAndGepTypePairVec()[i]; - const SVFValue* value = gep->getOffsetVarAndGepTypePairVec()[i].first->getValue(); + const SVFVar* var = gep->getOffsetVarAndGepTypePairVec()[i].first; const SVFType* type = IdxVarAndType.second; // Variables to store the lower and upper bounds of the index value @@ -241,11 +241,11 @@ IntervalValue AbstractState::getElementIndex(const GepStmt* gep) s64_t idxUb; // Determine the lower and upper bounds based on whether the value is a constant - if (const SVFConstantInt* constInt = SVFUtil::dyn_cast(value)) + if (const ConstantIntValVar* constInt = SVFUtil::dyn_cast(var)) idxLb = idxUb = constInt->getSExtValue(); else { - IntervalValue idxItv = (*this)[PAG::getPAG()->getValueNode(value)].getInterval(); + IntervalValue idxItv = (*this)[var->getId()].getInterval(); if (idxItv.isBottom()) idxLb = idxUb = 0; else @@ -320,7 +320,7 @@ IntervalValue AbstractState::getByteOffset(const GepStmt* gep) else assert(false && "idxOperandType must be ArrType or PtrType"); - if (const SVFConstantInt* op = SVFUtil::dyn_cast(idxOperandVar->getValue())) + if (const ConstantIntValVar* op = SVFUtil::dyn_cast(idxOperandVar)) { // Calculate the lower bound (lb) of the interval value s64_t lb = (double)Options::MaxFieldLimit() / elemByteSize >= op->getSExtValue() @@ -330,8 +330,7 @@ IntervalValue AbstractState::getByteOffset(const GepStmt* gep) } else { - u32_t idx = PAG::getPAG()->getValueNode(idxOperandVar->getValue()); - IntervalValue idxVal = (*this)[idx].getInterval(); + IntervalValue idxVal = (*this)[idxOperandVar->getId()].getInterval(); if (idxVal.isBottom()) res = res + IntervalValue(0, 0); diff --git a/svf/lib/MemoryModel/AccessPath.cpp b/svf/lib/MemoryModel/AccessPath.cpp index 92b21868a..23c3dc934 100644 --- a/svf/lib/MemoryModel/AccessPath.cpp +++ b/svf/lib/MemoryModel/AccessPath.cpp @@ -50,7 +50,7 @@ bool AccessPath::isConstantOffset() const { for(auto it : idxOperandPairs) { - if(SVFUtil::isa(it.first->getValue()) == false) + if(SVFUtil::isa(it.first) == false) return false; } return true; @@ -97,9 +97,8 @@ u32_t AccessPath::getElementNum(const SVFType* type) const // then the return byte offset is 16 Bytes. u32_t AccessPath::getStructFieldOffset(const SVFVar* idxOperandVar, const SVFStructType* idxOperandType) const { - const SVFValue* idxValue = idxOperandVar->getValue(); u32_t structByteOffset = 0; - if (const SVFConstantInt *op = SVFUtil::dyn_cast(idxValue)) + if (const ConstantIntValVar *op = SVFUtil::dyn_cast(idxOperandVar)) { for (u32_t structField = 0; structField < (u32_t) op->getSExtValue(); ++structField) { @@ -132,7 +131,7 @@ APOffset AccessPath::computeConstantByteOffset() const /// For example, there is struct DEST{int a, char b[10], int c[5]} /// (1) %c = getelementptr inbounds %struct.DEST, %struct.DEST* %arr, i32 0, i32 2 // (2) %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %b, i64 0, i64 8 - const SVFValue* value = idxOperandPairs[i].first->getValue(); + const SVFVar* var = idxOperandPairs[i].first; /// for (1) offsetVarAndGepTypePairs.size() = 2 /// i = 0, type: %struct.DEST*, PtrType, op = 0 /// i = 1, type: %struct.DEST, StructType, op = 2 @@ -157,7 +156,7 @@ APOffset AccessPath::computeConstantByteOffset() const type2 = gepSrcPointeeType(); } - const SVFConstantInt* op = SVFUtil::dyn_cast(value); + const ConstantIntValVar* op = SVFUtil::dyn_cast(var); if (const SVFStructType* structType = SVFUtil::dyn_cast(type)) { /// for (1) structType: %struct.DEST diff --git a/svf/lib/SVFIR/SVFIR.cpp b/svf/lib/SVFIR/SVFIR.cpp index ae52cb87a..dd4a366f8 100644 --- a/svf/lib/SVFIR/SVFIR.cpp +++ b/svf/lib/SVFIR/SVFIR.cpp @@ -391,7 +391,7 @@ NodeID SVFIR::addGepValNode(const SVFValue* curInst,const SVFValue* gepVal, cons assert(0==GepValObjMap[curInst].count(std::make_pair(base, ap)) && "this node should not be created before"); GepValObjMap[curInst][std::make_pair(base, ap)] = i; - GepValVar *node = new GepValVar(gepVal, i, ap, type); + GepValVar *node = new GepValVar(base, gepVal, i, ap, type); return addValNode(gepVal, node, i); }