37 using namespace SVFUtil;
44 idxOperandPairs.emplace_back(var, gepIterType);
51 for(
auto it : idxOperandPairs)
53 if(SVFUtil::isa<SVFConstantInt>(it.first->getValue()) ==
false)
65 if (SVFUtil::isa<SVFArrayType, SVFStructType>(
type))
69 else if (
type->isPointerTy())
80 else if (
type->isSingleValueType() || SVFUtil::isa<SVFFunctionType>(
type))
87 assert(
false &&
"What other types for this gep?");
101 u32_t structByteOffset = 0;
102 if (
const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(idxValue))
104 for (
u32_t structField = 0; structField < (
u32_t) op->getSExtValue(); ++structField)
109 return structByteOffset;
113 assert(
false &&
"struct type can only pair with constant idx");
127 assert(isConstantOffset() &&
"not a constant offset");
130 for(
int i = idxOperandPairs.size() - 1; i >= 0; i--)
135 const SVFValue* value = idxOperandPairs[i].first->getValue();
146 assert(
type &&
"this GepStmt comes from ExternalAPI cannot call this api");
151 type2 = arrType->getTypeOfElement();
153 else if (SVFUtil::isa<SVFPointerType>(
type))
157 type2 = gepSrcPointeeType();
160 const SVFConstantInt* op = SVFUtil::dyn_cast<SVFConstantInt>(value);
169 u32_t flattenIdx = structType->getTypeInfo()->getFlattenedFieldIdxVec()[structField];
182 return totalConstOffset;
216 assert(isConstantOffset() &&
"not a constant offset");
222 if (idxOperandPairs.size() == 0)
223 return getConstantStructFldIdx();
224 for(
int i = idxOperandPairs.size() - 1; i >= 0; i--)
226 const SVFValue* value = idxOperandPairs[i].first->getValue();
228 const SVFConstantInt* op = SVFUtil::dyn_cast<SVFConstantInt>(value);
229 assert(op &&
"not a constant offset?");
236 if(SVFUtil::isa<SVFPointerType>(
type))
237 totalConstOffset += op->
getSExtValue() * getElementNum(gepPointeeType);
248 SVFUtil::errs() <<
"It is an overflow access, hence it is the last idx\n";
256 u32_t flattenOffset =
259 totalConstOffset += flattenOffset;
263 return totalConstOffset;
271 result.
set(getConstantStructFldIdx());
277 assert(gepPointeeType == rhs.
gepSrcPointeeType() &&
"source element type not match");
279 ap.
fldIdx += getConstantStructFldIdx();
289 return (fldIdx < rhs.
fldIdx);
294 if (pairVec.size() != rhsPairVec.size())
295 return (pairVec.size() < rhsPairVec.size());
298 IdxOperandPairs::const_iterator it = pairVec.begin();
299 IdxOperandPairs::const_iterator rhsIt = rhsPairVec.begin();
300 for (; it != pairVec.end() && rhsIt != rhsPairVec.end(); ++it, ++rhsIt)
302 return (*it) < (*rhsIt);
316 if (lhsLocations == rhsLocations)
318 else if (lhsLocations.
contains(rhsLocations))
320 else if (rhsLocations.
contains(lhsLocations))
335 std::stringstream rawstr(str);
337 rawstr <<
"AccessPath\tField_Index: " << getConstantStructFldIdx();
338 rawstr <<
",\tNum-Stride: {";
340 IdxOperandPairs::const_iterator it = vec.begin();
341 IdxOperandPairs::const_iterator eit = vec.end();
342 for (; it != eit; ++it)
344 const SVFType* ty = it->second;
345 rawstr <<
" (Svf var: " << it->first->
toString() <<
", Iter type: " << *ty <<
")";
std::vector< IdxOperandPair > IdxOperandPairs
u32_t getStructFieldOffset(const SVFVar *idxOperandVar, const SVFStructType *idxOperandType) const
Return byte offset from the beginning of the structure to the field where it is located for struct ty...
bool addOffsetVarAndGepTypePair(const SVFVar *var, const SVFType *gepIterType)
u32_t getElementNum(const SVFType *type) const
Return element number of a type.
bool isConstantOffset() const
Return TRUE if this is a constant location set.
APOffset computeConstantByteOffset() const
std::string dump() const
Dump location set.
const IdxOperandPairs & getIdxOperandPairVec() const
AccessPath operator+(const AccessPath &rhs) const
Overload operators.
NodeBS computeAllLocations() const
Compute all possible locations according to offset and number-stride pairs.
const SVFType * gepSrcPointeeType() const
LSRelation checkRelation(const AccessPath &LHS, const AccessPath &RHS)
Check relations of two location sets.
APOffset fldIdx
Accumulated Constant Offsets.
bool operator<(const AccessPath &rhs) const
APOffset computeConstantOffset() const
For example,.
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
s64_t getSExtValue() const
std::string toString() const
u32_t getByteSize() const
const SVFValue * getValue() const
Get/has methods of the components.
bool intersects(const SparseBitVector< ElementSize > *RHS) const
bool contains(const SparseBitVector< ElementSize > &RHS) const
const SVFType * getOriginalElemType(u32_t fldIdx) const
std::vector< u32_t > & getFlattenedElemIdxVec()
std::vector< u32_t > & getFlattenedFieldIdxVec()
u32_t getFlattenedElemIdx(const SVFType *T, u32_t origId)
Flattened element idx of an array or struct by considering stride.
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis.
const StInfo * getTypeInfo(const SVFType *T) const
Get struct info.
u32_t getNumOfFlattenElements(const SVFType *T)
Number of flattened elements of an array or struct.
std::ostream & errs()
Overwrite llvm::errs()
std::ostream & outs()
Overwrite llvm::outs()