Skip to content

Commit a5c611a

Browse files
authored
GCC Compatibility (#787)
* Make phasar compile with gcc (g++-11) and uncover (and fix) two bugs related to json ser/de with LLVMAliasSet and LLVMBasedICFG that were not detected untio now, because of nlohmann's implicit conversions feature * Address review comments * Simplify isLLVMZeroValue according to the discussion in #787
1 parent 10483a3 commit a5c611a

28 files changed

+149
-73
lines changed

include/phasar/ControlFlow/CallGraphBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ template <typename Derived> class CallGraphBase : public CRTPBase<Derived> {
3737
/// NOTE: This function is typically called in a hot part of the analysis and
3838
/// should therefore be very fast
3939
[[nodiscard]] decltype(auto) getCalleesOfCallAt(ByConstRef<n_t> Inst) const
40-
noexcept(noexcept(self().getCalleesOfCallAtImpl(Inst))) {
40+
noexcept(noexcept(this->self().getCalleesOfCallAtImpl(Inst))) {
4141
static_assert(
4242
is_iterable_over_v<decltype(self().getCalleesOfCallAtImpl(Inst)), f_t>);
4343
return self().getCalleesOfCallAtImpl(Inst);
@@ -47,7 +47,7 @@ template <typename Derived> class CallGraphBase : public CRTPBase<Derived> {
4747
/// call the given function induced by the used call-graph.
4848
[[nodiscard]] decltype(auto) getCallersOf(ByConstRef<f_t> Fun) const {
4949
static_assert(
50-
is_iterable_over_v<decltype(self().getCallersOfImpl(Fun)), n_t>);
50+
is_iterable_over_v<decltype(this->self().getCallersOfImpl(Fun)), n_t>);
5151
return self().getCallersOfImpl(Fun);
5252
}
5353
};

include/phasar/DataFlow/IfdsIde/EdgeFunction.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,21 +442,32 @@ class [[clang::trivial_abi]] EdgeFunction final : EdgeFunctionBase {
442442
typename = std::enable_if_t<
443443
!std::is_same_v<EdgeFunction, std::decay_t<ConcreteEF>> &&
444444
IsEdgeFunction<ConcreteEF>>>
445-
[[nodiscard]] friend bool operator==(EdgeFunctionRef<ConcreteEF> LHS,
446-
const EdgeFunction &RHS) noexcept {
447-
if (!RHS.template isa<ConcreteEF>()) {
445+
[[nodiscard]] bool equals(EdgeFunctionRef<ConcreteEF> Other) const noexcept {
446+
// NOTE: Workaround issue in g++ that does not allow transitive friends: If
447+
// putting this code in the operator== below, we cannot access
448+
// Other.Instance, although it is friended...
449+
if (!isa<ConcreteEF>()) {
448450
return false;
449451
}
450-
if (LHS.Instance == RHS.EF) {
452+
if (Other.Instance == EF) {
451453
return true;
452454
}
453455
if constexpr (IsEqualityComparable<ConcreteEF>) {
454-
return *LHS == *getPtr<ConcreteEF>(RHS.EF);
456+
return *Other == *getPtr<ConcreteEF>(EF);
455457
} else {
456458
return true;
457459
}
458460
}
459461

462+
template <typename ConcreteEF,
463+
typename = std::enable_if_t<
464+
!std::is_same_v<EdgeFunction, std::decay_t<ConcreteEF>> &&
465+
IsEdgeFunction<ConcreteEF>>>
466+
[[nodiscard]] friend bool operator==(EdgeFunctionRef<ConcreteEF> LHS,
467+
const EdgeFunction &RHS) noexcept {
468+
return RHS.equals(LHS);
469+
}
470+
460471
template <typename ConcreteEF,
461472
typename = std::enable_if_t<
462473
!std::is_same_v<EdgeFunction, std::decay_t<ConcreteEF>> &&

include/phasar/DataFlow/IfdsIde/FlowFunctions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ template <typename D, typename Container = std::set<D>> class FlowFunction {
7373
template <typename FF> struct IsFlowFunction {
7474
template <typename D, typename Container>
7575
static std::true_type test(const FlowFunction<D, Container> &);
76-
static std::false_type test(...) {}
76+
static std::false_type test(...);
7777

7878
static constexpr bool value = // NOLINT
7979
std::is_same_v<std::true_type,

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedBackwardICFG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class LLVMBasedBackwardICFG : public LLVMBasedBackwardCFG,
5252
LLVMBasedBackwardICFG(LLVMBasedICFG *ForwardICFG);
5353

5454
private:
55+
using typename ICFGBase::f_t;
56+
using typename ICFGBase::n_t;
57+
5558
[[nodiscard]] FunctionRange getAllFunctionsImpl() const;
5659
[[nodiscard]] f_t getFunctionImpl(llvm::StringRef Fun) const;
5760

include/phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class LLVMBasedICFG : public LLVMBasedCFG, public ICFGBase<LLVMBasedICFG> {
4848
friend ICFGBase;
4949

5050
public:
51+
using typename ICFGBase::f_t;
52+
using typename ICFGBase::n_t;
53+
5154
// For backward compatibility
5255
static constexpr llvm::StringLiteral GlobalCRuntimeModelName =
5356
GlobalCtorsDtorsModel::ModelName;

include/phasar/PhasarLLVM/ControlFlow/SparseLLVMBasedCFG.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class SparseLLVMBasedCFG : public LLVMBasedCFG,
3030
friend struct SVFGCache;
3131
friend SparseCFGBase<SparseLLVMBasedCFG>;
3232

33+
using typename LLVMBasedCFG::n_t;
34+
3335
public:
3436
using vgraph_t =
3537
llvm::SmallDenseMap<const llvm::Instruction *, const llvm::Instruction *>;

include/phasar/PhasarLLVM/ControlFlow/SparseLLVMBasedICFG.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class SparseLLVMBasedICFG
3333
friend SparseLLVMBasedCFGProvider<SparseLLVMBasedICFG>;
3434

3535
public:
36+
using typename LLVMBasedICFG::f_t;
37+
using typename LLVMBasedICFG::n_t;
38+
3639
/// Constructor that delegates all arguments to the ctor of LLVMBasedICFG
3740
explicit SparseLLVMBasedICFG(LLVMProjectIRDB *IRDB,
3841
CallGraphAnalysisType CGType,
@@ -47,7 +50,7 @@ class SparseLLVMBasedICFG
4750
LLVMAliasInfoRef PT);
4851

4952
explicit SparseLLVMBasedICFG(LLVMProjectIRDB *IRDB,
50-
const nlohmann::json &SerializedCG,
53+
const CallGraphData &SerializedCG,
5154
LLVMAliasInfoRef PT);
5255

5356
~SparseLLVMBasedICFG();

include/phasar/PhasarLLVM/ControlFlow/SparseLLVMBasedICFGView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class SparseLLVMBasedICFGView
4545
friend SparseLLVMBasedCFGProvider<SparseLLVMBasedICFGView>;
4646

4747
public:
48+
using typename LLVMBasedCFG::f_t;
49+
using typename LLVMBasedCFG::n_t;
50+
4851
explicit SparseLLVMBasedICFGView(const LLVMBasedICFG *ICF,
4952
LLVMAliasInfoRef PT);
5053

include/phasar/PhasarLLVM/DataFlow/IfdsIde/DefaultAliasAwareIDEProblem.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class DefaultAliasAwareIDEProblem
6565
protected detail::IDEAliasAwareDefaultFlowFunctionsImpl {
6666
public:
6767
using typename IDETabulationProblem<AnalysisDomainTy>::db_t;
68+
using typename IDETabulationProblem<AnalysisDomainTy>::n_t;
69+
using typename IDETabulationProblem<AnalysisDomainTy>::f_t;
70+
using typename IDETabulationProblem<AnalysisDomainTy>::d_t;
71+
using typename IDETabulationProblem<AnalysisDomainTy>::FlowFunctionPtrType;
6872

6973
using detail::IDEAliasAwareDefaultFlowFunctionsImpl::getAliasInfo;
7074

@@ -110,6 +114,11 @@ class DefaultAliasAwareIFDSProblem
110114
: public IFDSTabulationProblem<LLVMAnalysisDomainDefault>,
111115
protected detail::IDEAliasAwareDefaultFlowFunctionsImpl {
112116
public:
117+
using typename IFDSTabulationProblem::d_t;
118+
using typename IFDSTabulationProblem::f_t;
119+
using typename IFDSTabulationProblem::FlowFunctionPtrType;
120+
using typename IFDSTabulationProblem::n_t;
121+
113122
/// Constructs an IFDSTabulationProblem with the usual arguments + alias
114123
/// information.
115124
///

include/phasar/PhasarLLVM/DataFlow/IfdsIde/DefaultNoAliasIDEProblem.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class DefaultNoAliasIDEProblem
5959
public:
6060
using IDETabulationProblem<AnalysisDomainTy>::IDETabulationProblem;
6161

62+
using typename IDETabulationProblem<AnalysisDomainTy>::f_t;
63+
using typename IDETabulationProblem<AnalysisDomainTy>::FlowFunctionPtrType;
64+
using typename IDETabulationProblem<AnalysisDomainTy>::n_t;
65+
6266
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunction(n_t Curr,
6367
n_t Succ) override {
6468
return getNormalFlowFunctionImpl(Curr, Succ);
@@ -89,6 +93,12 @@ class DefaultNoAliasIFDSProblem
8993
public:
9094
using IFDSTabulationProblem::IFDSTabulationProblem;
9195

96+
using typename IFDSTabulationProblem::d_t;
97+
using typename IFDSTabulationProblem::f_t;
98+
using typename IFDSTabulationProblem::FlowFunctionPtrType;
99+
using typename IFDSTabulationProblem::l_t;
100+
using typename IFDSTabulationProblem::n_t;
101+
92102
[[nodiscard]] FlowFunctionPtrType getNormalFlowFunction(n_t Curr,
93103
n_t Succ) override {
94104
return getNormalFlowFunctionImpl(Curr, Succ);

0 commit comments

Comments
 (0)