Skip to content

Commit b5142d3

Browse files
committed
Merge remote-tracking branch 'origin/development' into f-UpdateLLVM16
2 parents acb89bd + 10483a3 commit b5142d3

30 files changed

+488
-536
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ if (NOT PHASAR_IN_TREE)
284284
FetchContent_Declare(
285285
googletest
286286
GIT_REPOSITORY https://github.com/google/googletest.git
287-
GIT_TAG v1.16.0
287+
GIT_TAG v1.17.0
288288
)
289289
FetchContent_MakeAvailable(googletest)
290290
endif()

external/json

Submodule json updated 837 files

include/phasar/DataFlow/IfdsIde/Solver/Compressor.h

Lines changed: 1 addition & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -3,158 +3,12 @@
33

44
#include "phasar/DB/ProjectIRDBBase.h"
55
#include "phasar/Utils/ByRef.h"
6-
#include "phasar/Utils/TypeTraits.h"
7-
8-
#include "llvm/ADT/DenseMap.h"
9-
#include "llvm/ADT/DenseMapInfo.h"
10-
#include "llvm/ADT/SmallVector.h"
6+
#include "phasar/Utils/Compressor.h"
117

128
#include <cstdint>
13-
#include <deque>
14-
#include <functional>
15-
#include <optional>
169
#include <type_traits>
1710

