svf-tools 1.0.976 → 1.0.978

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,337 +0,0 @@
1
- /*
2
- * MTAResultValidator.h
3
- *
4
- * Created on: 29/06/2015
5
- * Author: Peng Di and Ding Ye
6
- */
7
-
8
- #ifndef MTARESULTVALIDATOR_H_
9
- #define MTARESULTVALIDATOR_H_
10
-
11
- #include "MTA/MHP.h"
12
- #include "SVF-LLVM/LLVMUtil.h"
13
-
14
- /*!
15
- * Validate the result of context-sensitive analysis, including context-sensitive
16
- * thread detection and thread interleaving.
17
- */
18
- namespace SVF
19
- {
20
- typedef unsigned NodeID;
21
-
22
- class MTAResultValidator
23
- {
24
-
25
- public:
26
- typedef int INTERLEV_FLAG;
27
- MTAResultValidator(MHP* mh) :
28
- mhp(mh)
29
- {
30
- tcg = mhp->getThreadCallGraph();
31
- tdAPI = tcg->getThreadAPI();
32
- mod = mhp->getTCT()->getSVFModule();
33
- }
34
- // Destructor
35
- ~MTAResultValidator()
36
- {
37
- }
38
-
39
- // Analysis
40
- void analyze();
41
- inline SVFModule* getModule() const
42
- {
43
- return mod;
44
- }
45
- protected:
46
-
47
- /*
48
- * Assistant functions
49
- */
50
-
51
- // Split string
52
- std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
53
- std::vector<std::string> split(const std::string &s, char delim);
54
-
55
- // Get special arguments of given call sites
56
- NodeID getIntArg(const Instruction* inst, unsigned int arg_num);
57
- std::vector<std::string> getStringArg(const Instruction* inst, unsigned int arg_num);
58
- CallStrCxt getCxtArg(const Instruction* inst, unsigned int arg_num);
59
-
60
- /*
61
- * Get the previous LoadInst or StoreInst from Instruction "I" in the
62
- * same BasicBlock. Return nullptr if none exists.
63
- */
64
- const Instruction* getPreviousMemoryAccessInst(const Instruction* I);
65
-
66
- // Compare two cxts
67
- bool matchCxt(const CallStrCxt cxt1, const CallStrCxt cxt2) const;
68
-
69
- // Dump calling context information
70
- void dumpCxt(const CallStrCxt& cxt) const;
71
-
72
- void dumpInterlev(NodeBS& lev);
73
-
74
- // Get the validation result string of a single validation scenario.
75
- inline std::string getOutput(const char *scenario, bool analysisRes);
76
- inline std::string getOutputforInterlevAnalysis(const char *scenario, INTERLEV_FLAG analysisRes);
77
-
78
- /*
79
- * Collect the callsite targets for validations.
80
- * The targets are labeled by "cs1:", "cs2:"... that are the names of its basic blocks.
81
- * The collected targets are stored in csnumToInstMap that maps label "cs1" to its Callsite.
82
- */
83
- bool collectCallsiteTargets();
84
-
85
- /*
86
- * Collect the CxtThread targets for validations.
87
- * The collected targets are stored in vthdToCxt that maps vthd to cxt.
88
- */
89
- bool collectCxtThreadTargets();
90
-
91
- /*
92
- * Collect TCT targets for validations.
93
- * The collected targets are stored in rthdToChildren.
94
- */
95
- bool collectTCTTargets();
96
-
97
- /*
98
- * Collect the thread interleaving targets for validations.
99
- * The collected targets are stored in instToTSMap and threadStmtToInterLeaving.
100
- */
101
- bool collectInterleavingTargets();
102
-
103
- /*
104
- * Perform validation for Cxtthread.
105
- * If correct, the validator maps given thread vthd to static CxtThread rthd stored in vthdTorthd.
106
- */
107
- bool validateCxtThread();
108
-
109
- /*
110
- * Perform validation for TCT.
111
- */
112
- bool validateTCT();
113
-
114
- /*
115
- * Perform validation for thread interleaving.
116
- */
117
- INTERLEV_FLAG validateInterleaving();
118
-
119
- private:
120
-
121
- typedef Map<NodeID, const SVFInstruction*> csnumToInst;
122
- typedef Map<NodeID, CallStrCxt> vthdToCxtMap;
123
- typedef Map<NodeID, NodeID> vthdTorthdMap;
124
- typedef Map<NodeID, NodeID> rthdTovthdMap;
125
-
126
- typedef Map<NodeID, Set<NodeID>> rthdToChildrenMap;
127
-
128
- MHP::InstToThreadStmtSetMap instToTSMap; // Map a instruction to CxtThreadStmtSet
129
- MHP::ThreadStmtToThreadInterleav threadStmtToInterLeaving; /// Map a statement to its thread interleavings
130
-
131
- static constexpr char const *CXT_THREAD = "CXT_THREAD";
132
- static constexpr char const *INTERLEV_ACCESS = "INTERLEV_ACCESS";
133
- static constexpr char const *TCT_ACCESS = "TCT_ACCESS";
134
-
135
- ThreadAPI* tdAPI;
136
- ThreadCallGraph* tcg;
137
- MHP* mhp;
138
- vthdToCxtMap vthdToCxt;
139
- vthdTorthdMap vthdTorthd;
140
- rthdTovthdMap rthdTovthd;
141
- csnumToInst csnumToInstMap;
142
- rthdToChildrenMap rthdToChildren;
143
- SVFModule* mod;
144
- /// Constant INTERLEV_FLAG values
145
- //@{
146
- static const INTERLEV_FLAG INTERLEV_TRUE = 0x01;
147
- static const INTERLEV_FLAG INTERLEV_IMPRECISE = 0x02;
148
- static const INTERLEV_FLAG INTERLEV_UNSOUND = 0x04;
149
- //@}
150
- };
151
-
152
-
153
-
154
- /*!
155
- * \brief Validate the result of concurrent analysis.
156
- *
157
- * The properties to validate of two memory accesses include
158
- * one or more of the following four:
159
- * (1) they may accesses aliases;
160
- * (2) they may happen in parallel;
161
- * (3) they are protected by common lock(s);
162
- * (4) they may cause a data race error.
163
- * The ground truth are specified by the "RC_ACCESS" function in the target program.
164
- *
165
- * Users may utilize this result validator to validate their analysis with
166
- * one or more of the four properties, by inheriting the RCResultValidator class.
167
- * The corresponding virtual function of the desired property should be overridden.
168
- */
169
- class RaceResultValidator
170
- {
171
- public:
172
- typedef int RC_FLAG;
173
-
174
- /*!
175
- * Data structure for recording access pairs for the validation.
176
- */
177
- class AccessPair
178
- {
179
- public:
180
- /// Constructor
181
- AccessPair(const Instruction* I1, const Instruction* I2,
182
- const RC_FLAG flags) :
183
- I1(I1), I2(I2), flags(flags)
184
- {
185
- }
186
-
187
- /// Class member access
188
- //@{
189
- inline bool isFlaged(const RC_FLAG flag) const
190
- {
191
- return flags & flag;
192
- }
193
- inline const Instruction* getInstruction1() const
194
- {
195
- return I1;
196
- }
197
- inline const Instruction* getInstruction2() const
198
- {
199
- return I2;
200
- }
201
- //@}
202
-
203
- private:
204
- const Instruction* I1;
205
- const Instruction* I2;
206
- RC_FLAG flags;
207
- };
208
-
209
- /// Destructor
210
- virtual ~RaceResultValidator()
211
- {
212
- release();
213
- }
214
-
215
- /// Initialization
216
- void init(SVFModule* M)
217
- {
218
- this->M = M;
219
- selectedValidationScenarios = RC_MHP | RC_ALIASES | RC_PROTECTED | RC_RACE;
220
- collectValidationTargets();
221
- }
222
-
223
- /// Analysis
224
- void analyze()
225
- {
226
- validateAll();
227
- }
228
-
229
- /// Release resource
230
- void release()
231
- {
232
- }
233
-
234
- /// Check if the input program has validation target
235
- inline bool hasValidationTarget() const
236
- {
237
- return !accessPairs.empty();
238
- }
239
-
240
- protected:
241
- /// Interface to the specific validation properties.
242
- /// Override one or more to implement your own analysis.
243
- //@{
244
- virtual bool mayAccessAliases(const Instruction* I1,
245
- const Instruction* I2)
246
- {
247
- selectedValidationScenarios &= ~RC_ALIASES;
248
- return true;
249
- }
250
- virtual bool mayHappenInParallel(const Instruction* I1,
251
- const Instruction* I2)
252
- {
253
- selectedValidationScenarios &= ~RC_MHP;
254
- return true;
255
- }
256
- virtual bool protectedByCommonLocks(const Instruction* I1,
257
- const Instruction* I2)
258
- {
259
- selectedValidationScenarios &= ~RC_PROTECTED;
260
- return true;
261
- }
262
- virtual bool mayHaveDataRace(const Instruction* I1,
263
- const Instruction* I2)
264
- {
265
- selectedValidationScenarios &= ~RC_RACE;
266
- return true;
267
- }
268
- //@}
269
-
270
- /*!
271
- * Collect the targets for validations.
272
- * The targets should be memory access Instructions in pairs.
273
- * The collected targets are stored in the member variable "accessPairs".
274
- */
275
- void collectValidationTargets();
276
-
277
- /// Perform validation for all targets.
278
- void validateAll();
279
-
280
- /// Get the validation result string of a single validation scenario.
281
- inline std::string getOutput(const char *scenario,
282
- bool analysisRes, bool expectedRes)
283
- {
284
- std::string ret(scenario);
285
- ret += "\t";
286
- if (expectedRes)
287
- ret += " T: ";
288
- else
289
- ret += " F: ";
290
- if (analysisRes == expectedRes)
291
- ret += SVFUtil::sucMsg("SUCCESS");
292
- else
293
- ret += SVFUtil::errMsg("FAILURE");
294
- return ret;
295
- }
296
-
297
- private:
298
- SVFModule* M;
299
- std::vector<AccessPair> accessPairs;
300
- RC_FLAG selectedValidationScenarios;
301
-
302
- /*!
303
- * Comparison function to sort the validation targets in ascending order of
304
- * the validation id (i.e., the 1st argument of RC_ACCESS function call).
305
- */
306
- static bool compare(const CallBase* CI1, const CallBase* CI2)
307
- {
308
- const Value *V1 = CI1->getArgOperand(0);
309
- const Value *V2 = CI2->getArgOperand(0);
310
- const ConstantInt* C1 = SVFUtil::dyn_cast<ConstantInt>(V1);
311
- const ConstantInt* C2 = SVFUtil::dyn_cast<ConstantInt>(V2);
312
- assert(0 != C1 && 0 != C2);
313
- return C1->getZExtValue() < C2->getZExtValue();
314
- }
315
-
316
- /*!
317
- * Get the previous LoadInst or StoreInst from Instruction "I" in the
318
- * same BasicBlock.
319
- * Return nullptr if none exists.
320
- */
321
- const Instruction* getPreviousMemoryAccessInst(
322
- const Instruction* I);
323
-
324
- /// Constant RC_FLAG values
325
- //@{
326
- static const RC_FLAG RC_MHP = 0x01;
327
- static const RC_FLAG RC_ALIASES = 0x02;
328
- static const RC_FLAG RC_PROTECTED = 0x04;
329
- static const RC_FLAG RC_RACE = 0x10;
330
- //@}
331
-
332
- /// The name of the function which is used to specify the ground truth
333
- /// of the validation properties in the target program.
334
- static constexpr char const *RC_ACCESS = "RC_ACCESS";
335
- };
336
- } // namespace SVF end
337
- #endif /* MTARESULTVALIDATOR_H_ */