Skip to content

Commit

Permalink
getElementNum for multi-level pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
jumormt committed Dec 28, 2023
1 parent de63fe7 commit 460444f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions svf/lib/MemoryModel/AccessPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,26 @@ bool AccessPath::isConstantOffset() const

/// Return element number of a type
/// (1) StructType or Array, return flattened number elements.
/// (2) SingleValueType or Function Type, return 1
/// (2) Pointer type, return max field limit
/// (3) Non-pointer SingleValueType or Function Type, return 1
u32_t AccessPath::getElementNum(const SVFType* type) const
{
if (SVFUtil::isa<SVFArrayType, SVFStructType>(type))
{
return SymbolTableInfo::SymbolInfo()->getNumOfFlattenElements(type);
}
else if (type->isSingleValueType() || SVFUtil::isa<SVFFunctionType>(type))
} else if (type->isPointerTy())

Check warning on line 68 in svf/lib/MemoryModel/AccessPath.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MemoryModel/AccessPath.cpp#L68

Added line #L68 was not covered by tests
{
// if type is a pointer, should be like:
// %2 = getelementptr inbounds i32*, i32** %1, ...
// where gepSrcPointee is of pointer type (i32*).
// the element number of int* should be 1
// this can be transformed to:
// %2 = getelementptr inbounds [N x i32], [N x i32]* %1, ...
// However, we do not know N without context information. int** implies non-contiguous blocks of memory
// In this case, we conservatively return max field limit
return Options::MaxFieldLimit();

Check warning on line 77 in svf/lib/MemoryModel/AccessPath.cpp

View check run for this annotation

Codecov / codecov/patch

svf/lib/MemoryModel/AccessPath.cpp#L77

Added line #L77 was not covered by tests
}
else if (type->isSingleValueType() || SVFUtil::isa<SVFFunctionType>(type))
{
return 1;
}
else
Expand Down

0 comments on commit 460444f

Please sign in to comment.