1811
namespace psr {
19-
template <typename T, typename Enable = void> class Compressor;
20-
21-
/// \brief A utility class that assigns a sequential Id to every inserted
22-
/// object.
23-
///
24-
/// This specialization handles types that can be efficiently passed by value
25-
template <typename T>
26-
class Compressor<T, std::enable_if_t<CanEfficientlyPassByValue<T>>> {
27-
public:
28-
void reserve(size_t Capacity) {
29-
assert(Capacity <= UINT32_MAX);
30-
ToInt.reserve(Capacity);
31-
FromInt.reserve(Capacity);
32-
}
33-
34-
uint32_t getOrInsert(T Elem) {
35-
auto [It, Inserted] = ToInt.try_emplace(Elem, ToInt.size());
36-
if (Inserted) {
37-
FromInt.push_back(Elem);
38-
}
39-
return It->second;
40-
}
41-
42-
std::optional<uint32_t> getOrNull(T Elem) const {
43-
if (auto It = ToInt.find(Elem); It != ToInt.end()) {
44-
return It->second;
45-
}
46-
return std::nullopt;
47-
}
48-
49-
T operator[](size_t Idx) const noexcept {
50-
assert(Idx < FromInt.size());
51-
return FromInt[Idx];
52-
}
53-
54-
[[nodiscard]] size_t size() const noexcept { return FromInt.size(); }
55-
[[nodiscard]] size_t capacity() const noexcept {
56-
return FromInt.capacity() +
57-
ToInt.getMemorySize() / sizeof(typename decltype(ToInt)::value_type);
58-
}
59-
60-
auto begin() const noexcept { return FromInt.begin(); }
61-
auto end() const noexcept { return FromInt.end(); }
62-
63-
private:
64-
llvm::DenseMap<T, uint32_t> ToInt;
65-
llvm::SmallVector<T, 0> FromInt;
66-
};
67-
68-
/// \brief A utility class that assigns a sequential Id to every inserted
69-
/// object.
70-
///
71-
/// This specialization handles types that cannot be efficiently passed by value
72-
template <typename T>
73-
class Compressor<T, std::enable_if_t<!CanEfficientlyPassByValue<T>>> {
74-
public:
75-
void reserve(size_t Capacity) {
76-
assert(Capacity <= UINT32_MAX);
77-
ToInt.reserve(Capacity);
78-
}
79-
80-
/// Returns the index of the given element in the compressors storage. If the
81-
/// element isn't present yet, it will be added first and its index will
82-
/// then be returned.
83-
uint32_t getOrInsert(const T &Elem) {
84-
if (auto It = ToInt.find(&Elem); It != ToInt.end()) {
85-
return It->second;
86-
}
87-
auto Ret = FromInt.size();
88-
auto *Ins = &FromInt.emplace_back(Elem);
89-
ToInt[Ins] = Ret;
90-
return Ret;
91-
}
92-
93-
/// Returns the index of the given element in the compressors storage. If the
94-
/// element isn't present yet, it will be added first and its index will
95-
/// then be returned.
96-
uint32_t getOrInsert(T &&Elem) {
97-
if (auto It = ToInt.find(&Elem); It != ToInt.end()) {
98-
return It->second;
99-
}
100-
auto Ret = FromInt.size();
101-
auto *Ins = &FromInt.emplace_back(std::move(Elem));
102-
ToInt[Ins] = Ret;
103-
return Ret;
104-
}
105-
106-
/// Returns the index of the given element in the compressors storage. If the
107-
/// element isn't present, std::nullopt will be returned
108-
std::optional<uint32_t> getOrNull(const T &Elem) const {
109-
if (auto It = ToInt.find(&Elem); It != ToInt.end()) {
110-
return It->second;
111-
}
112-
return std::nullopt;
113-
}
114-
115-
const T &operator[](size_t Idx) const noexcept {
116-
assert(Idx < FromInt.size());
117-
return FromInt[Idx];
118-
}
119-
120-
[[nodiscard]] size_t size() const noexcept { return FromInt.size(); }
121-
[[nodiscard]] size_t capacity() const noexcept {
122-
return FromInt.size() +
123-
ToInt.getMemorySize() / sizeof(typename decltype(ToInt)::value_type);
124-
}
125-
126-
auto begin() const noexcept { return FromInt.begin(); }
127-
auto end() const noexcept { return FromInt.end(); }
128-
129-
private:
130-
struct DSI : llvm::DenseMapInfo<const T *> {
131-
static auto getHashValue(const T *Elem) noexcept {
132-
assert(Elem != nullptr);
133-
if constexpr (has_llvm_dense_map_info<T>) {
134-
return llvm::DenseMapInfo<T>::getHashValue(*Elem);
135-
} else {
136-
return std::hash<T>{}(*Elem);
137-
}
138-
}
139-
static auto isEqual(const T *LHS, const T *RHS) noexcept {
140-
if (LHS == RHS) {
141-
return true;
142-
}
143-
if (LHS == DSI::getEmptyKey() || LHS == DSI::getTombstoneKey() ||
144-
RHS == DSI::getEmptyKey() || RHS == DSI::getTombstoneKey()) {
145-
return false;
146-
}
147-
if constexpr (has_llvm_dense_map_info<T>) {
148-
return llvm::DenseMapInfo<T>::isEqual(*LHS, *RHS);
149-
} else {
150-
return *LHS == *RHS;
151-
}
152-
}
153-
};
154-
155-
std::deque<T> FromInt;
156-
llvm::DenseMap<const T *, uint32_t, DSI> ToInt;
157-
};
15812

15913
struct NoneCompressor final {
16014
constexpr NoneCompressor() noexcept = default;

include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class IterativeIDESolver
474474
return true;
475475
}
476476

477-
auto NewEF = EF.joinWith(std::move(LocalEF));
477+
auto NewEF = Problem.combine(EF, std::move(LocalEF));
478478
assert(NewEF != nullptr);
479479

480480
if (NewEF != EF) {
@@ -540,7 +540,7 @@ class IterativeIDESolver
540540
return;
541541
}
542542

543-
auto NewEF = EF.joinWith(std::move(LocalEF));
543+
auto NewEF = Problem.combine(EF, std::move(LocalEF));
544544
assert(NewEF != nullptr);
545545

546546
if (NewEF != EF) {
@@ -622,10 +622,11 @@ class IterativeIDESolver
622622
auto FactId = FactCompressor.getOrInsert(Fact);
623623
auto EF = [&] {
624624
if constexpr (ComputeValues) {
625-
return SourceEF.composeWith(FECache.getNormalEdgeFunction(
625+
auto NEF = FECache.getNormalEdgeFunction(
626626
Problem, AtInstruction, CSFact, Succ, Fact,
627627
combineIds(AtInstructionId, SuccId),
628-
combineIds(PropagatedFactId, FactId)));
628+
combineIds(PropagatedFactId, FactId));
629+
return Problem.extend(SourceEF, std::move(NEF));
629630
} else {
630631
return EdgeFunctionPtrType{};
631632
}
@@ -694,10 +695,11 @@ class IterativeIDESolver
694695

695696
auto EF = [&] {
696697
if constexpr (ComputeValues) {
697-
return SourceEF.composeWith(FECache.getCallToRetEdgeFunction(
698+
auto CEF = FECache.getCallToRetEdgeFunction(
698699
Problem, AtInstruction, CSFact, RetSite, Fact, Callees /*Vec*/,
699700
combineIds(AtInstructionId, RetSiteId),
700-
combineIds(PropagatedFactId, FactId)));
701+
combineIds(PropagatedFactId, FactId));
702+
return Problem.extend(SourceEF, std::move(CEF));
701703
} else {
702704
return EdgeFunctionPtrType{};
703705
}
@@ -835,10 +837,11 @@ class IterativeIDESolver
835837

836838
auto CallEF = [&] {
837839
if constexpr (ComputeValues) {
838-
return SourceEF.composeWith(FECache.getCallEdgeFunction(
840+
auto CEF = FECache.getCallEdgeFunction(
839841
Problem, AtInstruction, CSFact, Callee, Fact,
840842
combineIds(AtInstructionId, CalleeId),
841-
combineIds(CSFactId, FactId)));
843+
combineIds(CSFactId, FactId));
844+
return Problem.extend(SourceEF, std::move(CEF));
842845
} else {
843846
return EdgeFunctionPtrType{};
844847
}
@@ -900,7 +903,7 @@ class IterativeIDESolver
900903
Problem, AtInstruction, CSFact, RetSite, Fact,
901904
combineIds(AtInstructionId, RetSiteId),
902905
combineIds(CSFactId, FactId));
903-
return EF ? SourceEF.composeWith(std::move(EF)) : SourceEF;
906+
return EF ? Problem.extend(SourceEF, std::move(EF)) : SourceEF;
904907
} else {
905908
return EdgeFunctionPtrType{};
906909
}
@@ -939,8 +942,8 @@ class IterativeIDESolver
939942
Problem, CallSite, Callee, ExitInst, SummaryFact, RetSite,
940943
RetFact, ExitId, combineIds(CSId, RSId),
941944
combineIds(SummaryFactId, RetFactId));
942-
return CallEF.composeWith(Summary.second)
943-
.composeWith(std::move(RetEF));
945+
return Problem.extend(Problem.extend(CallEF, Summary.second),
946+
std::move(RetEF));
944947
} else {
945948
return EdgeFunctionPtrType{};
946949
}
@@ -954,16 +957,15 @@ class IterativeIDESolver
954957
}
955958

