From cb22e1967b0a18f9bd27a8c7fcb36d8b10158422 Mon Sep 17 00:00:00 2001 From: Johannes Blaser Date: Fri, 16 Feb 2024 10:31:04 +0100 Subject: [PATCH] Integrated comments on initial pull request #1376; fixed C++ copy-elision; fixed non-specific return types --- svf-llvm/include/SVF-LLVM/CppUtil.h | 2 -- svf-llvm/include/SVF-LLVM/ObjTypeInference.h | 5 +++-- svf-llvm/lib/CppUtil.cpp | 12 ------------ svf-llvm/lib/ObjTypeInference.cpp | 6 +++--- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/svf-llvm/include/SVF-LLVM/CppUtil.h b/svf-llvm/include/SVF-LLVM/CppUtil.h index 1b8a8ecf1..6a3376697 100644 --- a/svf-llvm/include/SVF-LLVM/CppUtil.h +++ b/svf-llvm/include/SVF-LLVM/CppUtil.h @@ -156,8 +156,6 @@ std::string extractClsNameFromDynCast(const CallBase* callBase); const Type *cppClsNameToType(const std::string &className); -std::string typeToClsName(const Type *ty); - /// Constants pertaining to CTir, for C and C++. /// TODO: move helper functions here too? diff --git a/svf-llvm/include/SVF-LLVM/ObjTypeInference.h b/svf-llvm/include/SVF-LLVM/ObjTypeInference.h index ec5fcc675..a64ac30f4 100644 --- a/svf-llvm/include/SVF-LLVM/ObjTypeInference.h +++ b/svf-llvm/include/SVF-LLVM/ObjTypeInference.h @@ -48,7 +48,7 @@ class ObjTypeInference typedef Map ValueToType; typedef std::pair ValueBoolPair; typedef Map> ValueToClassNames; - typedef Map> ObjToClsNameSources; + typedef Map> ObjToClsNameSources; private: @@ -122,7 +122,8 @@ class ObjTypeInference Set &bwFindAllocOrClsNameSources(const Value *startValue); /// forward find class name sources starting from an allocation - Set &fwFindClsNameSources(const Value *startValue); + Set &fwFindClsNameSources(const Value *startValue); }; + } #endif //SVF_OBJTYPEINFERENCE_H diff --git a/svf-llvm/lib/CppUtil.cpp b/svf-llvm/lib/CppUtil.cpp index 14bae02e8..2c81f5a29 100644 --- a/svf-llvm/lib/CppUtil.cpp +++ b/svf-llvm/lib/CppUtil.cpp @@ -883,15 +883,3 @@ const Type *cppUtil::cppClsNameToType(const std::string &className) clsName + className); return classTy ? classTy : LLVMModuleSet::getLLVMModuleSet()->getTypeInference()->ptrType(); } - -std::string cppUtil::typeToClsName(const Type *ty) -{ - if (const auto *stTy = SVFUtil::dyn_cast(ty)) - { - const std::string &typeName = stTy->getName().str(); - const std::string &className = typeName.substr( - clsName.size(), typeName.size() - clsName.size()); - return className; - } - return ""; -} \ No newline at end of file diff --git a/svf-llvm/lib/ObjTypeInference.cpp b/svf-llvm/lib/ObjTypeInference.cpp index 2150526c9..baa45ede9 100644 --- a/svf-llvm/lib/ObjTypeInference.cpp +++ b/svf-llvm/lib/ObjTypeInference.cpp @@ -611,7 +611,7 @@ Set &ObjTypeInference::inferThisPtrClsName(const Value *thisPtr) auto addNamesFromFunc = [&names](const Function *func) -> void { ABORT_IFNOT(isClsNameSource(func), "Func is invalid class name source: " + dumpValueAndDbgInfo(func)); - for (auto name : extractClsNamesFromFunc(func)) names.insert(name); + for (const auto &name : extractClsNamesFromFunc(func)) names.insert(name); }; // Lambda for getting callee & extracting class name for calls to constructors/destructors/template funcs @@ -806,7 +806,7 @@ Set &ObjTypeInference::bwFindAllocOrClsNameSources(const Value *s return _valueToAllocOrClsNameSources[startValue]; } -Set &ObjTypeInference::fwFindClsNameSources(const Value *startValue) +Set &ObjTypeInference::fwFindClsNameSources(const Value *startValue) { assert(startValue && "startValue was null?"); @@ -817,7 +817,7 @@ Set &ObjTypeInference::fwFindClsNameSources(const Value *startVal return tIt->second; } - Set sources; + Set sources; // Lambda for adding a callee to the sources iff it is a constructor/destructor/template/dyncast auto inferViaCppCall = [&sources](const CallBase *caller)