Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add source element type in accesspath #1269

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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