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 coverage and fix struct gep accumulatedGepByteOffset() #1241

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
add comments to AccessPath::computeConstantByteOffset()
  • Loading branch information
jiawei.wang committed Nov 10, 2023
commit cc2e754606fb534370f049b28193f5d45f6f11a1
18 changes: 18 additions & 0 deletions svf/lib/MemoryModel/AccessPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,43 @@
APOffset totalConstOffset = 0;
for(int i = offsetVarAndGepTypePairs.size() - 1; i >= 0; i--)
{
/// 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
// (2) %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %b, i64 0, i64 8
const SVFValue* value = offsetVarAndGepTypePairs[i].first->getValue();
/// 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
const SVFType* type = offsetVarAndGepTypePairs[i].second;
const SVFType* type2 = type;
if (const SVFArrayType* arrType = SVFUtil::dyn_cast<SVFArrayType>(type))
{
/// for (2) i = 1, arrType: [10 x i8], type2 = i8
type2 = arrType->getTypeOfElement();
}
else if (const SVFPointerType* ptrType = SVFUtil::dyn_cast<SVFPointerType>(type))
{
/// for (1) i = 0, ptrType: %struct.DEST*, type2: %struct.DEST
/// for (2) i = 0, ptrType: [10 x i8]*, type2 = [10 x i8]
type2 = ptrType->getPtrElementType();
}

const SVFConstantInt* op = SVFUtil::dyn_cast<SVFConstantInt>(value);
if (const SVFStructType* structType = SVFUtil::dyn_cast<SVFStructType>(type)) {

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

View check run for this annotation

Codecov / codecov/patch

svf/lib/MemoryModel/AccessPath.cpp#L129

Added line #L129 was not covered by tests
/// for (1) structType: %struct.DEST
/// structField = 0, type2: int
/// structField = 1, type2: char[10]
/// structField = 2, type2: int[5]
for (u32_t structField = 0; structField < (u32_t)op->getSExtValue(); ++structField) {
type2 = structType->getTypeInfo()->getOriginalElemType(structField);
totalConstOffset += type2->getLLVMByteSize();

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

View check run for this annotation

Codecov / codecov/patch

svf/lib/MemoryModel/AccessPath.cpp#L134-L136

Added lines #L134 - L136 were not covered by tests
}
} else {
/// 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
totalConstOffset += op->getSExtValue() * type2->getLLVMByteSize();
}
}
Expand Down
Loading