diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index abcbc9e6f..9e79fb1db 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -303,7 +303,7 @@ bool SVFIRBuilder::computeGepOffset(const User *V, AccessPath& ap) continue; APOffset idx = op->getSExtValue(); u32_t offset = pag->getSymbolInfo()->getFlattenedElemIdx(LLVMModuleSet::getLLVMModuleSet()->getSVFType(arrTy), idx); - ap.setFldIdx(ap.getConstantFieldIdx() + offset); + ap.setFldIdx(ap.getConstantStructFldIdx() + offset); } else if (const StructType *ST = SVFUtil::dyn_cast(gepTy)) { @@ -311,7 +311,7 @@ bool SVFIRBuilder::computeGepOffset(const User *V, AccessPath& ap) //The actual index APOffset idx = op->getSExtValue(); u32_t offset = pag->getSymbolInfo()->getFlattenedElemIdx(LLVMModuleSet::getLLVMModuleSet()->getSVFType(ST), idx); - ap.setFldIdx(ap.getConstantFieldIdx() + offset); + ap.setFldIdx(ap.getConstantStructFldIdx() + offset); } else if (gepTy->isSingleValueType()) { diff --git a/svf-llvm/lib/SVFIRExtAPI.cpp b/svf-llvm/lib/SVFIRExtAPI.cpp index b924180c3..c4258aeff 100644 --- a/svf-llvm/lib/SVFIRExtAPI.cpp +++ b/svf-llvm/lib/SVFIRExtAPI.cpp @@ -112,9 +112,9 @@ void SVFIRBuilder::addComplexConsForExt(Value *D, Value *S, const Value* szValue { LLVMModuleSet* llvmmodule = LLVMModuleSet::getLLVMModuleSet(); const SVFType* dElementType = pag->getSymbolInfo()->getFlatternedElemType(llvmmodule->getSVFType(dtype), - fields[index].getConstantFieldIdx()); + fields[index].getConstantStructFldIdx()); const SVFType* sElementType = pag->getSymbolInfo()->getFlatternedElemType(llvmmodule->getSVFType(stype), - fields[index].getConstantFieldIdx()); + fields[index].getConstantStructFldIdx()); NodeID dField = getGepValVar(D,fields[index],dElementType); NodeID sField = getGepValVar(S,fields[index],sElementType); NodeID dummy = pag->addDummyValNode(); @@ -180,7 +180,8 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle for (u32_t index = 0; index < sz; index++) { LLVMModuleSet* llvmmodule = LLVMModuleSet::getLLVMModuleSet(); - const SVFType* dElementType = pag->getSymbolInfo()->getFlatternedElemType(llvmmodule->getSVFType(dtype), dstFields[index].getConstantFieldIdx()); + const SVFType* dElementType = pag->getSymbolInfo()->getFlatternedElemType(llvmmodule->getSVFType(dtype), + dstFields[index].getConstantStructFldIdx()); NodeID dField = getGepValVar(cs->getArgOperand(0), dstFields[index], dElementType); addStoreEdge(getValueNode(cs->getArgOperand(1)),dField); } @@ -233,7 +234,8 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle // We have vArg3 points to the entry of _Rb_tree_node_base { color; parent; left; right; }. // Now we calculate the offset from base to vArg3 NodeID vnArg3 = pag->getValueNode(svfCall->getArgOperand(3)); - APOffset offset = getAccessPathFromBaseNode(vnArg3).getConstantFieldIdx(); + APOffset offset = + getAccessPathFromBaseNode(vnArg3).getConstantStructFldIdx(); // We get all flattened fields of base vector fields = pag->getTypeLocSetsMap(vnArg3).second; @@ -245,7 +247,7 @@ void SVFIRBuilder::handleExtCall(const CallBase* cs, const SVFFunction* svfCalle if((u32_t)i >= fields.size()) break; const SVFType* elementType = pag->getSymbolInfo()->getFlatternedElemType(pag->getTypeLocSetsMap(vnArg3).first, - fields[i].getConstantFieldIdx()); + fields[i].getConstantStructFldIdx()); NodeID vnD = getGepValVar(cs->getArgOperand(3), fields[i], elementType); NodeID vnS = pag->getValueNode(svfCall->getArgOperand(1)); if(vnD && vnS) diff --git a/svf/include/Graphs/ConsGEdge.h b/svf/include/Graphs/ConsGEdge.h index 91fed6a1f..23db2abec 100644 --- a/svf/include/Graphs/ConsGEdge.h +++ b/svf/include/Graphs/ConsGEdge.h @@ -308,7 +308,7 @@ class NormalGepCGEdge : public GepCGEdge /// Get location set of the gep edge inline APOffset getConstantFieldIdx() const { - return ap.getConstantFieldIdx(); + return ap.getConstantStructFldIdx(); } }; diff --git a/svf/include/MemoryModel/AccessPath.h b/svf/include/MemoryModel/AccessPath.h index 5f2d4d0a8..b2b632ad2 100644 --- a/svf/include/MemoryModel/AccessPath.h +++ b/svf/include/MemoryModel/AccessPath.h @@ -95,7 +95,7 @@ class AccessPath /// Get methods //@{ - inline APOffset getConstantFieldIdx() const + inline APOffset getConstantStructFldIdx() const { return fldIdx; } @@ -177,7 +177,7 @@ template <> struct std::hash { SVF::Hash> h; std::hash v; - return h(std::make_pair(ap.getConstantFieldIdx(), + return h(std::make_pair(ap.getConstantStructFldIdx(), v(ap.getIdxOperandPairVec()))); } }; diff --git a/svf/include/SVFIR/SVFStatements.h b/svf/include/SVFIR/SVFStatements.h index 501b42aaa..d8b8152ed 100644 --- a/svf/include/SVFIR/SVFStatements.h +++ b/svf/include/SVFIR/SVFStatements.h @@ -517,10 +517,10 @@ class GepStmt: public AssignStmt return getAccessPath().computeConstantOffset(); } /// Field index of the gep statement if it access the field of a struct - inline APOffset getConstantFieldIdx() const + inline APOffset getConstantStructFldIdx() const { assert(isVariantFieldGep()==false && "Can't retrieve the AccessPath if using a variable field index (pointer arithmetic) for struct field access "); - return getAccessPath().getConstantFieldIdx(); + return getAccessPath().getConstantStructFldIdx(); } /// Gep statement with a variant field index (pointer arithmetic) for struct field access inline bool isVariantFieldGep() const diff --git a/svf/include/SVFIR/SVFVariables.h b/svf/include/SVFIR/SVFVariables.h index 8a70c5be7..d209e5a6a 100644 --- a/svf/include/SVFIR/SVFVariables.h +++ b/svf/include/SVFIR/SVFVariables.h @@ -420,7 +420,7 @@ class GepValVar: public ValVar /// offset of the base value variable inline APOffset getConstantFieldIdx() const { - return ap.getConstantFieldIdx(); + return ap.getConstantStructFldIdx(); } /// Return name of a LLVM value diff --git a/svf/lib/AbstractExecution/SVFIR2ConsExeState.cpp b/svf/lib/AbstractExecution/SVFIR2ConsExeState.cpp index 36e9ea067..38436f9ed 100644 --- a/svf/lib/AbstractExecution/SVFIR2ConsExeState.cpp +++ b/svf/lib/AbstractExecution/SVFIR2ConsExeState.cpp @@ -609,7 +609,8 @@ std::pair SVFIR2ConsExeState::getGepOffset(const SVF::GepStmt *gep { /// for instant constant index, e.g. gep arr, 1 if (gep->getOffsetVarAndGepTypePairVec().empty()) - return std::make_pair(gep->getConstantFieldIdx(), gep->getConstantFieldIdx()); + return std::make_pair(gep->getConstantStructFldIdx(), + gep->getConstantStructFldIdx()); s32_t totalOffset = 0; /// default value of MaxFieldLimit is 512 diff --git a/svf/lib/AbstractExecution/SVFIR2ItvExeState.cpp b/svf/lib/AbstractExecution/SVFIR2ItvExeState.cpp index beab30211..64f5dfdf2 100644 --- a/svf/lib/AbstractExecution/SVFIR2ItvExeState.cpp +++ b/svf/lib/AbstractExecution/SVFIR2ItvExeState.cpp @@ -266,6 +266,8 @@ SVFIR2ItvExeState::Addrs SVFIR2ItvExeState::getGepObjAddress(u32_t pointer, APOf */ IntervalValue SVFIR2ItvExeState::getByteOffset(const GepStmt *gep) { + if (gep->isConstantOffset()) + return IntervalValue((s64_t)gep->accumulateConstantByteOffset()); IntervalValue res(0); // Initialize the result interval 'res' to 0. // Loop through the offsetVarAndGepTypePairVec in reverse order. for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--) @@ -337,6 +339,8 @@ IntervalValue SVFIR2ItvExeState::getByteOffset(const GepStmt *gep) */ IntervalValue SVFIR2ItvExeState::getItvOfFlattenedElemIndex(const GepStmt *gep) { + if (gep->isConstantOffset()) + return IntervalValue((s64_t)gep->accumulateConstantOffset()); IntervalValue res(0); for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--) { diff --git a/svf/lib/DDA/ContextDDA.cpp b/svf/lib/DDA/ContextDDA.cpp index 99ee23c3f..c67bfa2c8 100644 --- a/svf/lib/DDA/ContextDDA.cpp +++ b/svf/lib/DDA/ContextDDA.cpp @@ -171,7 +171,8 @@ CxtPtSet ContextDDA::processGepPts(const GepSVFGNode* gep, const CxtPtSet& srcPt } else { - CxtVar var(ptd.get_cond(),getGepObjVar(ptd.get_id(),gepStmt->getAccessPath().getConstantFieldIdx())); + CxtVar var(ptd.get_cond(),getGepObjVar(ptd.get_id(), + gepStmt->getAccessPath().getConstantStructFldIdx())); tmpDstPts.set(var); } } diff --git a/svf/lib/DDA/FlowDDA.cpp b/svf/lib/DDA/FlowDDA.cpp index bbf41619d..bf22a1793 100644 --- a/svf/lib/DDA/FlowDDA.cpp +++ b/svf/lib/DDA/FlowDDA.cpp @@ -156,7 +156,7 @@ PointsTo FlowDDA::processGepPts(const GepSVFGNode* gep, const PointsTo& srcPts) } else { - NodeID fieldSrcPtdNode = getGepObjVar(ptd, gepStmt->getAccessPath().getConstantFieldIdx()); + NodeID fieldSrcPtdNode = getGepObjVar(ptd, gepStmt->getAccessPath().getConstantStructFldIdx()); tmpDstPts.set(fieldSrcPtdNode); } } diff --git a/svf/lib/MemoryModel/AccessPath.cpp b/svf/lib/MemoryModel/AccessPath.cpp index 3c5f8d4f3..c20776250 100644 --- a/svf/lib/MemoryModel/AccessPath.cpp +++ b/svf/lib/MemoryModel/AccessPath.cpp @@ -210,7 +210,7 @@ APOffset AccessPath::computeConstantOffset() const assert(isConstantOffset() && "not a constant offset"); if(idxOperandPairs.empty()) - return getConstantFieldIdx(); + return getConstantStructFldIdx(); APOffset totalConstOffset = 0; for(int i = idxOperandPairs.size() - 1; i >= 0; i--) @@ -249,14 +249,14 @@ APOffset AccessPath::computeConstantOffset() const NodeBS AccessPath::computeAllLocations() const { NodeBS result; - result.set(getConstantFieldIdx()); + result.set(getConstantStructFldIdx()); return result; } AccessPath AccessPath::operator+(const AccessPath& rhs) const { AccessPath ap(rhs); - ap.fldIdx += getConstantFieldIdx(); + ap.fldIdx += getConstantStructFldIdx(); for (auto &p : ap.getIdxOperandPairVec()) ap.addOffsetVarAndGepTypePair(p.first, p.second); @@ -314,7 +314,7 @@ std::string AccessPath::dump() const std::string str; std::stringstream rawstr(str); - rawstr << "AccessPath\tField_Index: " << getConstantFieldIdx(); + rawstr << "AccessPath\tField_Index: " << getConstantStructFldIdx(); rawstr << ",\tNum-Stride: {"; const IdxOperandPairs& vec = getIdxOperandPairVec(); IdxOperandPairs::const_iterator it = vec.begin(); diff --git a/svf/lib/SVFIR/SVFIR.cpp b/svf/lib/SVFIR/SVFIR.cpp index 09700e54a..fb8a0e83d 100644 --- a/svf/lib/SVFIR/SVFIR.cpp +++ b/svf/lib/SVFIR/SVFIR.cpp @@ -633,7 +633,7 @@ void SVFIR::print() outs() << (*iter)->getSrcID() << " -- VariantGep --> " << (*iter)->getDstID() << "\n"; else - outs() << gep->getRHSVarID() << " -- Gep (" << gep->getConstantFieldIdx() + outs() << gep->getRHSVarID() << " -- Gep (" << gep->getConstantStructFldIdx() << ") --> " << gep->getLHSVarID() << "\n"; } diff --git a/svf/lib/WPA/Andersen.cpp b/svf/lib/WPA/Andersen.cpp index 921e291f7..a22f19b78 100644 --- a/svf/lib/WPA/Andersen.cpp +++ b/svf/lib/WPA/Andersen.cpp @@ -457,7 +457,7 @@ bool Andersen::processGepPts(const PointsTo& pts, const GepCGEdge* edge) continue; } - NodeID fieldSrcPtdNode = consCG->getGepObjVar(o, normalGepEdge->getAccessPath().getConstantFieldIdx()); + NodeID fieldSrcPtdNode = consCG->getGepObjVar(o, normalGepEdge->getAccessPath().getConstantStructFldIdx()); tmpDstPts.set(fieldSrcPtdNode); } } diff --git a/svf/lib/WPA/FlowSensitive.cpp b/svf/lib/WPA/FlowSensitive.cpp index e9b4c9856..fa158645a 100644 --- a/svf/lib/WPA/FlowSensitive.cpp +++ b/svf/lib/WPA/FlowSensitive.cpp @@ -529,7 +529,7 @@ bool FlowSensitive::processGep(const GepSVFGNode* edge) continue; } - NodeID fieldSrcPtdNode = getGepObjVar(o, gepStmt->getAccessPath().getConstantFieldIdx()); + NodeID fieldSrcPtdNode = getGepObjVar(o, gepStmt->getAccessPath().getConstantStructFldIdx()); tmpDstPts.set(fieldSrcPtdNode); } }