Static Value-Flow Analysis
Loading...
Searching...
No Matches
AbstractInterpretation.h
Go to the documentation of this file.
1//===- AbstractInterpretation.h -- Abstract Execution----------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23
24//
25// Created by Jiawei Wang on 2024/1/10.
26// The implementation is based on
27// Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
28// 46th International Conference on Software Engineering. (ICSE24)
29//
30#pragma once
32#include "AE/Core/ICFGWTO.h"
34#include "AE/Svfexe/AbsExtAPI.h"
35#include "Util/SVFBugReport.h"
36#include "WPA/Andersen.h"
37
38namespace SVF
39{
40class AbstractInterpretation;
41class AbsExtAPI;
42class AEStat;
43class AEAPI;
44
45template<typename T> class FILOWorkList;
46
48class AEStat : public SVFStat
49{
50public:
51 void countStateSize();
57 {
58 }
59 inline std::string getMemUsage()
60 {
62 return SVFUtil::getMemoryUsageKB(&vmrss, &vmsize) ? std::to_string(vmsize) + "KB" : "cannot read memory usage";
63 }
64
65 void finializeStat();
66 void performStat() override;
67
68public:
71 std::string memory_usage;
72 std::string memUsage;
73
74
76 {
77 if (generalNumMap.count("Function_Trace") == 0)
78 {
79 generalNumMap["Function_Trace"] = 0;
80 }
81 return generalNumMap["Function_Trace"];
82 }
84 {
85 if (generalNumMap.count("Block_Trace") == 0)
86 {
87 generalNumMap["Block_Trace"] = 0;
88 }
89 return generalNumMap["Block_Trace"];
90 }
92 {
93 if (generalNumMap.count("ICFG_Node_Trace") == 0)
94 {
95 generalNumMap["ICFG_Node_Trace"] = 0;
96 }
97 return generalNumMap["ICFG_Node_Trace"];
98 }
99};
100
103{
104 friend class AEStat;
105 friend class AEAPI;
107
108public:
112
113 virtual void runOnModule(ICFG* icfg);
114
116 virtual ~AbstractInterpretation();
117
119 void analyse();
120
122 {
124 return instance;
125 }
126
127 void addDetector(std::unique_ptr<AEDetector> detector)
128 {
129 detectors.push_back(std::move(detector));
130 }
131
133
134private:
136 virtual void handleGlobalNode();
137
139 void initWTO();
140
147 bool mergeStatesFromPredecessors(const ICFGNode * icfgNode);
148
156
163
169 virtual void handleCallSite(const ICFGNode* node);
170
176 virtual void handleCycleWTO(const ICFGCycleWTO* cycle);
177
178 void handleWTOComponents(const std::list<const ICFGWTOComp*>& wtoComps);
179
181
182
188 virtual void handleSVFStatement(const SVFStmt* stmt);
189
195 virtual void SkipRecursiveCall(const CallICFGNode* callnode);
196
197
207
217
218
219 void collectCheckPoint();
220 void checkPointAllSet();
221
222 void updateStateOnAddr(const AddrStmt *addr);
223
225
226 void updateStateOnCmp(const CmpStmt *cmp);
227
228 void updateStateOnLoad(const LoadStmt *load);
229
230 void updateStateOnStore(const StoreStmt *store);
231
232 void updateStateOnCopy(const CopyStmt *copy);
233
234 void updateStateOnCall(const CallPE *callPE);
235
236 void updateStateOnRet(const RetPE *retPE);
237
238 void updateStateOnGep(const GepStmt *gep);
239
241
242 void updateStateOnPhi(const PhiStmt *phi);
243
244
248 AEAPI* api{nullptr};
249
252
253 std::vector<const CallICFGNode*> callSiteStack;
256
257
259 {
260 const ICFGNode* repNode = icfg->getRepNode(node);
261 if (abstractTrace.count(repNode) == 0)
262 {
263 assert(0 && "No preAbsTrace for this node");
264 }
265 else
266 {
267 return abstractTrace[repNode];
268 }
269 }
270
272 {
273 const ICFGNode* repNode = icfg->getRepNode(node);
274 return abstractTrace.count(repNode) != 0;
275 }
276
278 {
279 return utils;
280 }
281
282 // helper functions in handleCallSite
283 virtual bool isExtCall(const CallICFGNode* callNode);
284 virtual void extCallPass(const CallICFGNode* callNode);
285 virtual bool isRecursiveCall(const CallICFGNode* callNode);
286 virtual void recursiveCallPass(const CallICFGNode* callNode);
287 virtual bool isDirectCall(const CallICFGNode* callNode);
288 virtual void directCallFunPass(const CallICFGNode* callNode);
289 virtual bool isIndirectCall(const CallICFGNode* callNode);
290 virtual void indirectCallFunPass(const CallICFGNode* callNode);
291
292 // there data should be shared with subclasses
293 Map<std::string, std::function<void(const CallICFGNode*)>> func_map;
294
295 Map<const ICFGNode*, AbstractState> abstractTrace; // abstract states immediately after nodes
296 std::string moduleName;
297
298 std::vector<std::unique_ptr<AEDetector>> detectors;
300
301 // according to varieties of cmp insts,
302 // maybe var X var, var X const, const X var, const X const
303 // we accept 'var X const' 'var X var' 'const X const'
304 // if 'const X var', we need to reverse op0 op1 and its predicate 'var X' const'
305 // X' is reverse predicate of X
306 // == -> !=, != -> ==, > -> <=, >= -> <, < -> >=, <= -> >
307
327
328
348
349};
350}
copy
Definition cJSON.cpp:414
AEStat: Statistic for AE.
std::string memory_usage
void performStat() override
AEStat(AbstractInterpretation *ae)
std::string getMemUsage()
AbstractInterpretation * _ae
Handles external API calls and manages abstract states.
Definition AbsExtAPI.h:46
AbstractInterpretation is same as Abstract Execution.
void updateStateOnCall(const CallPE *callPE)
virtual bool isRecursiveCall(const CallICFGNode *callNode)
virtual void recursiveCallPass(const CallICFGNode *callNode)
Map< std::string, std::function< void(const CallICFGNode *)> > func_map
void updateStateOnStore(const StoreStmt *store)
virtual bool isDirectCall(const CallICFGNode *callNode)
bool hasAbsStateFromTrace(const ICFGNode *node)
static AbstractInterpretation & getAEInstance()
virtual void handleCycleWTO(const ICFGCycleWTO *cycle)
handle wto cycle (loop)
Map< const CallGraphNode *, ICFGWTO * > funcToWTO
void updateStateOnGep(const GepStmt *gep)
virtual void extCallPass(const CallICFGNode *callNode)
virtual void handleGlobalNode()
Global ICFGNode is handled at the entry of the program,.
bool mergeStatesFromPredecessors(const ICFGNode *icfgNode)
virtual void directCallFunPass(const CallICFGNode *callNode)
void handleWTOComponent(const ICFGWTOComp *wtoComp)
virtual bool isExtCall(const CallICFGNode *callNode)
virtual bool isIndirectCall(const CallICFGNode *callNode)
void initWTO()
Mark recursive functions in the call graph.
SCCDetection< PTACallGraph * > CallGraphSCC
void updateStateOnPhi(const PhiStmt *phi)
bool isBranchFeasible(const IntraCFGEdge *intraEdge, AbstractState &as)
std::vector< std::unique_ptr< AEDetector > > detectors
void addDetector(std::unique_ptr< AEDetector > detector)
AbstractState & getAbsStateFromTrace(const ICFGNode *node)
Set< const CallGraphNode * > recursiveFuns
Set< const CallICFGNode * > checkpoints
bool isSwitchBranchFeasible(const SVFVar *var, s64_t succ, AbstractState &as)
void updateStateOnSelect(const SelectStmt *select)
virtual void handleSVFStatement(const SVFStmt *stmt)
virtual void indirectCallFunPass(const CallICFGNode *callNode)
SVFIR * svfir
protected data members, also used in subclasses
virtual void runOnModule(ICFG *icfg)
void updateStateOnAddr(const AddrStmt *addr)
virtual ~AbstractInterpretation()
Destructor.
bool isCmpBranchFeasible(const CmpStmt *cmpStmt, s64_t succ, AbstractState &as)
virtual void handleCallSite(const ICFGNode *node)
void updateStateOnRet(const RetPE *retPE)
void handleWTOComponents(const std::list< const ICFGWTOComp * > &wtoComps)
Hanlde two types of WTO components (singleton and cycle)
void updateStateOnCopy(const CopyStmt *copy)
AEAPI * api
Execution State, used to store the Interval Value of every SVF variable.
void updateStateOnLoad(const LoadStmt *load)
void updateStateOnBinary(const BinaryOPStmt *binary)
Map< const ICFGNode *, AbstractState > abstractTrace
std::vector< const CallICFGNode * > callSiteStack
virtual void handleSingletonWTO(const ICFGSingletonWTO *icfgSingletonWto)
handle instructions in svf basic blocks
Map< s32_t, s32_t > _switch_lhsrhs_predicate
void updateStateOnCmp(const CmpStmt *cmp)
virtual void SkipRecursiveCall(const CallICFGNode *callnode)
Detector for identifying buffer overflow issues.
Definition AEDetector.h:134
@ ICMP_SGT
signed greater than
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ ICMP_NE
not equal
@ ICMP_ULT
unsigned less than
@ ICMP_SLT
signed less than
@ ICMP_UGT
unsigned greater than
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_SLE
signed less or equal
const ICFGNode * getRepNode(const ICFGNode *node) const
Definition ICFG.h:246
NUMStatMap generalNumMap
Definition SVFStat.h:76
double startTime
Definition SVFStat.h:80
static double getClk(bool mark=false)
Definition SVFStat.cpp:48
bool getMemoryUsageKB(u32_t *vmrss_kb, u32_t *vmsize_kb)
Get memory usage from system file. Return TRUE if succeed.
Definition SVFUtil.cpp:178
for isBitcode
Definition BasicTypes.h:68
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
signed s32_t
Definition GeneralType.h:47
unsigned u32_t
Definition GeneralType.h:46
signed long long s64_t
Definition GeneralType.h:49