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 on: Jan 10, 2024
26// Author: Xiao Cheng, Jiawei Wang
27// The implementation is based on
28// Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
29// 46th International Conference on Software Engineering. (ICSE24)
30//
31#pragma once
33#include "AE/Core/ICFGWTO.h"
35#include "AE/Svfexe/AbsExtAPI.h"
36#include "Util/SVFBugReport.h"
37#include "Util/SVFStat.h"
38#include "Graphs/SCC.h"
39
40namespace SVF
41{
42class AbstractInterpretation;
43class AbsExtAPI;
44class AEStat;
45class AEAPI;
46
47template<typename T> class FILOWorkList;
48
50class AEStat : public SVFStat
51{
52public:
53 void countStateSize();
59 {
60 }
61 inline std::string getMemUsage()
62 {
64 return SVFUtil::getMemoryUsageKB(&vmrss, &vmsize) ? std::to_string(vmsize) + "KB" : "cannot read memory usage";
65 }
66
67 void finializeStat();
68 void performStat() override;
69
70public:
73 std::string memory_usage;
74 std::string memUsage;
75
76
78 {
79 if (generalNumMap.count("Function_Trace") == 0)
80 {
81 generalNumMap["Function_Trace"] = 0;
82 }
83 return generalNumMap["Function_Trace"];
84 }
86 {
87 if (generalNumMap.count("Block_Trace") == 0)
88 {
89 generalNumMap["Block_Trace"] = 0;
90 }
91 return generalNumMap["Block_Trace"];
92 }
94 {
95 if (generalNumMap.count("ICFG_Node_Trace") == 0)
96 {
97 generalNumMap["ICFG_Node_Trace"] = 0;
98 }
99 return generalNumMap["ICFG_Node_Trace"];
100 }
101};
102
105{
106 friend class AEStat;
107 friend class AEAPI;
110
111public:
113
114 /*
115 * For recursive test case
116 * int demo(int a) {
117 if (a >= 10000)
118 return a;
119 demo(a+1);
120 }
121
122 int main() {
123 int result = demo(0);
124 }
125 * if set TOP, result = [-oo, +oo] since the return value, and any stored object pointed by q at *q = p in recursive functions will be set to the top value.
126 * if set WIDEN_ONLY, result = [10000, +oo] since only widening is applied at the cycle head of recursive functions without narrowing.
127 * if set WIDEN_NARROW, result = [10000, 10000] since both widening and narrowing are applied at the cycle head of recursive functions.
128 * */
135
138
139 virtual void runOnModule(ICFG* icfg);
140
142 virtual ~AbstractInterpretation();
143
145 void analyse();
146
148 {
150 return instance;
151 }
152
153 void addDetector(std::unique_ptr<AEDetector> detector)
154 {
155 detectors.push_back(std::move(detector));
156 }
157
159
167 {
168 if (abstractTrace.count(node) == 0)
169 {
170 assert(false && "No preAbsTrace for this node");
171 abort();
172 }
173 else
174 {
175 return abstractTrace[node];
176 }
177 }
178
179private:
181 virtual void handleGlobalNode();
182
184 void initWTO();
185
192 bool mergeStatesFromPredecessors(const ICFGNode * icfgNode);
193
201
208
214 virtual void handleCallSite(const ICFGNode* node);
215
221 virtual void handleCycleWTO(const ICFGCycleWTO* cycle);
222
223 void handleWTOComponents(const std::list<const ICFGWTOComp*>& wtoComps);
224
226
227
233 virtual void handleSVFStatement(const SVFStmt* stmt);
234
240 virtual void SkipRecursiveCall(const CallICFGNode* callnode);
241
242
252
262
263
264 void collectCheckPoint();
265 void checkPointAllSet();
266
267 void updateStateOnAddr(const AddrStmt *addr);
268
270
271 void updateStateOnCmp(const CmpStmt *cmp);
272
273 void updateStateOnLoad(const LoadStmt *load);
274
275 void updateStateOnStore(const StoreStmt *store);
276
277 void updateStateOnCopy(const CopyStmt *copy);
278
279 void updateStateOnCall(const CallPE *callPE);
280
281 void updateStateOnRet(const RetPE *retPE);
282
283 void updateStateOnGep(const GepStmt *gep);
284
286
287 void updateStateOnPhi(const PhiStmt *phi);
288
289
293 AEAPI* api{nullptr};
294
297
298 std::vector<const CallICFGNode*> callSiteStack;
302
303
305 {
306 return abstractTrace.count(node) != 0;
307 }
308
310 {
311 return utils;
312 }
313
314 // helper functions in handleCallSite
315 virtual bool isExtCall(const CallICFGNode* callNode);
316 virtual void extCallPass(const CallICFGNode* callNode);
317 virtual bool isRecursiveFun(const FunObjVar* fun);
318 virtual bool isRecursiveCall(const CallICFGNode* callNode);
319 virtual void recursiveCallPass(const CallICFGNode *callNode);
320 virtual bool isRecursiveCallSite(const CallICFGNode* callNode, const FunObjVar *);
321 virtual bool isDirectCall(const CallICFGNode* callNode);
322 virtual void directCallFunPass(const CallICFGNode* callNode);
323 virtual bool isIndirectCall(const CallICFGNode* callNode);
324 virtual void indirectCallFunPass(const CallICFGNode* callNode);
325
326 // there data should be shared with subclasses
327 Map<std::string, std::function<void(const CallICFGNode*)>> func_map;
328
329 Map<const ICFGNode*, AbstractState> abstractTrace; // abstract states immediately after nodes
330 std::string moduleName;
331
332 std::vector<std::unique_ptr<AEDetector>> detectors;
334
335 // according to varieties of cmp insts,
336 // maybe var X var, var X const, const X var, const X const
337 // we accept 'var X const' 'var X var' 'const X const'
338 // if 'const X var', we need to reverse op0 op1 and its predicate 'var X' const'
339 // X' is reverse predicate of X
340 // == -> !=, != -> ==, > -> <=, >= -> <, < -> >=, <= -> >
341
361
362
382
383};
384}
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:44
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)
Set< const FunObjVar * > recursiveFuns
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()
Compute IWTO for each function partition entry.
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)
Retrieves the abstract state from the trace for a given ICFG node.
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)
virtual bool isRecursiveCallSite(const CallICFGNode *callNode, const FunObjVar *)
virtual bool isRecursiveFun(const FunObjVar *fun)
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)
Handle two types of WTO components (singleton and cycle)
void updateStateOnCopy(const CopyStmt *copy)
Set< std::pair< const CallICFGNode *, NodeID > > nonRecursiveCallSites
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
SCCDetection< CallGraph * > CallGraphSCC
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)
Map< const FunObjVar *, const ICFGWTO * > funcToWTO
Detector for identifying buffer overflow issues.
Definition AEDetector.h:136
@ 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
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:179
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:48
unsigned u32_t
Definition GeneralType.h:47
signed long long s64_t
Definition GeneralType.h:50