From 90d28c291a6567ab484dc64335fb9ffb5d6f0dc8 Mon Sep 17 00:00:00 2001 From: Fabian Schiebel Date: Fri, 18 Aug 2023 13:33:40 +0200 Subject: [PATCH] Fix backwards ICFG (not all required interface functions were implemented) + use explicit template instantiation to make sure, the interface is fully implemented in the future --- include/phasar/ControlFlow/ICFGBase.h | 16 +++++----------- .../ControlFlow/LLVMBasedBackwardICFG.h | 10 +++++++++- .../PhasarLLVM/ControlFlow/LLVMBasedICFG.h | 2 ++ .../ControlFlow/LLVMBasedBackwardICFG.cpp | 9 ++++++++- lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp | 2 ++ 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/phasar/ControlFlow/ICFGBase.h b/include/phasar/ControlFlow/ICFGBase.h index 1f62fb69a..619bffb07 100644 --- a/include/phasar/ControlFlow/ICFGBase.h +++ b/include/phasar/ControlFlow/ICFGBase.h @@ -101,14 +101,7 @@ template class ICFGBase { n_t>); return self().getReturnSitesOfCallAtImpl(Inst); } - /// Returns an iterable range of all global initializer functions - [[nodiscard]] decltype(auto) - getGlobalInitializers(ByConstRef Fun) const { - static_assert( - is_iterable_over_v); - return self().getGlobalInitializersImpl(Fun); - } + /// Prints the underlying call-graph as DOT to the given output-stream void print(llvm::raw_ostream &OS = llvm::outs()) const { self().printImpl(OS); @@ -128,9 +121,10 @@ template class ICFGBase { /// from the given analysis-Domain template // NOLINTNEXTLINE(readability-identifier-naming) -constexpr bool is_icfg_v = is_crtp_base_of_v - &&std::is_same_v - &&std::is_same_v; +constexpr bool is_icfg_v = + is_crtp_base_of_v && + std::is_same_v && + std::is_same_v; } // namespace psr diff --git a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h index 10a342488..101718a42 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h +++ b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h @@ -19,9 +19,14 @@ namespace psr { class LLVMBasedICFG; +class LLVMBasedBackwardICFG; +template class CallGraph; + +template <> +struct CFGTraits : CFGTraits {}; class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG, - public ICFGBase { + public ICFGBase { friend ICFGBase; class LLVMBackwardRet { @@ -60,6 +65,7 @@ class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG, getReturnSitesOfCallAtImpl(n_t Inst) const; void printImpl(llvm::raw_ostream &OS) const; [[nodiscard]] nlohmann::json getAsJsonImpl() const; + [[nodiscard]] const CallGraph &getCallGraphImpl() const noexcept; llvm::LLVMContext BackwardRetsCtx; llvm::DenseMap BackwardRets; @@ -68,6 +74,8 @@ class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG, LLVMBasedICFG *ForwardICFG{}; }; + +extern template class ICFGBase; } // namespace psr #endif diff --git a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h index e2171a31a..07e4ff8fb 100644 --- a/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h +++ b/include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h @@ -150,6 +150,8 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase { LLVMProjectIRDB *IRDB = nullptr; MaybeUniquePtr TH; }; + +extern template class ICFGBase; } // namespace psr #endif diff --git a/lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp b/lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp index 6edadac34..0ca199d25 100644 --- a/lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp +++ b/lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp @@ -9,7 +9,6 @@ #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h" -#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h" #include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h" namespace psr { @@ -68,4 +67,12 @@ void LLVMBasedBackwardICFG::printImpl(llvm::raw_ostream &OS) const { nlohmann::json LLVMBasedBackwardICFG::getAsJsonImpl() const { return ForwardICFG->getAsJson(); } + +auto LLVMBasedBackwardICFG::getCallGraphImpl() const noexcept + -> const CallGraph & { + return ForwardICFG->getCallGraph(); +} + +template class ICFGBase; + } // namespace psr diff --git a/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp b/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp index 42d715c27..cb7f69df3 100644 --- a/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp +++ b/lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp @@ -443,4 +443,6 @@ void LLVMBasedICFG::printImpl(llvm::raw_ostream &OS) const { [this](n_t Inst) { return IRDB->getInstructionId(Inst); }); } +template class ICFGBase; + } // namespace psr