Skip to content

Commit

Permalink
Merge pull request #1269 from jumormt/12.4
Browse files Browse the repository at this point in the history
add source element type in accesspath
  • Loading branch information
yuleisui authored Dec 4, 2023
2 parents ff1c10a + 9f45edc commit 0ee2872
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ void SVFIRBuilder::processCE(const Value* val)
const Constant* opnd = gepce->getOperand(0);
// handle recursive constant express case (gep (bitcast (gep X 1)) 1)
processCE(opnd);
AccessPath ap;
auto &GEPOp = llvm::cast<llvm::GEPOperator>(*gepce);
Type *pType = GEPOp.getSourceElementType();
AccessPath ap(0, LLVMModuleSet::getLLVMModuleSet()->getSVFType(pType));
bool constGep = computeGepOffset(gepce, ap);
// must invoke pag methods here, otherwise it will be a dead recursion cycle
const SVFValue* cval = getCurrentValue();
Expand Down Expand Up @@ -710,7 +712,7 @@ void SVFIRBuilder::visitGetElementPtrInst(GetElementPtrInst &inst)

NodeID src = getValueNode(inst.getPointerOperand());

AccessPath ap;
AccessPath ap(0, LLVMModuleSet::getLLVMModuleSet()->getSVFType(inst.getSourceElementType()));
bool constGep = computeGepOffset(&inst, ap);
addGepEdge(src, dst, ap, constGep);
}
Expand Down
17 changes: 13 additions & 4 deletions svf/include/MemoryModel/AccessPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ class AccessPath
typedef std::vector<IdxOperandPair> IdxOperandPairs;

/// Constructor
AccessPath(APOffset o = 0) : fldIdx(o) {}
AccessPath(APOffset o = 0, const SVFType* srcTy = nullptr) : fldIdx(o), gepSourceElementType(srcTy) {}

/// Copy Constructor
AccessPath(const AccessPath& ap)
: fldIdx(ap.fldIdx),
idxOperandPairs(ap.getIdxOperandPairVec())
: fldIdx(ap.fldIdx),
idxOperandPairs(ap.getIdxOperandPairVec()),
gepSourceElementType(ap.getGepSourceElementType())
{
}

Expand All @@ -84,12 +85,13 @@ class AccessPath
{
fldIdx = rhs.fldIdx;
idxOperandPairs = rhs.getIdxOperandPairVec();
gepSourceElementType = rhs.gepSourceElementType;
return *this;
}
inline bool operator==(const AccessPath& rhs) const
{
return this->fldIdx == rhs.fldIdx &&
this->idxOperandPairs == rhs.idxOperandPairs;
this->idxOperandPairs == rhs.idxOperandPairs && this->gepSourceElementType == rhs.gepSourceElementType;
}
//@}

Expand All @@ -107,6 +109,10 @@ class AccessPath
{
return idxOperandPairs;
}
inline const SVFType* getGepSourceElementType() const
{
return gepSourceElementType;
}
//@}

/**
Expand Down Expand Up @@ -167,6 +173,9 @@ class AccessPath

APOffset fldIdx; ///< Accumulated Constant Offsets
IdxOperandPairs idxOperandPairs; ///< a vector of actual offset in the form of <SVF Var, iterator type>
const SVFType* gepSourceElementType; /// source element type in gep instruction,
/// e.g., %f1 = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %arrayidx, i32 0, i32 0
/// the source element type is %struct.MyStruct
};

} // End namespace SVF
Expand Down
4 changes: 3 additions & 1 deletion svf/lib/MemoryModel/AccessPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ APOffset AccessPath::computeConstantOffset() const

assert(isConstantOffset() && "not a constant offset");

if(idxOperandPairs.empty())
// source element type is struct
if(gepSourceElementType && gepSourceElementType->isStructTy())
return getConstantStructFldIdx();

APOffset totalConstOffset = 0;
Expand Down Expand Up @@ -255,6 +256,7 @@ NodeBS AccessPath::computeAllLocations() const

AccessPath AccessPath::operator+(const AccessPath& rhs) const
{
assert(gepSourceElementType == rhs.getGepSourceElementType() && "source element type not match");
AccessPath ap(rhs);
ap.fldIdx += getConstantStructFldIdx();
for (auto &p : ap.getIdxOperandPairVec())
Expand Down

0 comments on commit 0ee2872

Please sign in to comment.