Skip to content

Commit

Permalink
Merge pull request #1293 from Qcloud1223/master
Browse files Browse the repository at this point in the history
consider multiple uses of heap object
  • Loading branch information
yuleisui authored Dec 20, 2023
2 parents af2bdc8 + 9122f3d commit 7d68ccb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions svf-llvm/include/SVF-LLVM/LLVMUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ const Value* stripAllCasts(const Value* val);
/// Get the type of the heap allocation
const Type* getTypeOfHeapAlloc(const Instruction* inst);

/// Return the bitcast instruction which is val's only use site, otherwise
/// Return the bitcast instruction right next to val, otherwise
/// return nullptr
const Value* getUniqueUseViaCastInst(const Value* val);
const Value* getFirstUseViaCastInst(const Value* val);

/// Return corresponding constant expression, otherwise return nullptr
//@{
Expand Down
18 changes: 12 additions & 6 deletions svf-llvm/lib/LLVMUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,23 @@ void LLVMUtil::getPrevInsts(const Instruction* curInst, std::vector<const SVFIns
* for example, %4 = call align 16 i8* @malloc(i64 10); %5 = bitcast i8* %4 to i32*
* return %5 whose type is i32* but not %4 whose type is i8*
*/
const Value* LLVMUtil::getUniqueUseViaCastInst(const Value* val)
const Value* LLVMUtil::getFirstUseViaCastInst(const Value* val)
{
const PointerType * type = SVFUtil::dyn_cast<PointerType>(val->getType());
assert(type && "this value should be a pointer type!");
/// If type is void* (i8*) and val is only used at a bitcast instruction
/// If type is void* (i8*) and val is immediately used at a bitcast instruction
if (IntegerType *IT = SVFUtil::dyn_cast<IntegerType>(getPtrElementType(type)))
{
if (IT->getBitWidth() == 8 && val->getNumUses()==1)
if (IT->getBitWidth() == 8)
{
const Use *u = &*val->use_begin();
return SVFUtil::dyn_cast<BitCastInst>(u->getUser());
const Value *latestUse = nullptr;
for (const auto &it : val->uses()) {
if (SVFUtil::isa<BitCastInst>(it.getUser()))
latestUse = it.getUser();
else
latestUse = nullptr;
}
return latestUse;
}
}
return nullptr;
Expand All @@ -371,7 +377,7 @@ const Type* LLVMUtil::getTypeOfHeapAlloc(const Instruction *inst)
const SVFInstruction* svfinst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(inst);
if(SVFUtil::isHeapAllocExtCallViaRet(svfinst))
{
if(const Value* v = getUniqueUseViaCastInst(inst))
if(const Value* v = getFirstUseViaCastInst(inst))
{
if(const PointerType* newTy = SVFUtil::dyn_cast<PointerType>(v->getType()))
type = newTy;
Expand Down
2 changes: 1 addition & 1 deletion svf-llvm/lib/SVFIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ const Value* SVFIRBuilder::getBaseValueForExtArg(const Value* V)
const SVFInstruction* svfInst = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cb);
if (SVFUtil::isHeapAllocExtCallViaRet(svfInst))
{
if (const Value* bitCast = getUniqueUseViaCastInst(cb))
if (const Value* bitCast = getFirstUseViaCastInst(cb))
return bitCast;
}
}
Expand Down
4 changes: 2 additions & 2 deletions svf-llvm/lib/SymbolTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ u32_t SymbolTableBuilder::analyzeHeapAllocByteSize(const Value* val)
*/
void SymbolTableBuilder::analyzeHeapObjType(ObjTypeInfo* typeinfo, const Value* val)
{
if(const Value* castUse = getUniqueUseViaCastInst(val))
if(const Value* castUse = getFirstUseViaCastInst(val))
{
typeinfo->setFlag(ObjTypeInfo::HEAP_OBJ);
typeinfo->resetTypeForHeapStaticObj(
Expand All @@ -774,7 +774,7 @@ void SymbolTableBuilder::analyzeHeapObjType(ObjTypeInfo* typeinfo, const Value*
*/
void SymbolTableBuilder::analyzeStaticObjType(ObjTypeInfo* typeinfo, const Value* val)
{
if(const Value* castUse = getUniqueUseViaCastInst(val))
if(const Value* castUse = getFirstUseViaCastInst(val))
{
typeinfo->setFlag(ObjTypeInfo::STATIC_OBJ);
typeinfo->resetTypeForHeapStaticObj(
Expand Down

0 comments on commit 7d68ccb

Please sign in to comment.