diff --git a/CMakeLists.txt b/CMakeLists.txt index b9b6bf810..9743e3ad8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -293,8 +293,12 @@ else() endif() # SQL -find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) -find_library(SQLITE3_LIBRARY NAMES sqlite3) +find_package(SQLite3) +if(SQLite3_FOUND) + set(PHASAR_HAS_SQLITE ON) +else() + set(PHASAR_HAS_SQLITE OFF) +endif() option(USE_LLVM_FAT_LIB "Link against libLLVM.so instead of the individual LLVM libraries if possible (default is OFF; always on if BUILD_SHARED_LIBS is ON)" OFF) diff --git a/bootstrap.sh b/bootstrap.sh index bb641b5da..345d88570 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -108,7 +108,7 @@ set -- "${POSITIONAL[@]}" # restore positional parameters echo "installing phasar dependencies..." if [ -x "$(command -v pacman)" ]; then - yes | sudo pacman -Syu --needed which zlib sqlite3 python3 doxygen gcc python-pip ninja cmake + yes | sudo pacman -Syu --needed which zlib python3 doxygen gcc ninja cmake else ./utils/InstallAptDependencies.sh fi diff --git a/cmake/phasar_macros.cmake b/cmake/phasar_macros.cmake index 3a6d28dbb..2ce5cd45f 100644 --- a/cmake/phasar_macros.cmake +++ b/cmake/phasar_macros.cmake @@ -76,6 +76,13 @@ function(generate_ll_file) set(GEN_C_FLAGS -fno-discard-value-names -emit-llvm -S -w) set(GEN_CMD_COMMENT "[LL]") + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) + list(APPEND GEN_CXX_FLAGS -Xclang -no-opaque-pointers) + endif() + if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15) + list(APPEND GEN_C_FLAGS -Xclang -no-opaque-pointers) + endif() + if(GEN_LL_MEM2REG) list(APPEND GEN_CXX_FLAGS -Xclang -disable-O0-optnone) list(APPEND GEN_C_FLAGS -Xclang -disable-O0-optnone) @@ -121,7 +128,7 @@ function(generate_ll_file) add_custom_command( OUTPUT ${test_code_ll_file} COMMAND ${GEN_CMD} ${test_code_file_path} -o ${test_code_ll_file} - COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} opt -mem2reg -S ${test_code_ll_file} -o ${test_code_ll_file} + COMMAND ${CMAKE_CXX_COMPILER_LAUNCHER} opt -mem2reg -S -opaque-pointers=0 ${test_code_ll_file} -o ${test_code_ll_file} COMMENT ${GEN_CMD_COMMENT} DEPENDS ${GEN_LL_FILE} VERBATIM diff --git a/config.h.in b/config.h.in index 923329206..253f05f86 100644 --- a/config.h.in +++ b/config.h.in @@ -9,4 +9,6 @@ #cmakedefine DYNAMIC_LOG #cmakedefine BUILD_PHASAR_CLANG +#cmakedefine PHASAR_HAS_SQLITE + #endif /* PHASAR_CONFIG_CONFIG_H */ diff --git a/include/phasar/DB.h b/include/phasar/DB.h index f77b88f01..4ddd16a5e 100644 --- a/include/phasar/DB.h +++ b/include/phasar/DB.h @@ -10,8 +10,12 @@ #ifndef PHASAR_DB_H #define PHASAR_DB_H -#include "phasar/DB/Hexastore.h" +#include "phasar/Config/phasar-config.h" #include "phasar/DB/ProjectIRDBBase.h" + +#ifdef PHASAR_HAS_SQLITE +#include "phasar/DB/Hexastore.h" #include "phasar/DB/Queries.h" +#endif #endif // PHASAR_DB_H diff --git a/include/phasar/DB/Hexastore.h b/include/phasar/DB/Hexastore.h index 02bfb698a..d6960c903 100644 --- a/include/phasar/DB/Hexastore.h +++ b/include/phasar/DB/Hexastore.h @@ -10,17 +10,20 @@ #ifndef PHASAR_DB_HEXASTORE_H_ #define PHASAR_DB_HEXASTORE_H_ -#include "phasar/DB/Queries.h" +#include "phasar/Config/phasar-config.h" +#ifndef PHASAR_HAS_SQLITE +#error \ + "Hexastore requires SQLite3. Please install libsqlite3-dev and reconfigure PhASAR." +#endif #include "llvm/Support/raw_ostream.h" -#include "boost/format.hpp" -#include "sqlite3.h" - #include #include #include +struct sqlite3; + namespace psr { /** * @brief Holds the results of a query to the Hexastore. @@ -51,6 +54,7 @@ struct HSResult { LHS.Object == RHS.Object; } }; + /** * A Hexastore is an efficient approach to store large graphs. * This approach is based on the paper "Database-Backed Program Analysis diff --git a/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h b/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h index 4e05c9279..0be77db3d 100644 --- a/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h +++ b/include/phasar/DataFlow/Mono/Solver/InterMonoSolver.h @@ -24,7 +24,6 @@ #include #include #include -#include namespace psr { @@ -368,18 +367,8 @@ template class InterMonoSolver { } // Compute the data-flow facts using the respective kind of flows if (ICF->isCallSite(Src)) { - // Handle call flow(s) - if (!isIntraEdge(Edge)) { - // real call - for (auto &[Ctx, Facts] : Analysis[Src]) { - processCall(Edge); // TODO: decompose into processCall and - // processCallToRet - } - } else { - // call-to-return - processCall( - Edge); // TODO: decompose into processCall and processCallToRet - } + // Handle call flow(s) and call-to-return flow + processCall(Edge); } else if (ICF->isExitInst(Src)) { // Handle return flow processExit(Edge); diff --git a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h index 12bc78493..92e964e14 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h +++ b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h @@ -42,6 +42,7 @@ namespace psr { class LLVMTypeHierarchy; class LLVMProjectIRDB; +class Resolver; class LLVMBasedICFG; template <> struct CFGTraits : CFGTraits {}; @@ -87,6 +88,11 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase { LLVMAliasInfoRef PT = nullptr, Soundness S = Soundness::Soundy, bool IncludeGlobals = true); + explicit LLVMBasedICFG(LLVMProjectIRDB *IRDB, Resolver &CGResolver, + llvm::ArrayRef EntryPoints = {}, + LLVMTypeHierarchy *TH = nullptr, + Soundness S = Soundness::Soundy, + bool IncludeGlobals = true); /// Creates an ICFG with an already given call-graph explicit LLVMBasedICFG(CallGraph CG, LLVMProjectIRDB *IRDB, @@ -157,6 +163,10 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase { [[nodiscard]] llvm::Function *buildCRuntimeGlobalCtorsDtorsModel( llvm::Module &M, llvm::ArrayRef UserEntryPoints); + void initialize(LLVMProjectIRDB *IRDB, Resolver &CGResolver, + llvm::ArrayRef EntryPoints, + LLVMTypeHierarchy *TH, Soundness S, bool IncludeGlobals); + // --- CallGraph CG; diff --git a/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h b/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h index 5755c5207..13c75d8f3 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h +++ b/include/phasar/PhasarLLVM/ControlFlow/Resolver/OTFResolver.h @@ -35,16 +35,14 @@ class Value; namespace psr { -class LLVMBasedICFG; class LLVMTypeHierarchy; class OTFResolver : public Resolver { protected: - LLVMBasedICFG &ICF; LLVMAliasInfoRef PT; public: - OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH, LLVMBasedICFG &ICF, + OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH, LLVMAliasInfoRef PT); ~OTFResolver() override = default; diff --git a/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h b/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h index 58671342f..73adbd37e 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h +++ b/include/phasar/PhasarLLVM/ControlFlow/Resolver/Resolver.h @@ -36,7 +36,6 @@ namespace psr { class LLVMProjectIRDB; class LLVMTypeHierarchy; enum class CallGraphAnalysisType; -class LLVMBasedICFG; class LLVMPointsToInfo; [[nodiscard]] std::optional @@ -83,9 +82,10 @@ class Resolver { [[nodiscard]] virtual std::string str() const = 0; - static std::unique_ptr - create(CallGraphAnalysisType Ty, LLVMProjectIRDB *IRDB, LLVMTypeHierarchy *TH, - LLVMBasedICFG *ICF = nullptr, LLVMAliasInfoRef PT = nullptr); + static std::unique_ptr create(CallGraphAnalysisType Ty, + LLVMProjectIRDB *IRDB, + LLVMTypeHierarchy *TH, + LLVMAliasInfoRef PT = nullptr); }; } // namespace psr diff --git a/include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/EdgeValue.h b/include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/EdgeValue.h index c26a6191c..783698c91 100644 --- a/include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/EdgeValue.h +++ b/include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/EdgeValue.h @@ -10,6 +10,7 @@ #ifndef PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H #define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEGENERALIZEDLCA_EDGEVALUE_H +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/Twine.h" #include "llvm/IR/Constant.h" diff --git a/lib/AnalysisStrategy/CMakeLists.txt b/lib/AnalysisStrategy/CMakeLists.txt index 5bb3d4446..8a194cc68 100644 --- a/lib/AnalysisStrategy/CMakeLists.txt +++ b/lib/AnalysisStrategy/CMakeLists.txt @@ -2,6 +2,5 @@ file(GLOB_RECURSE ANALYSIS_STRATEGY_SRC *.h *.cpp) add_phasar_library(phasar_analysis_strategy ${ANALYSIS_STRATEGY_SRC} - LINKS phasar_db phasar_controlflow LLVM_LINK_COMPONENTS Support ) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e1cc7b0f6..3c2ab5fdf 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -18,29 +18,35 @@ if(PHASAR_BUILD_DYNLIB) set(PHASAR_DYNLIB_KIND SHARED) endif() +set(PHASAR_LINK_LIBS + phasar_utils + phasar_passes + phasar_config + phasar_pointer + phasar_controlflow + + phasar_llvm_utils + phasar_llvm_db + phasar_llvm_pointer + phasar_llvm_typehierarchy + phasar_llvm_controlflow + + phasar_taintconfig + phasar_mono + phasar_llvm + phasar_llvm_ifdside + phasar_analysis_strategy + phasar_controller +) +if(SQLite3_FOUND) + list(APPEND PHASAR_LINK_LIBS phasar_db) +endif() + add_phasar_library(phasar ${PHASAR_DYNLIB_KIND} FILES LibPhasar.cpp LINKS - phasar_utils - phasar_passes - phasar_config - phasar_db - phasar_pointer - phasar_controlflow - - phasar_llvm_utils - phasar_llvm_db - phasar_llvm_pointer - phasar_llvm_typehierarchy - phasar_llvm_controlflow - - phasar_taintconfig - phasar_mono - phasar_llvm - phasar_llvm_ifdside - phasar_analysis_strategy - phasar_controller + ${PHASAR_LINK_LIBS} LINK_PRIVATE ${Boost_LIBRARIES} LLVM_LINK_COMPONENTS diff --git a/lib/Controller/CMakeLists.txt b/lib/Controller/CMakeLists.txt index dba171b58..b5fe95c5b 100644 --- a/lib/Controller/CMakeLists.txt +++ b/lib/Controller/CMakeLists.txt @@ -15,6 +15,7 @@ add_phasar_library(phasar_controller phasar_utils phasar_analysis_strategy phasar_taintconfig + phasar_passes LLVM_LINK_COMPONENTS Core diff --git a/lib/DB/CMakeLists.txt b/lib/DB/CMakeLists.txt index d5dbf67e1..74fef8d36 100644 --- a/lib/DB/CMakeLists.txt +++ b/lib/DB/CMakeLists.txt @@ -1,12 +1,10 @@ -file(GLOB_RECURSE DB_SRC *.h *.cpp) +if(SQLite3_FOUND) + file(GLOB_RECURSE DB_SRC *.h *.cpp) -add_phasar_library(phasar_db - ${DB_SRC} - LINKS phasar_passes phasar_utils - LLVM_LINK_COMPONENTS Support - LINK_PRIVATE ${SQLITE3_LIBRARY} -) - -target_include_directories(phasar_db - PRIVATE ${SQLITE3_INCLUDE_DIR} -) + add_phasar_library(phasar_db + ${DB_SRC} + LINKS phasar_passes phasar_utils + LLVM_LINK_COMPONENTS Support + LINK_PRIVATE SQLite::SQLite3 + ) +endif() diff --git a/lib/DB/Hexastore.cpp b/lib/DB/Hexastore.cpp index 6ae20cdfe..a912b4683 100644 --- a/lib/DB/Hexastore.cpp +++ b/lib/DB/Hexastore.cpp @@ -9,11 +9,16 @@ #include "phasar/DB/Hexastore.h" +#include "phasar/DB/Queries.h" + +#include "boost/format.hpp" +#include "sqlite3.h" + namespace psr { Hexastore::Hexastore(const std::string &Filename) { sqlite3_open(Filename.c_str(), &HSInternalDB); - const std::string Query = INIT; + const std::string &Query = INIT; char *Err; sqlite3_exec(HSInternalDB, Query.c_str(), callback, nullptr, &Err); if (Err != nullptr) { diff --git a/lib/PhasarLLVM/ControlFlow/CMakeLists.txt b/lib/PhasarLLVM/ControlFlow/CMakeLists.txt index ff8f27e28..0000f7b1a 100644 --- a/lib/PhasarLLVM/ControlFlow/CMakeLists.txt +++ b/lib/PhasarLLVM/ControlFlow/CMakeLists.txt @@ -7,7 +7,6 @@ add_phasar_library(phasar_llvm_controlflow phasar_llvm_pointer phasar_llvm_typehierarchy phasar_llvm_utils - phasar_db phasar_controlflow LLVM_LINK_COMPONENTS diff --git a/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp b/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp index 87b2279f2..eadc987db 100644 --- a/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp +++ b/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp @@ -9,7 +9,6 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" -#include "phasar/Config/Configuration.h" #include "phasar/ControlFlow/CallGraph.h" #include "phasar/ControlFlow/CallGraphAnalysisType.h" #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h" @@ -24,27 +23,22 @@ #include "phasar/Utils/MaybeUniquePtr.h" #include "phasar/Utils/PAMMMacros.h" #include "phasar/Utils/Soundness.h" -#include "phasar/Utils/TypeTraits.h" -#include "phasar/Utils/Utilities.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instruction.h" #include "llvm/Support/ErrorHandling.h" -#include #include namespace psr { struct LLVMBasedICFG::Builder { LLVMProjectIRDB *IRDB = nullptr; - LLVMAliasInfoRef PT{}; LLVMTypeHierarchy *TH{}; + Resolver *Res = nullptr; CallGraphBuilder CGBuilder{}; - std::unique_ptr Res = nullptr; llvm::DenseSet VisitedFunctions{}; llvm::SmallVector UserEntryPoints{}; @@ -321,6 +315,28 @@ bool LLVMBasedICFG::Builder::constructDynamicCall(const llvm::Instruction *CS) { return NewTargetsFound; } +void LLVMBasedICFG::initialize(LLVMProjectIRDB *IRDB, Resolver &CGResolver, + llvm::ArrayRef EntryPoints, + LLVMTypeHierarchy *TH, Soundness S, + bool IncludeGlobals) { + Builder B{IRDB, this->TH.get(), &CGResolver}; + + B.initEntryPoints(EntryPoints); + B.initGlobalsAndWorkList(this, IncludeGlobals); + + PHASAR_LOG_LEVEL_CAT( + INFO, "LLVMBasedICFG", + "Starting ICFG construction " + << std::chrono::steady_clock::now().time_since_epoch().count()); + + this->CG = B.buildCallGraph(S); + + PHASAR_LOG_LEVEL_CAT( + INFO, "LLVMBasedICFG", + "Finished ICFG construction " + << std::chrono::steady_clock::now().time_since_epoch().count()); +} + LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB, CallGraphAnalysisType CGType, llvm::ArrayRef EntryPoints, @@ -333,29 +349,29 @@ LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB, this->TH = std::make_unique(*IRDB); } - Builder B{IRDB, PT, this->TH.get()}; LLVMAliasInfo PTOwn; if (!PT && CGType == CallGraphAnalysisType::OTF) { PTOwn = std::make_unique(IRDB); - B.PT = PTOwn.asRef(); + PT = PTOwn.asRef(); } - B.Res = Resolver::create(CGType, IRDB, this->TH.get(), this, B.PT); - B.initEntryPoints(EntryPoints); - B.initGlobalsAndWorkList(this, IncludeGlobals); + auto CGRes = Resolver::create(CGType, IRDB, this->TH.get(), PT); + initialize(IRDB, *CGRes, EntryPoints, TH, S, IncludeGlobals); +} - PHASAR_LOG_LEVEL_CAT( - INFO, "LLVMBasedICFG", - "Starting ICFG construction " - << std::chrono::steady_clock::now().time_since_epoch().count()); +LLVMBasedICFG::LLVMBasedICFG(LLVMProjectIRDB *IRDB, Resolver &CGResolver, + llvm::ArrayRef EntryPoints, + LLVMTypeHierarchy *TH, Soundness S, + bool IncludeGlobals) + : IRDB(IRDB), TH(TH) { + assert(IRDB != nullptr); - this->CG = B.buildCallGraph(S); + if (!TH) { + this->TH = std::make_unique(*IRDB); + } - PHASAR_LOG_LEVEL_CAT( - INFO, "LLVMBasedICFG", - "Finished ICFG construction " - << std::chrono::steady_clock::now().time_since_epoch().count()); + initialize(IRDB, CGResolver, EntryPoints, TH, S, IncludeGlobals); } LLVMBasedICFG::LLVMBasedICFG(CallGraph CG, LLVMProjectIRDB *IRDB, diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp index 347399716..261ea90ed 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/OTFResolver.cpp @@ -16,8 +16,6 @@ #include "phasar/Utils/Logger.h" #include "phasar/Utils/Utilities.h" -#include "llvm/ADT/DenseMapInfo.h" -#include "llvm/ADT/Hashing.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/Constants.h" @@ -27,17 +25,14 @@ #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" -#include "llvm/IR/Operator.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" -#include - using namespace psr; OTFResolver::OTFResolver(LLVMProjectIRDB &IRDB, LLVMTypeHierarchy &TH, - LLVMBasedICFG &ICF, LLVMAliasInfoRef PT) - : Resolver(IRDB, TH), ICF(ICF), PT(PT) {} + LLVMAliasInfoRef PT) + : Resolver(IRDB, TH), PT(PT) {} void OTFResolver::preCall(const llvm::Instruction *Inst) {} @@ -60,7 +55,7 @@ void OTFResolver::handlePossibleTargets(const llvm::CallBase *CallSite, } // handle return value if (CalleeTarget->getReturnType()->isPointerTy()) { - for (const auto &ExitPoint : ICF.getExitPointsOf(CalleeTarget)) { + for (const auto &ExitPoint : psr::getAllExitPoints(CalleeTarget)) { // get the function's return value if (const auto *Ret = llvm::dyn_cast(ExitPoint)) { // introduce alias to the returned value @@ -95,10 +90,6 @@ auto OTFResolver::resolveVirtualCall(const llvm::CallBase *CallSite) PHASAR_LOG_LEVEL(DEBUG, "Virtual function table entry is: " << VtableIndex); - // const llvm::Value *Receiver = CallSite->getArgOperand(0); - - const auto *FTy = CallSite->getFunctionType(); - auto PTS = PT.getAliasSet(CallSite->getCalledOperand(), CallSite); for (const auto *P : *PTS) { if (const auto *PGV = llvm::dyn_cast(P)) { diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp index 2f0b883e1..817f9a209 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/RTAResolver.cpp @@ -99,8 +99,6 @@ void RTAResolver::resolveAllocatedStructTypes() { } llvm::DenseSet AllocatedStructTypes; - const llvm::StringSet<> MemAllocatingFunctions = {"_Znwm", "_Znam", "malloc", - "calloc", "realloc"}; for (const auto *Fun : IRDB.getAllFunctions()) { for (const auto &Inst : llvm::instructions(Fun)) { @@ -114,8 +112,7 @@ void RTAResolver::resolveAllocatedStructTypes() { // check if an instance of a user-defined type is allocated on the // heap - if (!MemAllocatingFunctions.contains( - CallSite->getCalledFunction()->getName())) { + if (!isHeapAllocatingFunction(CallSite->getCalledFunction())) { continue; } /// TODO: Does this iteration over the users make sense? diff --git a/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp b/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp index fbb08a957..0beb6d174 100644 --- a/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp +++ b/lib/PhasarLLVM/ControlFlow/Resolver/Resolver.cpp @@ -145,7 +145,7 @@ auto Resolver::resolveFunctionPointer(const llvm::CallBase *CallSite) FunctionSetTy CalleeTargets; for (const auto *F : IRDB.getAllFunctions()) { - if (isConsistentCall(CallSite, F)) { + if (F->hasAddressTaken() && isConsistentCall(CallSite, F)) { CalleeTargets.insert(F); } } @@ -158,7 +158,6 @@ void Resolver::otherInst(const llvm::Instruction *Inst) {} std::unique_ptr Resolver::create(CallGraphAnalysisType Ty, LLVMProjectIRDB *IRDB, LLVMTypeHierarchy *TH, - LLVMBasedICFG *ICF, LLVMAliasInfoRef PT) { assert(IRDB != nullptr); @@ -179,9 +178,8 @@ std::unique_ptr Resolver::create(CallGraphAnalysisType Ty, "The VTA callgraph algorithm is not implemented yet"); case CallGraphAnalysisType::OTF: assert(TH != nullptr); - assert(ICF != nullptr); assert(PT); - return std::make_unique(*IRDB, *TH, *ICF, PT); + return std::make_unique(*IRDB, *TH, PT); case CallGraphAnalysisType::Invalid: llvm::report_fatal_error("Invalid callgraph algorithm specified"); } diff --git a/lib/PhasarLLVM/DB/CMakeLists.txt b/lib/PhasarLLVM/DB/CMakeLists.txt index 5c89b3aa6..bb6e3c396 100644 --- a/lib/PhasarLLVM/DB/CMakeLists.txt +++ b/lib/PhasarLLVM/DB/CMakeLists.txt @@ -4,7 +4,6 @@ add_phasar_library(phasar_llvm_db ${PSR_LLVM_DB_SRC} LINKS - phasar_db phasar_utils phasar_llvm_utils diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt b/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt index 9411bc739..327eb03af 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/CMakeLists.txt @@ -11,7 +11,6 @@ add_phasar_library(phasar_llvm_ifdside phasar_llvm_typehierarchy phasar_llvm_controlflow phasar_llvm_utils - phasar_db phasar_taintconfig LLVM_LINK_COMPONENTS diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp index b49ecb872..7ce08382f 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp @@ -29,12 +29,15 @@ #include "phasar/Utils/Logger.h" #include "llvm/Demangle/Demangle.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instructions.h" #include "llvm/Support/Casting.h" #include "llvm/Support/raw_ostream.h" +#include + namespace psr { using namespace glca; @@ -669,11 +672,17 @@ bool IDEGeneralizedLCA::isEntryPoint(const std::string &Name) const { } bool IDEGeneralizedLCA::isStringConstructor(const llvm::Function *F) { - return (ICF->getSpecialMemberFunctionType(F) == - SpecialMemberFunctionType::Constructor && - llvm::demangle(F->getName().str()) - .find("::allocator >::basic_string") != - std::string::npos); + if (ICF->getSpecialMemberFunctionType(F) != + SpecialMemberFunctionType::Constructor) { + return false; + } + + static const std::regex StringCtorRex( + "::basic_string[[:space:]]?>\\(", + std::regex::extended | std::regex::nosubs | std::regex::optimize); + + auto DName = llvm::demangle(F->getName().str()); + return std::regex_search(DName, StringCtorRex); } } // namespace psr diff --git a/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt b/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt index 7c7d00bf9..4bbda6173 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt +++ b/lib/PhasarLLVM/DataFlow/Mono/CMakeLists.txt @@ -8,7 +8,6 @@ add_phasar_library(phasar_mono phasar_utils phasar_llvm_utils phasar_llvm_controlflow - phasar_db phasar_taintconfig LLVM_LINK_COMPONENTS diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp index ca19e4c6f..b2c2365b9 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/InterMonoFullConstantPropagation.cpp @@ -16,6 +16,7 @@ #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/BitVectorSet.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" diff --git a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp index 2c415cd17..41aeb91a4 100644 --- a/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp +++ b/lib/PhasarLLVM/DataFlow/Mono/Problems/IntraMonoFullConstantPropagation.cpp @@ -17,6 +17,7 @@ #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/BitVectorSet.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Value.h" diff --git a/lib/PhasarLLVM/Pointer/CMakeLists.txt b/lib/PhasarLLVM/Pointer/CMakeLists.txt index c189f6153..35cabf8af 100644 --- a/lib/PhasarLLVM/Pointer/CMakeLists.txt +++ b/lib/PhasarLLVM/Pointer/CMakeLists.txt @@ -5,7 +5,6 @@ add_phasar_library(phasar_llvm_pointer LINKS phasar_utils - phasar_db phasar_pointer phasar_llvm_utils phasar_llvm_db diff --git a/lib/PhasarLLVM/Pointer/LLVMBasedAliasAnalysis.cpp b/lib/PhasarLLVM/Pointer/LLVMBasedAliasAnalysis.cpp index c41bb3347..bf5ad618c 100644 --- a/lib/PhasarLLVM/Pointer/LLVMBasedAliasAnalysis.cpp +++ b/lib/PhasarLLVM/Pointer/LLVMBasedAliasAnalysis.cpp @@ -24,6 +24,7 @@ #include "llvm/IR/BasicBlock.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" +#include "llvm/IR/InstIterator.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Value.h" diff --git a/lib/PhasarLLVM/Pointer/external/llvm/CFLGraph.h b/lib/PhasarLLVM/Pointer/external/llvm/CFLGraph.h index 1e50223cb..c3e53c114 100644 --- a/lib/PhasarLLVM/Pointer/external/llvm/CFLGraph.h +++ b/lib/PhasarLLVM/Pointer/external/llvm/CFLGraph.h @@ -436,7 +436,13 @@ template class CFLGraphBuilder { // introduce any aliases. // TODO: address other common library functions such as realloc(), // strdup(), etc. - if (isMallocOrCallocLikeFn(&Call, &TLI) || isFreeCall(&Call, &TLI)) + if (isMallocOrCallocLikeFn(&Call, &TLI) || +#if LLVM_VERSION_MAJOR >= 15 + getFreedOperand(&Call, &TLI) +#else + isFreeCall(&Call, &TLI) +#endif + ) return; // TODO: Add support for noalias args/all the other fun function diff --git a/lib/PhasarLLVM/TaintConfig/CMakeLists.txt b/lib/PhasarLLVM/TaintConfig/CMakeLists.txt index 1a801938f..e3a9050f3 100644 --- a/lib/PhasarLLVM/TaintConfig/CMakeLists.txt +++ b/lib/PhasarLLVM/TaintConfig/CMakeLists.txt @@ -5,7 +5,6 @@ add_phasar_library(phasar_taintconfig LINKS phasar_utils - phasar_db phasar_llvm_db phasar_llvm_utils phasar_controlflow diff --git a/lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp b/lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp index 99a1a277e..c7465cdd8 100644 --- a/lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp +++ b/lib/PhasarLLVM/TaintConfig/LLVMTaintConfig.cpp @@ -16,6 +16,7 @@ #include "phasar/PhasarLLVM/Utils/LLVMShorthands.h" #include "phasar/Utils/Logger.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/Function.h" #include "llvm/IR/InstIterator.h" diff --git a/lib/PhasarLLVM/Utils/LLVMShorthands.cpp b/lib/PhasarLLVM/Utils/LLVMShorthands.cpp index 82ba97330..99f809513 100644 --- a/lib/PhasarLLVM/Utils/LLVMShorthands.cpp +++ b/lib/PhasarLLVM/Utils/LLVMShorthands.cpp @@ -21,8 +21,10 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instruction.h" diff --git a/lib/Pointer/CMakeLists.txt b/lib/Pointer/CMakeLists.txt index 5c2f8d43e..4695aeb0a 100644 --- a/lib/Pointer/CMakeLists.txt +++ b/lib/Pointer/CMakeLists.txt @@ -6,7 +6,6 @@ add_phasar_library(phasar_pointer LINKS phasar_utils - phasar_db LLVM_LINK_COMPONENTS Support diff --git a/unittests/DB/CMakeLists.txt b/unittests/DB/CMakeLists.txt index d3b224e01..87e1de139 100644 --- a/unittests/DB/CMakeLists.txt +++ b/unittests/DB/CMakeLists.txt @@ -1,7 +1,9 @@ -set(DBSources - HexastoreTest.cpp -) +if(SQLite3_FOUND) + set(DBSources + HexastoreTest.cpp + ) -foreach(TEST_SRC ${DBSources}) - add_phasar_unittest(${TEST_SRC}) -endforeach(TEST_SRC) + foreach(TEST_SRC ${DBSources}) + add_phasar_unittest(${TEST_SRC}) + endforeach(TEST_SRC) +endif() diff --git a/utils/InstallAptDependencies.sh b/utils/InstallAptDependencies.sh index 37bc530c6..8dba455bc 100755 --- a/utils/InstallAptDependencies.sh +++ b/utils/InstallAptDependencies.sh @@ -3,4 +3,4 @@ set -e sudo apt-get update sudo apt-get install git -y -sudo apt-get install zlib1g-dev sqlite3 libsqlite3-dev python3 doxygen python3-pip g++ ninja-build cmake -y +sudo apt-get install zlib1g-dev python3 python3-pip g++ ninja-build cmake -y