Skip to content

Commit 33a4042

Browse files
committed
minor
1 parent b0d8a8b commit 33a4042

File tree

6 files changed

+35
-24
lines changed

6 files changed

+35
-24
lines changed

examples/how-to/04-run-ifds-analysis/otf-reporter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
namespace {
99
/// A listener that gets notified, whenever the taint analysis detects a leak
10+
///
11+
/// Checkout the analysis-printers that are already provided by PhASAR:
12+
/// - "phasar/Utils/OnTheFlyReporter.h"
13+
/// - "phasar/PhasarLLVM/Utils/LLVMAnalysisPrinter.h"
14+
/// - "phasar/PhasarLLVM/Utils/SourceMgrPrinter.h"
1015
class LeakReporter
1116
: public psr::AnalysisPrinterBase<psr::LLVMIFDSAnalysisDomainDefault> {
1217

include/phasar/DataFlow/IfdsIde/IDETabulationProblem.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "phasar/DataFlow/IfdsIde/Solver/GenericSolverResults.h"
2121
#include "phasar/Utils/DefaultAnalysisPrinterSelector.h"
2222
#include "phasar/Utils/JoinLattice.h"
23+
#include "phasar/Utils/Macros.h"
2324
#include "phasar/Utils/MaybeUniquePtr.h"
2425
#include "phasar/Utils/NullAnalysisPrinter.h"
2526
#include "phasar/Utils/SemiRing.h"
@@ -186,17 +187,17 @@ class IDETabulationProblem : public FlowFunctions<AnalysisDomainTy, Container>,
186187
std::move(FactToGenerate), getZeroValue());
187188
}
188189

