Skip to content

Commit f9a2f83

Browse files
committed
Add command-line flags to manually configure the IFDSIDESolverConfig
1 parent 79aa718 commit f9a2f83

8 files changed

Lines changed: 125 additions & 50 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ include_directories(${Boost_INCLUDE_DIRS})
119119

120120
# JSON library
121121
option(JSON_BuildTests OFF)
122+
set(JSON_Install ON)
122123
add_subdirectory(external/json EXCLUDE_FROM_ALL)
123124
include_directories(external/json/single_include/)
124125

126+
# JSON Schema Validator
127+
set(BUILD_TESTS OFF)
128+
set(BUILD_EXAMPLES OFF)
129+
add_subdirectory(external/json-schema-validator EXCLUDE_FROM_ALL)
130+
include_directories(external/json-schema-validator/src)
131+
125132
# Googletest
126133
if (NOT PHASAR_IN_TREE)
127134
add_subdirectory(external/googletest EXCLUDE_FROM_ALL)

include/phasar/Controller/AnalysisController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "phasar/DB/ProjectIRDB.h"
2121
#include "phasar/PhasarLLVM/AnalysisStrategy/Strategies.h"
2222
#include "phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h"
23+
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IFDSIDESolverConfig.h"
2324
#include "phasar/PhasarLLVM/Pointer/LLVMBasedPointsToAnalysis.h"
2425
#include "phasar/PhasarLLVM/Pointer/LLVMPointsToSet.h"
2526
#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h"
@@ -62,6 +63,7 @@ class AnalysisController {
6263
std::string ProjectID;
6364
std::string OutDirectory;
6465
boost::filesystem::path ResultDirectory;
66+
IFDSIDESolverConfig SolverConfig;
6567
[[maybe_unused]] Soundness SoundnessLevel;
6668
[[maybe_unused]] bool AutoGlobalSupport;
6769

@@ -122,6 +124,7 @@ class AnalysisController {
122124
const std::set<std::string> &EntryPoints,
123125
AnalysisStrategy Strategy,
124126
AnalysisControllerEmitterOptions EmitterOptions,
127+
IFDSIDESolverConfig SolverConfig,
125128
const std::string &ProjectID = "default-phasar-project",
126129
const std::string &OutDirectory = "");
127130

include/phasar/PhasarLLVM/AnalysisStrategy/WholeProgramAnalysis.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "phasar/DB/ProjectIRDB.h"
2121
#include "phasar/PhasarLLVM/AnalysisStrategy/AnalysisSetup.h"
22+
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IFDSIDESolverConfig.h"
23+
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IDESolver.h"
2224

2325
namespace psr {
2426

@@ -51,7 +53,7 @@ class WholeProgramAnalysis {
5153
Solver DataFlowSolver;
5254

5355
public:
54-
WholeProgramAnalysis(ProjectIRDB &IRDB,
56+
WholeProgramAnalysis(IFDSIDESolverConfig SolverConfig, ProjectIRDB &IRDB,
5557
std::set<std::string> EntryPoints = {},
5658
PointerAnalysisTy *PointerInfo = nullptr,
5759
CallGraphAnalysisTy *CallGraph = nullptr,
@@ -70,12 +72,17 @@ class WholeProgramAnalysis {
7072
: std::unique_ptr<CallGraphAnalysisTy>(CallGraph)),
7173
EntryPoints(EntryPoints),
7274
ProblemDesc(&IRDB, TypeHierarchy, CallGraph, PointerInfo, EntryPoints),
73-
DataFlowSolver(ProblemDesc) {}
75+
DataFlowSolver(ProblemDesc) {
76+
if constexpr (has_setIFDSIDESolverConfig_v<ProblemDescription>) {
77+
ProblemDesc.setIFDSIDESolverConfig(SolverConfig);
78+
}
79+
}
7480

7581
template <typename T = ProblemDescription,
7682
typename = typename std::enable_if_t<!std::is_same_v<
7783
typename T::ConfigurationTy, HasNoConfigurationType>>>
78-
WholeProgramAnalysis(ProjectIRDB &IRDB, ConfigurationTy *Config,
84+
WholeProgramAnalysis(IFDSIDESolverConfig SolverConfig, ProjectIRDB &IRDB,
85+
ConfigurationTy *Config,
7986
std::set<std::string> EntryPoints = {},
8087
PointerAnalysisTy *PointerInfo = nullptr,
8188
CallGraphAnalysisTy *CallGraph = nullptr,
@@ -95,12 +102,17 @@ class WholeProgramAnalysis {
95102
EntryPoints(EntryPoints), Config(Config), OwnsConfig(false),
96103
ConfigPath(""), ProblemDesc(&IRDB, TypeHierarchy, CallGraph,
97104
PointerInfo, *Config, EntryPoints),
98-
DataFlowSolver(ProblemDesc) {}
105+
DataFlowSolver(ProblemDesc) {
106+
if constexpr (has_setIFDSIDESolverConfig_v<ProblemDescription>) {
107+
ProblemDesc.setIFDSIDESolverConfig(SolverConfig);
108+
}
109+
}
99110

100111
template <typename T = ProblemDescription,
101112
typename = typename std::enable_if_t<!std::is_same_v<
102113
typename T::ConfigurationTy, HasNoConfigurationType>>>
103-
WholeProgramAnalysis(ProjectIRDB &IRDB, std::string ConfigPath,
114+
WholeProgramAnalysis(IFDSIDESolverConfig SolverConfig, ProjectIRDB &IRDB,
115+
std::string ConfigPath,
104116
std::set<std::string> EntryPoints = {},
105117
PointerAnalysisTy *PointerInfo = nullptr,
106118
CallGraphAnalysisTy *CallGraph = nullptr,
@@ -121,7 +133,11 @@ class WholeProgramAnalysis {
121133
OwnsConfig(true), ConfigPath(ConfigPath),
122134
ProblemDesc(&IRDB, TypeHierarchy, CallGraph, PointerInfo, *Config,
123135
EntryPoints),
124-
DataFlowSolver(ProblemDesc) {}
136+
DataFlowSolver(ProblemDesc) {
137+
if constexpr (has_setIFDSIDESolverConfig_v<ProblemDescription>) {
138+
ProblemDesc.setIFDSIDESolverConfig(SolverConfig);
139+
}
140+
}
125141

126142
WholeProgramAnalysis(const WholeProgramAnalysis &) = delete;
127143

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IFDSIDESolverConfig.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "phasar/Config/Configuration.h"
2323
#include "phasar/Utils/EnumFlags.h"
2424
#include "phasar/Utils/Logger.h"
25-
#include "phasar/Utils/Utilities.h"
2625

2726
namespace psr {
2827

@@ -35,24 +34,25 @@ enum class SolverConfigOptions : uint32_t {
3534
EmitESG = 16,
3635
ComputePersistedSummaries = 32,
3736

38-
All = ~0u
37+
All = ~0U
3938
};
4039

4140
struct IFDSIDESolverConfig {
42-
IFDSIDESolverConfig();
43-
IFDSIDESolverConfig(SolverConfigOptions Options);
41+
IFDSIDESolverConfig() noexcept = default;
42+
IFDSIDESolverConfig(SolverConfigOptions Options) noexcept;
4443
~IFDSIDESolverConfig() = default;
45-
IFDSIDESolverConfig(const IFDSIDESolverConfig &) = default;
46-
IFDSIDESolverConfig &operator=(const IFDSIDESolverConfig &) = default;
47-
IFDSIDESolverConfig(IFDSIDESolverConfig &&) = default;
48-
IFDSIDESolverConfig &operator=(IFDSIDESolverConfig &&) = default;
44+
IFDSIDESolverConfig(const IFDSIDESolverConfig &) noexcept = default;
45+
IFDSIDESolverConfig &
46+
operator=(const IFDSIDESolverConfig &) noexcept = default;
47+
IFDSIDESolverConfig(IFDSIDESolverConfig &&) noexcept = default;
48+
IFDSIDESolverConfig &operator=(IFDSIDESolverConfig &&) noexcept = default;
4949

50-
bool followReturnsPastSeeds() const;
51-
bool autoAddZero() const;
52-
bool computeValues() const;
53-
bool recordEdges() const;
54-
bool emitESG() const;
55-
bool computePersistedSummaries() const;
50+
[[nodiscard]] bool followReturnsPastSeeds() const;
51+
[[nodiscard]] bool autoAddZero() const;
52+
[[nodiscard]] bool computeValues() const;
53+
[[nodiscard]] bool recordEdges() const;
54+
[[nodiscard]] bool emitESG() const;
55+
[[nodiscard]] bool computePersistedSummaries() const;
5656

5757
void setFollowReturnsPastSeeds(bool Set = true);
5858
void setAutoAddZero(bool Set = true);
@@ -61,6 +61,8 @@ struct IFDSIDESolverConfig {
6161
void setEmitESG(bool Set = true);
6262
void setComputePersistedSummaries(bool Set = true);
6363

64+
void setConfig(SolverConfigOptions Opt);
65+
6466
friend std::ostream &operator<<(std::ostream &OS,
6567
const IFDSIDESolverConfig &SC);
6668

include/phasar/Utils/TypeTraits.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <tuple>
1515
#include <type_traits>
1616

17+
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/IFDSIDESolverConfig.h"
18+
1719
#include "llvm/Support/raw_ostream.h"
1820

1921
namespace psr {
@@ -70,6 +72,13 @@ template <typename T>
7072
struct is_llvm_hashable<T, decltype(hash_value(std::declval<T>()))>
7173
: std::true_type {};
7274

75+
template <typename T, typename = void>
76+
struct has_setIFDSIDESolverConfig : std::false_type {};
77+
template <typename T>
78+
struct has_setIFDSIDESolverConfig<
79+
T, decltype(std::declval<T>().setIFDSIDESolverConfig(
80+
std::declval<IFDSIDESolverConfig>()))> : std::true_type {};
81+
7382
} // namespace detail
7483

7584
template <typename T>
@@ -98,6 +107,10 @@ constexpr bool is_std_hashable_v = detail::is_std_hashable<T>::value;
98107

99108
template <typename T>
100109
constexpr bool is_llvm_hashable_v = detail::is_llvm_hashable<T>::value;
110+
111+
template <typename T>
112+
constexpr bool has_setIFDSIDESolverConfig_v =
113+
detail::has_setIFDSIDESolverConfig<T>::value;
101114
} // namespace psr
102115

103116
#endif // PHASAR_UTILS_TYPETRAITS_H

lib/Controller/AnalysisController.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ AnalysisController::AnalysisController(
8181
CallGraphAnalysisType CGTy, Soundness SoundnessLevel,
8282
bool AutoGlobalSupport, const std::set<std::string> &EntryPoints,
8383
AnalysisStrategy Strategy, AnalysisControllerEmitterOptions EmitterOptions,
84-
const std::string &ProjectID, const std::string &OutDirectory)
84+
IFDSIDESolverConfig SolverConfig, const std::string &ProjectID,
85+
const std::string &OutDirectory)
8586
: IRDB(IRDB), TH(IRDB), PT(IRDB, !needsToEmitPTA(EmitterOptions), PTATy),
8687
ICF(IRDB, CGTy, EntryPoints, &TH, &PT, SoundnessLevel, AutoGlobalSupport),
8788
DataFlowAnalyses(std::move(DataFlowAnalyses)),
8889
AnalysisConfigs(std::move(AnalysisConfigs)), EntryPoints(EntryPoints),
8990
Strategy(Strategy), EmitterOptions(EmitterOptions), ProjectID(ProjectID),
90-
OutDirectory(OutDirectory), SoundnessLevel(SoundnessLevel),
91-
AutoGlobalSupport(AutoGlobalSupport) {
91+
OutDirectory(OutDirectory), SolverConfig(SolverConfig),
92+
SoundnessLevel(SoundnessLevel), AutoGlobalSupport(AutoGlobalSupport) {
9293
if (!OutDirectory.empty()) {
9394
// create directory for results
9495
ResultDirectory = OutDirectory + "/" + ProjectID + "-" + createTimeStamp();
@@ -145,22 +146,22 @@ void AnalysisController::executeWholeProgram() {
145146
case DataFlowAnalysisType::IFDSUninitializedVariables: {
146147
WholeProgramAnalysis<IFDSSolver_P<IFDSUninitializedVariables>,
147148
IFDSUninitializedVariables>
148-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
149+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
149150
WPA.solve();
150151
emitRequestedDataFlowResults(WPA);
151152
WPA.releaseAllHelperAnalyses();
152153
} break;
153154
case DataFlowAnalysisType::IFDSConstAnalysis: {
154155
WholeProgramAnalysis<IFDSSolver_P<IFDSConstAnalysis>, IFDSConstAnalysis>
155-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
156+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
156157
WPA.solve();
157158
emitRequestedDataFlowResults(WPA);
158159
WPA.releaseAllHelperAnalyses();
159160
} break;
160161
case DataFlowAnalysisType::IFDSTaintAnalysis: {
161162
auto Config = getTaintConfig();
162163
WholeProgramAnalysis<IFDSSolver_P<IFDSTaintAnalysis>, IFDSTaintAnalysis>
163-
WPA(IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
164+
WPA(SolverConfig, IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
164165
WPA.solve();
165166
emitRequestedDataFlowResults(WPA);
166167
WPA.releaseAllHelperAnalyses();
@@ -169,7 +170,7 @@ void AnalysisController::executeWholeProgram() {
169170
auto Config = getTaintConfig();
170171
WholeProgramAnalysis<IDESolver_P<IDEExtendedTaintAnalysis<>>,
171172
IDEExtendedTaintAnalysis<>>
172-
WPA(IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
173+
WPA(SolverConfig, IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
173174
WPA.solve();
174175
emitRequestedDataFlowResults(WPA);
175176
WPA.releaseAllHelperAnalyses();
@@ -179,7 +180,7 @@ void AnalysisController::executeWholeProgram() {
179180
/// So, keep the error-message until we have an implementation
180181

181182
// WholeProgramAnalysis<IDESolver_P<IDETaintAnalysis>, IDETaintAnalysis>
182-
// WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
183+
// WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
183184
// WPA.solve();
184185
// emitRequestedDataFlowResults(WPA);
185186
// WPA.releaseAllHelperAnalyses();
@@ -190,7 +191,7 @@ void AnalysisController::executeWholeProgram() {
190191
OpenSSLEVPKDFDescription TSDesc;
191192
WholeProgramAnalysis<IDESolver_P<IDETypeStateAnalysis>,
192193
IDETypeStateAnalysis>
193-
WPA(IRDB, &TSDesc, EntryPoints, &PT, &ICF, &TH);
194+
WPA(SolverConfig, IRDB, &TSDesc, EntryPoints, &PT, &ICF, &TH);
194195
WPA.solve();
195196
emitRequestedDataFlowResults(WPA);
196197
WPA.releaseAllHelperAnalyses();
@@ -199,29 +200,29 @@ void AnalysisController::executeWholeProgram() {
199200
CSTDFILEIOTypeStateDescription TSDesc;
200201
WholeProgramAnalysis<IDESolver_P<IDETypeStateAnalysis>,
201202
IDETypeStateAnalysis>
202-
WPA(IRDB, &TSDesc, EntryPoints, &PT, &ICF, &TH);
203+
WPA(SolverConfig, IRDB, &TSDesc, EntryPoints, &PT, &ICF, &TH);
203204
WPA.solve();
204205
emitRequestedDataFlowResults(WPA);
205206
WPA.releaseAllHelperAnalyses();
206207
} break;
207208
case DataFlowAnalysisType::IFDSTypeAnalysis: {
208209
WholeProgramAnalysis<IFDSSolver_P<IFDSTypeAnalysis>, IFDSTypeAnalysis>
209-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
210+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
210211
WPA.solve();
211212
emitRequestedDataFlowResults(WPA);
212213
WPA.releaseAllHelperAnalyses();
213214
} break;
214215
case DataFlowAnalysisType::IFDSSolverTest: {
215216
WholeProgramAnalysis<IFDSSolver_P<IFDSSolverTest>, IFDSSolverTest> WPA(
216-
IRDB, EntryPoints, &PT, &ICF, &TH);
217+
SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
217218
WPA.solve();
218219
emitRequestedDataFlowResults(WPA);
219220
WPA.releaseAllHelperAnalyses();
220221
} break;
221222
case DataFlowAnalysisType::IFDSLinearConstantAnalysis: {
222223
WholeProgramAnalysis<IFDSSolver_P<IFDSLinearConstantAnalysis>,
223224
IFDSLinearConstantAnalysis>
224-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
225+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
225226
WPA.solve();
226227
emitRequestedDataFlowResults(WPA);
227228
WPA.releaseAllHelperAnalyses();
@@ -230,30 +231,30 @@ void AnalysisController::executeWholeProgram() {
230231
auto Config = getTaintConfig();
231232
WholeProgramAnalysis<IFDSSolver_P<IFDSFieldSensTaintAnalysis>,
232233
IFDSFieldSensTaintAnalysis>
233-
WPA(IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
234+
WPA(SolverConfig, IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
234235
WPA.solve();
235236
emitRequestedDataFlowResults(WPA);
236237
WPA.releaseAllHelperAnalyses();
237238
} break;
238239
case DataFlowAnalysisType::IDELinearConstantAnalysis: {
239240
WholeProgramAnalysis<IDESolver_P<IDELinearConstantAnalysis>,
240241
IDELinearConstantAnalysis>
241-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
242+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
242243
WPA.solve();
243244
emitRequestedDataFlowResults(WPA);
244245
WPA.releaseAllHelperAnalyses();
245246
} break;
246247
case DataFlowAnalysisType::IDESolverTest: {
247248
WholeProgramAnalysis<IDESolver_P<IDESolverTest>, IDESolverTest> WPA(
248-
IRDB, EntryPoints, &PT, &ICF, &TH);
249+
SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
249250
WPA.solve();
250251
emitRequestedDataFlowResults(WPA);
251252
WPA.releaseAllHelperAnalyses();
252253
} break;
253254
case DataFlowAnalysisType::IDEInstInteractionAnalysis: {
254255
WholeProgramAnalysis<IDESolver_P<IDEInstInteractionAnalysis>,
255256
IDEInstInteractionAnalysis>
256-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
257+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
257258
WPA.solve();
258259
emitRequestedDataFlowResults(WPA);
259260
WPA.releaseAllHelperAnalyses();
@@ -262,23 +263,23 @@ void AnalysisController::executeWholeProgram() {
262263
WholeProgramAnalysis<
263264
IntraMonoSolver_P<IntraMonoFullConstantPropagation>,
264265
IntraMonoFullConstantPropagation>
265-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
266+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
266267
WPA.solve();
267268
emitRequestedDataFlowResults(WPA);
268269
WPA.releaseAllHelperAnalyses();
269270
} break;
270271
case DataFlowAnalysisType::IntraMonoSolverTest: {
271272
WholeProgramAnalysis<IntraMonoSolver_P<IntraMonoSolverTest>,
272273
IntraMonoSolverTest>
273-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
274+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
274275
WPA.solve();
275276
emitRequestedDataFlowResults(WPA);
276277
WPA.releaseAllHelperAnalyses();
277278
} break;
278279
case DataFlowAnalysisType::InterMonoSolverTest: {
279280
WholeProgramAnalysis<InterMonoSolver_P<InterMonoSolverTest, 3>,
280281
InterMonoSolverTest>
281-
WPA(IRDB, EntryPoints, &PT, &ICF, &TH);
282+
WPA(SolverConfig, IRDB, EntryPoints, &PT, &ICF, &TH);
282283
WPA.solve();
283284
emitRequestedDataFlowResults(WPA);
284285
WPA.releaseAllHelperAnalyses();
@@ -287,7 +288,7 @@ void AnalysisController::executeWholeProgram() {
287288
auto Config = getTaintConfig();
288289
WholeProgramAnalysis<InterMonoSolver_P<InterMonoTaintAnalysis, 3>,
289290
InterMonoTaintAnalysis>
290-
WPA(IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
291+
WPA(SolverConfig, IRDB, &Config, EntryPoints, &PT, &ICF, &TH);
291292
WPA.solve();
292293
emitRequestedDataFlowResults(WPA);
293294
WPA.releaseAllHelperAnalyses();
@@ -299,6 +300,7 @@ void AnalysisController::executeWholeProgram() {
299300
_DataFlowAnalysis)) {
300301
auto Problem = std::get<IFDSPluginConstructor>(_DataFlowAnalysis)(
301302
&IRDB, &TH, &ICF, &PT, EntryPoints);
303+
Problem->setIFDSIDESolverConfig(SolverConfig);
302304
IFDSSolver_P<std::remove_reference<decltype(*Problem)>::type> Solver(
303305
*Problem);
304306
Solver.solve();
@@ -307,6 +309,7 @@ void AnalysisController::executeWholeProgram() {
307309
_DataFlowAnalysis)) {
308310
auto Problem = std::get<IDEPluginConstructor>(_DataFlowAnalysis)(
309311
&IRDB, &TH, &ICF, &PT, EntryPoints);
312+
Problem->setIFDSIDESolverConfig(SolverConfig);
310313
IDESolver_P<std::remove_reference<decltype(*Problem)>::type> Solver(
311314
*Problem);
312315
Solver.solve();

0 commit comments

Comments
 (0)