956959
void processInterJobs() {
957-
958-
llvm::errs() << "processInterJobs: " << CallWL.size()
959-
<< " relevant calls\n";
960+
PHASAR_LOG_LEVEL(INFO, "processInterJobs: " << CallWL.size()
961+
<< " relevant calls");
960962

961963
/// Here, no other job is running concurrently, so we save and reset the
962964
/// CallWL, such that we can start concurrent jobs in the loop below
963965
std::vector<uint64_t> RelevantCalls(CallWL.begin(), CallWL.end());
964966

965967
scope_exit FinishedInterCalls = [] {
966-
llvm::errs() << "> end inter calls\n";
968+
PHASAR_LOG_LEVEL(INFO, "> end inter calls");
967969
};
968970

969971
if constexpr (EnableStatistics) {
@@ -1250,14 +1252,14 @@ class IterativeIDESolver
12501252
}
12511253

12521254
void runGC() {
1253-
llvm::errs() << "runGC() with " << CandidateFunctionsForGC.count()
1254-
<< " candidates\n";
1255+
PHASAR_LOG_LEVEL(INFO, "runGC() with " << CandidateFunctionsForGC.count()
1256+
<< " candidates");
12551257

12561258
size_t NumCollectedFuns = 0;
12571259

12581260
scope_exit FinishGC = [&NumCollectedFuns] {
1259-
llvm::errs() << "> Finished GC run (collected " << NumCollectedFuns
1260-
<< " functions)\n";
1261+
PHASAR_LOG_LEVEL(INFO, "> Finished GC run (collected " << NumCollectedFuns
1262+
<< " functions)");
12611263
};
12621264

12631265
auto FinalCandidates = getCollectableFunctions();

include/phasar/DataFlow/Mono/Contexts/CallStringCTX.h

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

44
#include "phasar/Utils/Printer.h"
55

6+
#include "llvm/ADT/Hashing.h"
67
#include "llvm/Support/raw_ostream.h"
78

8-
#include "boost/functional/hash.hpp"
9-
109
#include <deque>
1110
#include <functional>
1211
#include <initializer_list>
@@ -94,11 +93,9 @@ namespace std {
9493

9594
template <typename N, unsigned K> struct hash<psr::CallStringCTX<N, K>> {
9695
size_t operator()(const psr::CallStringCTX<N, K> &CS) const noexcept {
97-
boost::hash<std::deque<N>> HashDeque;
98-
std::hash<unsigned> HashUnsigned;
99-
size_t U = HashUnsigned(K);
100-
size_t H = HashDeque(CS.CallString);
101-
return U ^ (H << 1);
96+
auto H =
97+
llvm::hash_combine_range(CS.CallString.begin(), CS.CallString.end());
98+
return llvm::hash_combine(K, H);
10299
}
103100
};
104101

include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEFeatureTaintAnalysis.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,13 @@ class IDEFeatureTaintAnalysis
374374

375375
} // namespace psr
376376

377+
namespace std {
378+
template <> struct hash<psr::IDEFeatureTaintEdgeFact> {
379+
size_t
380+
operator()(const psr::IDEFeatureTaintEdgeFact &EdgeFact) const noexcept {
381+
return hash_value(EdgeFact);
382+
}
383+
};
384+
} // namespace std
385+
377386
#endif // PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IDEFEATURETAINTANALYSIS_H

include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IDETypeStateAnalysis.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "phasar/DataFlow/IfdsIde/FlowFunctions.h"
1616
#include "phasar/DataFlow/IfdsIde/IDETabulationProblem.h"
1717
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedCFG.h"
18+
#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h"
1819
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMZeroValue.h"
1920
#include "phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h"
2021
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
@@ -35,9 +36,6 @@
3536

3637
namespace psr {
3738

38-
class LLVMBasedICFG;
39-
class LLVMTypeHierarchy;
40-
4139
namespace detail {
4240

4341
class IDETypeStateAnalysisBaseCommon : public LLVMAnalysisDomainDefault {
@@ -123,7 +121,7 @@ class IDETypeStateAnalysisBase
123121
container_type getLocalAliasesAndAllocas(d_t V, llvm::StringRef Fname);
124122

125123
/**
126-
* @brief Checks if the type machtes the type of interest.
124+
* @brief Checks if the type matches the type of interest.
127125
*/
128126
bool hasMatchingType(d_t V);
129127

@@ -132,7 +130,7 @@ class IDETypeStateAnalysisBase
132130
return generateFlow(FactToGenerate, LLVMZeroValue::getInstance());
133131
}
134132

135-
bool hasMatchingTypeName(const llvm::Type *Ty);
133+
bool hasMatchingTypeName(const llvm::DIType *DITy);
136134

137135
std::map<const llvm::Value *, LLVMAliasInfo::AliasSetTy> AliasCache;
138136
LLVMAliasInfoRef PT{};
@@ -283,11 +281,7 @@ class IDETypeStateAnalysis
283281
template <typename LL = l_t,
284282
typename = std::enable_if_t<HasJoinLatticeTraits<LL>>>
285283
TSConstant(l_t Value, EmptyType /*unused*/ = {}) noexcept
286-
: ConstantEdgeFunction<l_t>{Value} {
287-
if constexpr (!HasJoinLatticeTraits<l_t>) {
288-
this->TSD = TSD;
289-
}
290-
}
284+
: ConstantEdgeFunction<l_t>{Value} {}
291285

292286
/// XXX: Cannot default compose() and join(), because l_t does not implement
293287
/// JoinLatticeTraits (because bottom value is not constant)

include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/TypeStateDescriptions/CSTDFILEIOTypeStateDescription.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "llvm/Support/raw_ostream.h"
1717

18-
#include <map>
1918
#include <set>
2019
#include <string>
2120

include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/TypeStateDescriptions/OpenSSLEVPKDFDescription.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/TypeStateDescriptions/TypeStateDescription.h"
1414

15-
#include <map>
1615
#include <set>
1716
#include <string>
1817

0 commit comments

Comments
 (0)