Skip to content

Commit

Permalink
Fix backwards ICFG (not all required interface functions were impleme…
Browse files Browse the repository at this point in the history
…nted) + use explicit template instantiation to make sure, the interface is fully implemented in the future
  • Loading branch information
fabianbs96 committed Aug 18, 2023
1 parent 1b28878 commit 90d28c2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
16 changes: 5 additions & 11 deletions include/phasar/ControlFlow/ICFGBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,7 @@ template <typename Derived> class ICFGBase {
n_t>);
return self().getReturnSitesOfCallAtImpl(Inst);
}
/// Returns an iterable range of all global initializer functions
[[nodiscard]] decltype(auto)
getGlobalInitializers(ByConstRef<f_t> Fun) const {
static_assert(
is_iterable_over_v<decltype(self().getGlobalInitializersImpl(Fun)),
f_t>);
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);
Expand All @@ -128,9 +121,10 @@ template <typename Derived> class ICFGBase {
/// from the given analysis-Domain
template <typename ICF, typename Domain>
// NOLINTNEXTLINE(readability-identifier-naming)
constexpr bool is_icfg_v = is_crtp_base_of_v<ICFGBase, ICF>
&&std::is_same_v<typename ICF::n_t, typename Domain::n_t>
&&std::is_same_v<typename ICF::f_t, typename Domain::f_t>;
constexpr bool is_icfg_v =
is_crtp_base_of_v<ICFGBase, ICF> &&
std::is_same_v<typename ICF::n_t, typename Domain::n_t> &&
std::is_same_v<typename ICF::f_t, typename Domain::f_t>;

} // namespace psr

Expand Down
10 changes: 9 additions & 1 deletion include/phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
namespace psr {

class LLVMBasedICFG;
class LLVMBasedBackwardICFG;
template <typename N, typename F> class CallGraph;

template <>
struct CFGTraits<LLVMBasedBackwardICFG> : CFGTraits<LLVMBasedBackwardCFG> {};

class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,
public ICFGBase<LLVMBasedBackwardCFG> {
public ICFGBase<LLVMBasedBackwardICFG> {
friend ICFGBase;

class LLVMBackwardRet {
Expand Down Expand Up @@ -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<n_t, f_t> &getCallGraphImpl() const noexcept;

llvm::LLVMContext BackwardRetsCtx;
llvm::DenseMap<const llvm::Function *, LLVMBackwardRet> BackwardRets;
Expand All @@ -68,6 +74,8 @@ class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,

LLVMBasedICFG *ForwardICFG{};
};

extern template class ICFGBase<LLVMBasedBackwardICFG>;
} // namespace psr

#endif
2 changes: 2 additions & 0 deletions include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
LLVMProjectIRDB *IRDB = nullptr;
MaybeUniquePtr<LLVMTypeHierarchy, true> TH;
};

extern template class ICFGBase<LLVMBasedICFG>;
} // namespace psr

#endif
9 changes: 8 additions & 1 deletion lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h"

#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h"
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"

namespace psr {
Expand Down Expand Up @@ -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<n_t, f_t> & {
return ForwardICFG->getCallGraph();
}

template class ICFGBase<LLVMBasedBackwardICFG>;

} // namespace psr
2 changes: 2 additions & 0 deletions lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,6 @@ void LLVMBasedICFG::printImpl(llvm::raw_ostream &OS) const {
[this](n_t Inst) { return IRDB->getInstructionId(Inst); });
}

template class ICFGBase<LLVMBasedICFG>;

} // namespace psr

0 comments on commit 90d28c2

Please sign in to comment.