Skip to content

Commit

Permalink
add typeinference pattern: alloc->gep->store->gep->load (issue SVF-to…
Browse files Browse the repository at this point in the history
  • Loading branch information
jumormt committed Apr 22, 2024
1 parent 3f9ff09 commit 289c6f6
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions svf-llvm/lib/ObjTypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,27 +247,51 @@ const Type *ObjTypeInference::fwInferObjType(const Value *var)
}
/*
* infer based on store (value operand) <- gep (result element)
%call1 = call i8* @TYPE_MALLOC(i32 noundef 16, i32 noundef 2), !dbg !39
%2 = bitcast i8* %call1 to %struct.MyStruct*, !dbg !41
%3 = load %struct.MyStruct*, %struct.MyStruct** %p, align 8, !dbg !42
%next = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %3, i32 0, i32 1, !dbg !43
store %struct.MyStruct* %2, %struct.MyStruct** %next, align 8, !dbg !44
%5 = load %struct.MyStruct*, %struct.MyStruct** %p, align 8, !dbg !48
%next3 = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %5, i32 0, i32 1, !dbg !49
%6 = load %struct.MyStruct*, %struct.MyStruct** %next3, align 8, !dbg !49
infer site -> %f1 = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %6, i32 0, i32 0, !dbg !50
*/
if (const auto *gepInst = SVFUtil::dyn_cast<GetElementPtrInst>(
storeInst->getPointerOperand()))
{
/*
%call1 = call i8* @TYPE_MALLOC(i32 noundef 16, i32 noundef 2), !dbg !39
%2 = bitcast i8* %call1 to %struct.MyStruct*, !dbg !41
%3 = load %struct.MyStruct*, %struct.MyStruct** %p, align 8, !dbg !42
%next = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %3, i32 0, i32 1, !dbg !43
store %struct.MyStruct* %2, %struct.MyStruct** %next, align 8, !dbg !44
%5 = load %struct.MyStruct*, %struct.MyStruct** %p, align 8, !dbg !48
%next3 = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %5, i32 0, i32 1, !dbg !49
%6 = load %struct.MyStruct*, %struct.MyStruct** %next3, align 8, !dbg !49
infer site -> %f1 = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %6, i32 0, i32 0, !dbg !50
*/
const Value *gepBase = gepInst->getPointerOperand();
if (!SVFUtil::isa<LoadInst>(gepBase)) continue;
const auto *load = SVFUtil::dyn_cast<LoadInst>(gepBase);
for (const auto &loadUse: load->getPointerOperand()->users())
{
if (loadUse == load || !SVFUtil::isa<LoadInst>(loadUse))
continue;
for (const auto &gepUse: loadUse->users())
if(const auto *load = SVFUtil::dyn_cast<LoadInst>(gepBase)){
for (const auto &loadUse: load->getPointerOperand()->users())
{
if (loadUse == load || !SVFUtil::isa<LoadInst>(loadUse))
continue;
for (const auto &gepUse: loadUse->users())
{
if (!SVFUtil::isa<GetElementPtrInst>(gepUse)) continue;
for (const auto &loadUse2: gepUse->users())
{
if (SVFUtil::isa<LoadInst>(loadUse2))
{
insertInferSitesOrPushWorklist(loadUse2);
}
}
}
}
} else if (const auto *alloc = SVFUtil::dyn_cast<AllocaInst>(gepBase)) {
/*
%2 = alloca %struct.ll, align 8
store i32 0, ptr %1, align 4
%3 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 16) #2
%4 = getelementptr inbounds %struct.ll, ptr %2, i32 0, i32 1
store ptr %3, ptr %4, align 8
%5 = getelementptr inbounds %struct.ll, ptr %2, i32 0, i32 1
%6 = load ptr, ptr %5, align 8
%7 = getelementptr inbounds %struct.ll, ptr %6, i32 0, i32 0
*/
for (const auto &gepUse: alloc->users())
{
if (!SVFUtil::isa<GetElementPtrInst>(gepUse)) continue;
for (const auto &loadUse2: gepUse->users())
Expand All @@ -279,7 +303,6 @@ const Type *ObjTypeInference::fwInferObjType(const Value *var)
}
}
}

}
}

Expand Down

0 comments on commit 289c6f6

Please sign in to comment.