Skip to content

Commit e5c5c69

Browse files
committed
allow further comparison operator for LatticeDomain
1 parent 1939bca commit e5c5c69

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

include/phasar/PhasarLLVM/Utils/LatticeDomain.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
#ifndef PHASAR_PHASARLLVM_UTILS_LATTICEDOMAIN_H
1111
#define PHASAR_PHASARLLVM_UTILS_LATTICEDOMAIN_H
1212

13-
#include "llvm/Support/ErrorHandling.h"
14-
#include "llvm/Support/raw_ostream.h"
15-
1613
#include <iostream>
1714
#include <type_traits>
1815
#include <variant>
1916

17+
#include "llvm/Support/ErrorHandling.h"
18+
#include "llvm/Support/raw_ostream.h"
19+
20+
#include "phasar/Utils/TypeTraits.h"
21+
2022
namespace psr {
2123

2224
/// Represents the infimum of the lattice:
@@ -119,6 +121,17 @@ inline bool operator==(const LatticeDomain<L> Lhs, const LL &Rhs) {
119121
return Rhs == Lhs;
120122
}
121123

124+
template <typename L, typename M>
125+
inline bool operator==(const L &Lhs, const M &Rhs) {
126+
if constexpr (is_variant_v<L>) {
127+
return Lhs == std::variant<M>(Rhs);
128+
}
129+
if constexpr (is_variant_v<M>) {
130+
return std::variant<L>(Lhs) == Rhs;
131+
}
132+
return Lhs == Rhs;
133+
}
134+
122135
template <typename L>
123136
inline bool operator!=(const LatticeDomain<L> &Lhs,
124137
const LatticeDomain<L> &Rhs) {

include/phasar/Utils/TypeTraits.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <ostream>
1414
#include <tuple>
1515
#include <type_traits>
16+
#include <variant>
1617

1718
#include "llvm/Support/raw_ostream.h"
1819

@@ -109,6 +110,15 @@ constexpr bool is_std_hashable_v = detail::is_std_hashable<T>::value; // NOLINT
109110
template <typename T>
110111
constexpr bool is_llvm_hashable_v = // NOLINT
111112
detail::is_llvm_hashable<T>::value;
113+
114+
template <typename T> struct is_variant : std::false_type {}; // NOLINT
115+
116+
template <typename... Args>
117+
struct is_variant<std::variant<Args...>> : std::true_type {}; // NOLINT
118+
119+
template <typename T>
120+
inline constexpr bool is_variant_v = is_variant<T>::value; // NOLINT
121+
112122
// NOLINTEND(readability-identifier-naming)
113123
} // namespace psr
114124

lib/PhasarLLVM/DataFlowSolver/Mono/Problems/InterMonoSolverTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ InterMonoSolverTest::callFlow(InterMonoSolverTest::n_t CallSite,
6767
const InterMonoSolverTest::mono_container_t &In) {
6868
cout << "InterMonoSolverTest::callFlow()\n";
6969
InterMonoSolverTest::mono_container_t Result;
70-
Result.setUnion(In);
70+
Result = Result.setUnion(In);
7171
if (const auto *const Call = llvm::dyn_cast<llvm::CallInst>(CallSite)) {
7272
Result.insert(Call);
7373
}

0 commit comments

Comments
 (0)