diff --git a/svf-llvm/include/SVF-LLVM/LLVMUtil.h b/svf-llvm/include/SVF-LLVM/LLVMUtil.h index 924839b2f..5fe7969ac 100644 --- a/svf-llvm/include/SVF-LLVM/LLVMUtil.h +++ b/svf-llvm/include/SVF-LLVM/LLVMUtil.h @@ -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 //@{ diff --git a/svf-llvm/lib/LLVMUtil.cpp b/svf-llvm/lib/LLVMUtil.cpp index 67e7d34e3..07d123845 100644 --- a/svf-llvm/lib/LLVMUtil.cpp +++ b/svf-llvm/lib/LLVMUtil.cpp @@ -346,17 +346,23 @@ void LLVMUtil::getPrevInsts(const Instruction* curInst, std::vector(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(getPtrElementType(type))) { - if (IT->getBitWidth() == 8 && val->getNumUses()==1) + if (IT->getBitWidth() == 8) { - const Use *u = &*val->use_begin(); - return SVFUtil::dyn_cast(u->getUser()); + const Value *latestUse = nullptr; + for (const auto &it : val->uses()) { + if (SVFUtil::isa(it.getUser())) + latestUse = it.getUser(); + else + latestUse = nullptr; + } + return latestUse; } } return nullptr; @@ -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(v->getType())) type = newTy; diff --git a/svf-llvm/lib/SVFIRBuilder.cpp b/svf-llvm/lib/SVFIRBuilder.cpp index 5922017dd..2c707fa8a 100644 --- a/svf-llvm/lib/SVFIRBuilder.cpp +++ b/svf-llvm/lib/SVFIRBuilder.cpp @@ -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; } } diff --git a/svf-llvm/lib/SymbolTableBuilder.cpp b/svf-llvm/lib/SymbolTableBuilder.cpp index a8b2b1cd7..8c08f5f4a 100644 --- a/svf-llvm/lib/SymbolTableBuilder.cpp +++ b/svf-llvm/lib/SymbolTableBuilder.cpp @@ -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( @@ -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(