Skip to content

Commit

Permalink
fix SVFBasicBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
bjjwwang committed Jan 27, 2025
1 parent 66508f7 commit 3776a6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
27 changes: 4 additions & 23 deletions svf-llvm/include/SVF-LLVM/LLVMModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class LLVMModuleSet
typedef Map<const Function*, SVFFunction*> LLVMFun2SVFFunMap;
typedef Map<const Function*, CallGraphNode*> LLVMFun2CallGraphNodeMap;
typedef Map<const BasicBlock*, SVFBasicBlock*> LLVMBB2SVFBBMap;
typedef Map<const SVFBasicBlock*, const BasicBlock*> SVFBB2LLVMBBMap;
typedef Map<const Instruction*, SVFInstruction*> LLVMInst2SVFInstMap;
typedef Map<const Argument*, SVFArgument*> LLVMArgument2SVFArgumentMap;
typedef Map<const Constant*, SVFConstant*> LLVMConst2SVFConstMap;
Expand Down Expand Up @@ -94,7 +93,6 @@ class LLVMModuleSet
LLVMFun2SVFFunMap LLVMFunc2SVFFunc; ///< Map an LLVM Function to an SVF Function
LLVMFun2CallGraphNodeMap LLVMFunc2CallGraphNode; ///< Map an LLVM Function to an CallGraph Node
LLVMBB2SVFBBMap LLVMBB2SVFBB;
SVFBB2LLVMBBMap SVFBB2LLVMBB;
LLVMInst2SVFInstMap LLVMInst2SVFInst;
LLVMArgument2SVFArgumentMap LLVMArgument2SVFArgument;
LLVMConst2SVFConstMap LLVMConst2SVFConst;
Expand Down Expand Up @@ -183,7 +181,7 @@ class LLVMModuleSet
inline void addBasicBlockMap(const BasicBlock* bb, SVFBasicBlock* svfBB)
{
LLVMBB2SVFBB[bb] = svfBB;
SVFBB2LLVMBB[svfBB] = bb;
SVFBaseNode2LLVMValue[svfBB] = bb;
}

inline void addInstructionMap(const Instruction* inst, SVFInstruction* svfInst)
Expand Down Expand Up @@ -249,19 +247,9 @@ class LLVMModuleSet

const Value* getLLVMValue(const SVFBaseNode* value) const
{
if (SVFUtil::isa<SVFBasicBlock>(value))
{
const SVFBasicBlock* bb = SVFUtil::cast<SVFBasicBlock>(value);
SVFBB2LLVMBBMap::const_iterator it = SVFBB2LLVMBB.find(bb);
assert(it!=SVFBB2LLVMBB.end() && "can't find corresponding llvm value!");
return it->second;
}
else
{
SVFBaseNode2LLVMValueMap ::const_iterator it = SVFBaseNode2LLVMValue.find(value);
assert(it != SVFBaseNode2LLVMValue.end() && "can't find corresponding llvm value!");
return it->second;
}
SVFBaseNode2LLVMValueMap ::const_iterator it = SVFBaseNode2LLVMValue.find(value);
assert(it != SVFBaseNode2LLVMValue.end() && "can't find corresponding llvm value!");
return it->second;
}

inline CallGraphNode* getCallGraphNode(const Function* fun) const
Expand All @@ -285,13 +273,6 @@ class LLVMModuleSet
return it->second;
}

const BasicBlock* getLLVMBasicBlock(const SVFBasicBlock* bb) const
{
SVFBB2LLVMBBMap::const_iterator it = SVFBB2LLVMBB.find(bb);
assert(it!=SVFBB2LLVMBB.end() && "LLVM BasicBlock not found!");
return it->second;
}

inline SVFInstruction* getSVFInstruction(const Instruction* inst) const
{
LLVMInst2SVFInstMap::const_iterator it = LLVMInst2SVFInst.find(inst);
Expand Down
4 changes: 2 additions & 2 deletions svf-llvm/lib/ObjTypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ Set<const Value *> &ObjTypeInference::bwfindAllocOfVar(const Value *var)
if (!callee->isDeclaration())
{
const SVFFunction *svfFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee);
const BasicBlock* exitBB = LLVMModuleSet::getLLVMModuleSet()->getLLVMBasicBlock(svfFunc->getExitBB());
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB()));
const Value *pValue = &exitBB->back();
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue);
ABORT_IFNOT(retInst && retInst->getReturnValue(), "not return inst?");
Expand Down Expand Up @@ -893,7 +893,7 @@ Set<const Value *> &ObjTypeInference::bwFindAllocOrClsNameSources(const Value *s
if (!callee->isDeclaration())
{
const SVFFunction *svfFunc = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(callee);
const BasicBlock* exitBB = LLVMModuleSet::getLLVMModuleSet()->getLLVMBasicBlock(svfFunc->getExitBB());
const BasicBlock* exitBB = SVFUtil::dyn_cast<BasicBlock>(LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfFunc->getExitBB()));
const Value *pValue = &exitBB->back();
const auto *retInst = SVFUtil::dyn_cast<ReturnInst>(pValue);
ABORT_IFNOT(retInst && retInst->getReturnValue(), "not return inst?");
Expand Down
1 change: 1 addition & 0 deletions svf/include/SVFIR/SVFValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ class SVFFunction : public SVFValue
inline const SVFBasicBlock* getEntryBlock() const
{
assert(hasBasicBlock() && "function does not have any Basicblock, external function?");
assert(bbGraph->begin()->second->getInEdges().size() == 0 && "the first basic block is not entry block");
return bbGraph->begin()->second;
}

Expand Down

0 comments on commit 3776a6a

Please sign in to comment.