Skip to content

Commit 94a0e47

Browse files
authored
Fix Backward ICFG (#660)
* 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 * pre-commit
1 parent 76fe080 commit 94a0e47

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

include/phasar/ControlFlow/ICFGBase.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,7 @@ template <typename Derived> class ICFGBase {
101101
n_t>);
102102
return self().getReturnSitesOfCallAtImpl(Inst);
103103
}
104-
/// Returns an iterable range of all global initializer functions
105-
[[nodiscard]] decltype(auto)
106-
getGlobalInitializers(ByConstRef<f_t> Fun) const {
107-
static_assert(
108-
is_iterable_over_v<decltype(self().getGlobalInitializersImpl(Fun)),
109-
f_t>);
110-
return self().getGlobalInitializersImpl(Fun);
111-
}
104+
112105
/// Prints the underlying call-graph as DOT to the given output-stream
113106
void print(llvm::raw_ostream &OS = llvm::outs()) const {
114107
self().printImpl(OS);

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919
namespace psr {
2020

2121
class LLVMBasedICFG;
22+
class LLVMBasedBackwardICFG;
23+
template <typename N, typename F> class CallGraph;
24+
25+
template <>
26+
struct CFGTraits<LLVMBasedBackwardICFG> : CFGTraits<LLVMBasedBackwardCFG> {};
2227

2328
class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,
24-
public ICFGBase<LLVMBasedBackwardCFG> {
29+
public ICFGBase<LLVMBasedBackwardICFG> {
2530
friend ICFGBase;
2631

2732
class LLVMBackwardRet {
@@ -60,6 +65,7 @@ class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,
6065
getReturnSitesOfCallAtImpl(n_t Inst) const;
6166
void printImpl(llvm::raw_ostream &OS) const;
6267
[[nodiscard]] nlohmann::json getAsJsonImpl() const;
68+
[[nodiscard]] const CallGraph<n_t, f_t> &getCallGraphImpl() const noexcept;
6369

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

6975
LLVMBasedICFG *ForwardICFG{};
7076
};
77+
78+
extern template class ICFGBase<LLVMBasedBackwardICFG>;
7179
} // namespace psr
7280

7381
#endif

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
162162
LLVMProjectIRDB *IRDB = nullptr;
163163
MaybeUniquePtr<LLVMTypeHierarchy, true> TH;
164164
};
165+
166+
extern template class ICFGBase<LLVMBasedICFG>;
165167
} // namespace psr
166168

167169
#endif

lib/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

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

12-
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h"
1312
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
1413

1514
namespace psr {
@@ -68,4 +67,12 @@ void LLVMBasedBackwardICFG::printImpl(llvm::raw_ostream &OS) const {
6867
nlohmann::json LLVMBasedBackwardICFG::getAsJsonImpl() const {
6968
return ForwardICFG->getAsJson();
7069
}
70+
71+
auto LLVMBasedBackwardICFG::getCallGraphImpl() const noexcept
72+
-> const CallGraph<n_t, f_t> & {
73+
return ForwardICFG->getCallGraph();
74+
}
75+
76+
template class ICFGBase<LLVMBasedBackwardICFG>;
77+
7178
} // namespace psr

lib/PhasarLLVM/ControlFlow/LLVMBasedICFG.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,6 @@ void LLVMBasedICFG::printImpl(llvm::raw_ostream &OS) const {
457457
[this](n_t Inst) { return IRDB->getInstructionId(Inst); });
458458
}
459459

460+
template class ICFGBase<LLVMBasedICFG>;
461+
460462
} // namespace psr

0 commit comments

Comments
 (0)