Skip to content

Commit

Permalink
remove hasName assertion and terminate early for no-name function
Browse files Browse the repository at this point in the history
  • Loading branch information
jumormt committed Dec 19, 2024
1 parent 0f3f2c6 commit 2346ab2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions svf-llvm/include/SVF-LLVM/LLVMUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ inline const Function* getProgEntryFunction(Module& module)
return nullptr;
}

/// Check if a function is an indirect or no-name function
inline bool isIndirectOrNoNameFunc(const Function* func) {
return func == nullptr || func->hasName() == false;
}

} // End namespace LLVMUtil

} // End namespace SVF
Expand Down
14 changes: 5 additions & 9 deletions svf-llvm/lib/CppUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ void stripBracketsAndNamespace(cppUtil::DemangledName& dname)

bool cppUtil::isConstructor(const Function* F)
{
if (F->isDeclaration())
return false;
if(LLVMUtil::isIndirectOrNoNameFunc(F) || F->isDeclaration()) return false;
std::string funcName = F->getName().str();
if (funcName.compare(0, vfunPreLabel.size(), vfunPreLabel) != 0)
{
Expand All @@ -508,8 +507,7 @@ bool cppUtil::isConstructor(const Function* F)

bool cppUtil::isDestructor(const Function* F)
{
if (F->isDeclaration())
return false;
if(LLVMUtil::isIndirectOrNoNameFunc(F) || F->isDeclaration()) return false;
std::string funcName = F->getName().str();
if (funcName.compare(0, vfunPreLabel.size(), vfunPreLabel) != 0)
{
Expand Down Expand Up @@ -705,7 +703,7 @@ bool LLVMUtil::isConstantObjSym(const Value* val)
*/
Set<std::string> cppUtil::extractClsNamesFromFunc(const Function *foo)
{
assert(foo->hasName() && "foo does not have a name? possible indirect call");
if(LLVMUtil::isIndirectOrNoNameFunc(foo)) return {};
const std::string &name = foo->getName().str();
if (isConstructor(foo) || isDestructor(foo))
{
Expand Down Expand Up @@ -863,8 +861,6 @@ bool cppUtil::isClsNameSource(const Value *val)
if (const auto *callBase = SVFUtil::dyn_cast<CallBase>(val))
{
const Function *foo = callBase->getCalledFunction();
// indirect call
if(!foo) return false;
return isConstructor(foo) || isDestructor(foo) || isTemplateFunc(foo) || isDynCast(foo);
}
else if (const auto *func = SVFUtil::dyn_cast<Function>(val))
Expand Down Expand Up @@ -894,7 +890,7 @@ bool cppUtil::matchesLabel(const std::string &foo, const std::string &label)
bool cppUtil::isTemplateFunc(const Function *foo)
{
/// if the function does not have a name, it can be a compiler generated internal function.
if(foo->hasName() == false)
if(LLVMUtil::isIndirectOrNoNameFunc(foo))
return false;
const std::string &name = foo->getName().str();
bool matchedLabel = matchesLabel(name, znstLabel) || matchesLabel(name, znkstLabel) ||
Expand All @@ -911,7 +907,7 @@ bool cppUtil::isTemplateFunc(const Function *foo)
*/
bool cppUtil::isDynCast(const Function *foo)
{
assert(foo->hasName() && "foo does not have a name? possible indirect call");
if(LLVMUtil::isIndirectOrNoNameFunc(foo)) return false;
return foo->getName().str() == dyncast;
}

Expand Down

0 comments on commit 2346ab2

Please sign in to comment.