Static Value-Flow Analysis
|
#include <AccessPath.h>
Public Types | |
enum | LSRelation { NonOverlap , Overlap , Subset , Superset , Same } |
typedef std::pair< const SVFVar *, const SVFType * > | IdxOperandPair |
typedef std::vector< IdxOperandPair > | IdxOperandPairs |
Private Member Functions | |
LSRelation | checkRelation (const AccessPath &LHS, const AccessPath &RHS) |
Check relations of two location sets. | |
NodeBS | computeAllLocations () const |
Compute all possible locations according to offset and number-stride pairs. | |
Private Attributes | |
APOffset | fldIdx |
Accumulated Constant Offsets. | |
IdxOperandPairs | idxOperandPairs |
a vector of actual offset in the form of <SVF Var, iterator type> | |
const SVFType * | gepPointeeType |
Friends | |
class | SymbolTableInfo |
class | SVFIRWriter |
class | SVFIRReader |
Definition at line 52 of file AccessPath.h.
Definition at line 64 of file AccessPath.h.
typedef std::vector<IdxOperandPair> SVF::AccessPath::IdxOperandPairs |
Definition at line 65 of file AccessPath.h.
Enumerator | |
---|---|
NonOverlap | |
Overlap | |
Subset | |
Superset | |
Same |
Definition at line 59 of file AccessPath.h.
|
inline |
Copy Constructor.
Definition at line 71 of file AccessPath.h.
|
inline |
Definition at line 78 of file AccessPath.h.
Add offset value to vector offsetVarAndGepTypePairs
Definition at line 42 of file AccessPath.cpp.
|
private |
Check relations of two location sets.
Definition at line 310 of file AccessPath.cpp.
|
private |
Compute all possible locations according to offset and number-stride pairs.
Compute all possible locations according to offset and number-stride pairs.
Definition at line 268 of file AccessPath.cpp.
APOffset AccessPath::computeConstantByteOffset | ( | ) | const |
Computes the total constant byte offset of an access path. This function iterates over the offset-variable-type pairs in reverse order, accumulating the total byte offset for constant offsets. For each pair, it retrieves the corresponding SVFValue and determines the type of offset (whether it's an array, pointer, or structure). If the offset corresponds to a structure, it further resolves the actual element type based on the offset value. It then multiplies the offset value by the size of the type to compute the byte offset. This is used to handle composite types where offsets are derived from the type's internal structure, such as arrays or structures with fields of various types and sizes. The function asserts that the access path must have a constant offset, and it is intended to be used when the offset is known to be constant at compile time.
Return accumulated constant offset
"value" is the offset variable (must be a constant) "type" is the location where we want to compute offset Given a vector and elem byte size: [(value1,type1), (value2,type2), (value3,type3)], bytesize totalConstByteOffset = ByteOffset(value1,type1) * ByteOffset(value2,type2) + ByteOffset(value3,type3) For a pointer type (e.g., t1 is PointerType), we will retrieve the pointee type and times the offset, i.e., getElementNum(t1) X off1
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
for (1) offsetVarAndGepTypePairs.size() = 2 i = 0, type: struct.DEST*, PtrType, op = 0 i = 1, type: struct.DEST, StructType, op = 2 for (2) offsetVarAndGepTypePairs.size() = 2 i = 0, type: [10 x i8]*, PtrType, op = 0 i = 1, type: [10 x i8], ArrType, op = 8
if offsetVarAndGepTypePairs[i].second is nullptr, it means GepStmt comes from external API, this GepStmt is assigned in SVFIRExtAPI.cpp at SVFIRBuilder::getBaseTypeAndFlattenedFields ls.addOffsetVarAndGepTypePair()
for (2) i = 1, arrType: [10 x i8], type2 = i8
for (1) i = 0, ptrType: struct.DEST*, type2: struct.DEST for (2) i = 0, ptrType: [10 x i8]*, type2 = [10 x i8]
for (1) structType: struct.DEST structField = 0, flattenIdx = 0, type2: int structField = 1, flattenIdx = 1, type2: char[10] structField = 2, flattenIdx = 11, type2: int[5]
for (2) i = 0, op: 0, type: [10 x i8]*(Ptr), type2: [10 x i8](Arr) i = 1, op: 8, type: [10 x i8](Arr), type2: i8
Definition at line 124 of file AccessPath.cpp.
APOffset AccessPath::computeConstantOffset | ( | ) | const |
For example,.
Return accumulated constant offset given OffsetVarVec compard to computeConstantByteOffset, it is field offset rather than byte offset e.g. GepStmt* gep = [i32*4], 2 APOffset byteOffset = gep->computeConstantOffset(); byteOffset should be 2 since it is field offset.
Return accumulated constant offset
"value" is the offset variable (must be a constant) "type" is the location where we want to compute offset Given a vector: [(value1,type1), (value2,type2), (value3,type3)] totalConstOffset = flattenOffset(value1,type1) * flattenOffset(value2,type2) + flattenOffset(value3,type3) For a pointer type (e.g., t1 is PointerType), we will retrieve the pointee type and times the offset, i.e., getElementNum(t1) X off1 %5 = getelementptr inbounds struct.Student, struct.Student* %4, i64 1 value1: i64 1 type1: struct.Student* computeConstantOffset = 32 %6 = getelementptr inbounds struct.Student, struct.Student* %5, i32 0, i32 1 value1: i32 0 type1: struct.Student* value2: i32 1 type2: struct.Student = type { struct.inner, [10 x [3 x i8]] } computeConstantOffset = 2 %7 = getelementptr inbounds [10 x [3 x i8]], [10 x [3 x i8]]* %6, i64 0, i64 3 value1: i64 0 type1: [10 x [3 x i8]]* value2: i64 3 type2: [10 x [3 x i8]] computeConstantOffset = 9 %8 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 2 value1: i64 0 type1: [3 x i8]* value2: i64 2 type2: [3 x i8] computeConstantOffset = 2
Definition at line 212 of file AccessPath.cpp.
std::string AccessPath::dump | ( | ) | const |
Dump location set.
Definition at line 332 of file AccessPath.cpp.
Definition at line 112 of file AccessPath.h.
|
inline |
Return element number of a type.
Return element number of a type (1) StructType or Array, return flattened number elements. (2) Pointer type, return max field limit (3) Non-pointer SingleValueType or Function Type, return 1
Definition at line 63 of file AccessPath.cpp.
|
inline |
Definition at line 108 of file AccessPath.h.
u32_t AccessPath::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 type.
Return byte offset from the beginning of the structure to the field where it is located for struct type
Definition at line 98 of file AccessPath.cpp.
|
inline |
Return TRUE if we share any location in common with RHS.
Definition at line 156 of file AccessPath.h.
bool AccessPath::isConstantOffset | ( | ) | const |
Return TRUE if this is a constant location set.
Return true if all offset values are constants.
Definition at line 49 of file AccessPath.cpp.
AccessPath AccessPath::operator+ | ( | const AccessPath & | rhs | ) | const |
Overload operators.
Definition at line 275 of file AccessPath.cpp.
bool AccessPath::operator< | ( | const AccessPath & | rhs | ) | const |
Definition at line 286 of file AccessPath.cpp.
|
inline |
Definition at line 84 of file AccessPath.h.
|
inline |
Definition at line 91 of file AccessPath.h.
|
inline |
Definition at line 104 of file AccessPath.h.
|
friend |
Definition at line 56 of file AccessPath.h.
|
friend |
Definition at line 55 of file AccessPath.h.
|
friend |
Definition at line 54 of file AccessPath.h.
|
private |
Accumulated Constant Offsets.
Definition at line 175 of file AccessPath.h.
Definition at line 177 of file AccessPath.h.
|
private |
a vector of actual offset in the form of <SVF Var, iterator type>
Definition at line 176 of file AccessPath.h.