189-
template <typename L = l_t>
190-
std::enable_if_t<!std::is_same_v<std::decay_t<L>, psr::BinaryDomain>>
191-
onResult(n_t Instr, d_t DfFact, l_t LatticeElement,
192-
DataFlowAnalysisType AnalysisType) {
193-
Printer->onResult(Instr, std::move(DfFact), std::move(LatticeElement),
190+
template <typename D = d_t, typename L = l_t>
191+
void onResult(n_t Instr, D &&DfFact, L &&LatticeElement,
192+
DataFlowAnalysisType AnalysisType) {
193+
Printer->onResult(Instr, PSR_FWD(DfFact), PSR_FWD(LatticeElement),
194194
AnalysisType);
195195
}
196-
template <typename L = l_t>
197-
std::enable_if_t<std::is_same_v<std::decay_t<L>, psr::BinaryDomain>>
198-
onResult(n_t Instr, d_t DfFact, DataFlowAnalysisType AnalysisType) {
199-
Printer->onResult(Instr, std::move(DfFact), AnalysisType);
196+
197+
template <typename D = d_t, typename L = l_t>
198+
std::enable_if_t<std::is_same_v<L, psr::BinaryDomain>>
199+
onResult(n_t Instr, D &&DfFact, DataFlowAnalysisType AnalysisType) {
200+
Printer->onResult(Instr, PSR_FWD(DfFact), AnalysisType);
200201
}
201202

202203
/// Seeds that just start with ZeroValue and bottomElement() at the starting

include/phasar/PhasarLLVM/Utils/LLVMAnalysisPrinter.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@ class DefaultLLVMAnalysisPrinter
2424
DefaultLLVMAnalysisPrinter() noexcept = default;
2525

2626
private:
27-
template <typename D = d_t>
2827
static std::optional<DebugLocation> getDbgLoc(n_t Instr,
2928
ByConstRef<d_t> DfFact) {
3029
auto Ret = getDebugLocation(Instr);
31-
if constexpr (std::is_convertible_v<ByConstRef<D>, const llvm::Value *>) {
30+
if constexpr (std::is_convertible_v<ByConstRef<d_t>, const llvm::Value *>) {
3231
if (!Ret) {
3332
Ret = getDebugLocation(static_cast<const llvm::Value *>(DfFact));
3433
}
3534
}
3635
return Ret;
3736
}
38-
template <typename D = d_t>
37+
3938
void printVariables(llvm::raw_ostream &OS,
4039
llvm::ArrayRef<Warning<AnalysisDomainTy>> Results) {
41-
if constexpr (std::is_convertible_v<const D &, const llvm::Value *>) {
40+
if constexpr (std::is_convertible_v<const d_t &, const llvm::Value *>) {
4241
bool HasVariable = false;
4342
for (const auto &Warn : Results) {
4443
if (auto VarName = getVarNameFromIR(Warn.Fact); !VarName.empty()) {
@@ -102,6 +101,8 @@ class DefaultLLVMAnalysisPrinter
102101
}
103102
OS << '\n';
104103
}
104+
105+
DbgResultsEntries.clear();
105106
NonDbgResultsEntries.clear();
106107
}
107108

include/phasar/Utils/AnalysisPrinterBase.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "phasar/Domain/BinaryDomain.h"
55
#include "phasar/PhasarLLVM/Utils/DataFlowAnalysisType.h"
6+
#include "phasar/Utils/Macros.h"
67

78
#include "llvm/Support/raw_ostream.h"
89

@@ -18,17 +19,16 @@ template <typename AnalysisDomainTy> class AnalysisPrinterBase {
1819
using l_t = typename AnalysisDomainTy::l_t;
1920

2021
public:
21-
template <typename L = l_t, typename = std::enable_if_t<!std::is_same_v<
22-
std::decay_t<L>, psr::BinaryDomain>>>
23-
void onResult(n_t Instr, d_t DfFact, l_t LatticeElement,
22+
template <typename D = d_t, typename L = l_t>
23+
void onResult(n_t Instr, D &&DfFact, L &&LatticeElement,
2424
DataFlowAnalysisType AnalysisType) {
25-
doOnResult(Instr, DfFact, LatticeElement, AnalysisType);
25+
doOnResult(Instr, PSR_FWD(DfFact), PSR_FWD(LatticeElement), AnalysisType);
2626
}
2727

28-
template <typename L = l_t, typename = std::enable_if_t<std::is_same_v<
29-
std::decay_t<L>, psr::BinaryDomain>>>
30-
void onResult(n_t Instr, d_t DfFact, DataFlowAnalysisType AnalysisType) {
31-
doOnResult(Instr, DfFact, psr::BinaryDomain::BOTTOM, AnalysisType);
28+
template <typename D = d_t, typename L = l_t>
29+
std::enable_if_t<std::is_same_v<L, psr::BinaryDomain>>
30+
onResult(n_t Instr, D &&DfFact, DataFlowAnalysisType AnalysisType) {
31+
doOnResult(Instr, PSR_FWD(DfFact), psr::BinaryDomain::BOTTOM, AnalysisType);
3232
}
3333

3434
void onInitialize() { doOnInitialize(); }
@@ -38,6 +38,7 @@ template <typename AnalysisDomainTy> class AnalysisPrinterBase {
3838

3939
AnalysisPrinterBase() = default;
4040
virtual ~AnalysisPrinterBase() = default;
41+
4142
AnalysisPrinterBase(const AnalysisPrinterBase &) = delete;
4243
AnalysisPrinterBase &operator=(const AnalysisPrinterBase &) = delete;
4344

include/phasar/Utils/DefaultAnalysisPrinter.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "phasar/Domain/BinaryDomain.h"
55
#include "phasar/Utils/AnalysisPrinterBase.h"
6+
#include "phasar/Utils/ByRef.h"
67
#include "phasar/Utils/Printer.h"
78

89
#include "llvm/Support/raw_ostream.h"
@@ -22,9 +23,10 @@ template <typename AnalysisDomainTy> struct Warning {
2223
l_t LatticeElement;
2324
DataFlowAnalysisType AnalysisType;
2425

25-
// Constructor
26-
Warning(n_t Inst, d_t DfFact, l_t Lattice,
27-
DataFlowAnalysisType DfAnalysisType)
26+
// Constructor -- With C++20, we can get rid of it; then the below
27+
// emplace_back works on aggregates too
28+
constexpr Warning(n_t Inst, ByMoveRef<d_t> DfFact, ByMoveRef<l_t> Lattice,
29+
DataFlowAnalysisType DfAnalysisType) noexcept
2830
: Instr(std::move(Inst)), Fact(std::move(DfFact)),
2931
LatticeElement(std::move(Lattice)), AnalysisType(DfAnalysisType) {}
3032
};

include/phasar/Utils/OnTheFlyAnalysisPrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "llvm/Support/raw_ostream.h"
1212

1313
#include <cassert>
14+
1415
namespace psr {
1516

1617
/// This class implements the AnalysisPrinterBase that prints the analysis

0 commit comments

Comments
 (0)