Static Value-Flow Analysis
|
#include <SaberCondAllocator.h>
Public Types | |
typedef Z3Expr | Condition |
typedef Map< u32_t, const ICFGNode * > | IndexToTermInstMap |
z3 condition | |
typedef Map< u32_t, Condition > | CondPosMap |
id to instruction map for z3 | |
typedef Map< const SVFBasicBlock *, CondPosMap > | BBCondMap |
typedef Set< const SVFBasicBlock * > | BasicBlockSet |
map bb to a Condition | |
typedef Map< const SVFFunction *, BasicBlockSet > | FunToExitBBsMap |
map a function to all its basic blocks calling program exit | |
typedef Map< const SVFBasicBlock *, Condition > | BBToCondMap |
map a basic block to its condition during control-flow guard computation | |
typedef FIFOWorkList< const SVFBasicBlock * > | CFWorkList |
worklist for control-flow guard computation | |
typedef Map< const SVFGNode *, Set< const SVFGNode * > > | SVFGNodeToSVFGNodeSetMap |
Protected Attributes | |
BBCondMap | bbConds |
map basic block to its successors/predecessors branch conditions | |
Private Member Functions | |
virtual void | allocateForBB (const SVFBasicBlock &bb) |
Allocate path condition for every basic block. | |
void | setBranchCond (const SVFBasicBlock *bb, const SVFBasicBlock *succ, const Condition &cond) |
Get/Set a branch condition, and its terminator instruction. | |
Condition | getBranchCond (const SVFBasicBlock *bb, const SVFBasicBlock *succ) const |
Get branch condition. | |
Condition | getEvalBrCond (const SVFBasicBlock *bb, const SVFBasicBlock *succ) |
Get a condition, evaluate the value for conditions if necessary (e.g., testNull like express) | |
Condition | evaluateBranchCond (const SVFBasicBlock *bb, const SVFBasicBlock *succ) |
Evaluate branch conditions. | |
Condition | evaluateLoopExitBranch (const SVFBasicBlock *bb, const SVFBasicBlock *succ) |
Evaluate loop exit branch. | |
Condition | evaluateTestNullLikeExpr (const BranchStmt *branchStmt, const SVFBasicBlock *succ) |
Return branch condition after evaluating test null like expression. | |
Condition | evaluateProgExit (const BranchStmt *branchStmt, const SVFBasicBlock *succ) |
Return condition when there is a branch calls program exit. | |
void | collectBBCallingProgExit (const SVFBasicBlock &bb) |
Collect basic block contains program exit function call. | |
bool | isBBCallsProgExit (const SVFBasicBlock *bb) |
bool | isEQCmp (const CmpStmt *cmp) const |
Evaluate test null/not null like expressions. | |
bool | isNECmp (const CmpStmt *cmp) const |
Return true if the predicate of this compare instruction is not equal. | |
bool | isTestNullExpr (const ICFGNode *test) const |
Return true if this is a test null expression. | |
bool | isTestNotNullExpr (const ICFGNode *test) const |
Return true if this is a test not null expression. | |
bool | isTestContainsNullAndTheValue (const CmpStmt *cmp) const |
Return true if two values on the predicate are what we want. | |
void | destroy () |
Release memory. | |
void | extractSubConds (const Condition &condition, NodeBS &support) const |
extract subexpression from a Z3 expression | |
Private Attributes | |
FunToExitBBsMap | funToExitBBsMap |
map a function to all its basic blocks calling program exit | |
BBToCondMap | bbToCondMap |
map a basic block to its path condition starting from root | |
const SVFGNode * | curEvalSVFGNode {} |
current llvm value to evaluate branch condition when computing guards | |
IndexToTermInstMap | idToTermInstMap |
NodeBS | negConds |
key: z3 expression id, value: instruction | |
std::vector< Condition > | conditionVec |
bit vector for distinguish neg | |
SVFGNodeToSVFGNodeSetMap | removedSUVFEdges |
a counter for fresh condition | |
Static Private Attributes | |
static u32_t | totalCondNum = 0 |
vector storing z3expression | |
SaberCondAllocator allocates conditions for each basic block of a certain CFG.
Definition at line 46 of file SaberCondAllocator.h.
map bb to a Condition
Definition at line 55 of file SaberCondAllocator.h.
Definition at line 54 of file SaberCondAllocator.h.
map a basic block to its condition during control-flow guard computation
Definition at line 57 of file SaberCondAllocator.h.
worklist for control-flow guard computation
Definition at line 58 of file SaberCondAllocator.h.
Definition at line 51 of file SaberCondAllocator.h.
id to instruction map for z3
map a branch to its Condition
Definition at line 53 of file SaberCondAllocator.h.
map a function to all its basic blocks calling program exit
Definition at line 56 of file SaberCondAllocator.h.
z3 condition
Definition at line 52 of file SaberCondAllocator.h.
typedef Map<const SVFGNode*, Set<const SVFGNode*> > SVF::SaberCondAllocator::SVFGNodeToSVFGNodeSetMap |
Definition at line 59 of file SaberCondAllocator.h.
SaberCondAllocator::SaberCondAllocator | ( | ) |
|
inlinevirtual |
Perform path allocation.
Allocate path condition for each branch
Definition at line 59 of file SaberCondAllocator.cpp.
|
privatevirtual |
Allocate path condition for every basic block.
Allocate conditions for a basic block and propagate its condition to its successors.
TODO: handle BranchInst and SwitchInst individually here!!
Definition at line 89 of file SaberCondAllocator.cpp.
|
inline |
Definition at line 177 of file SaberCondAllocator.h.
|
private |
Collect basic block contains program exit function call.
Whether this basic block contains program exit function call
Definition at line 430 of file SaberCondAllocator.cpp.
|
virtual |
Compute calling inter-procedural guards between two SVFGNodes (from caller to callee) src –c1--> callBB –true--> funEntryBB –c2--> dst the InterCallVFGGuard is c1 ^ c2
Definition at line 489 of file SaberCondAllocator.cpp.
|
virtual |
Compute return inter-procedural guards between two SVFGNodes (from callee to caller) src –c1--> funExitBB –true--> retBB –c2--> dst the InterRetVFGGuard is c1 ^ c2
Definition at line 506 of file SaberCondAllocator.cpp.
|
virtual |
Guard Computation for a value-flow (between two basic blocks)
Compute intra-procedural guards between two SVFGNodes (inside same function)
if the dstBB is the eligible loop exit of the current basic block we can early terminate the computation
calculate the branch condition if succ post dominate bb, then we get brCond quicker by using postDT note that we assume loop exit always post dominate loop bodys which means loops are approximated only once.
Definition at line 520 of file SaberCondAllocator.cpp.
Condition operations.
Definition at line 87 of file SaberCondAllocator.h.
Definition at line 95 of file SaberCondAllocator.h.
Definition at line 91 of file SaberCondAllocator.h.
|
inlineprivate |
|
inline |
Definition at line 157 of file SaberCondAllocator.h.
Definition at line 115 of file SaberCondAllocator.h.
|
private |
Evaluate branch conditions.
Evaluate the branch condition
(1) Evaluate a branch when it reaches a program exit (2) Evaluate a branch when it is loop exit branch (3) Evaluate a branch when it is a test null like condition
Definition at line 302 of file SaberCondAllocator.cpp.
|
private |
Evaluate loop exit branch.
Evaluate loop exit branch to be true if bb is loop header and succ is the only exit basic block outside the loop (excluding exit bbs which call program exit) for all other case, we conservatively evaluate false for now
exclude exit bb which calls program exit
if the dst dominate all other loop exit bbs, then dst can certainly be reached
Definition at line 266 of file SaberCondAllocator.cpp.
|
private |
Return condition when there is a branch calls program exit.
Evaluate condition for program exit (e.g., exit(0))
then branch calls program exit
else branch calls program exit
no branch call program exit
Definition at line 222 of file SaberCondAllocator.cpp.
|
private |
Return branch condition after evaluating test null like expression.
Evaluate null like expression for source-sink related bug detection in SABER
Definition at line 186 of file SaberCondAllocator.cpp.
Iterator every element of the condition.
Definition at line 108 of file SaberCondAllocator.h.
|
private |
extract subexpression from a Z3 expression
Definition at line 637 of file SaberCondAllocator.cpp.
|
private |
Get branch condition.
Get a branch condition
Definition at line 142 of file SaberCondAllocator.cpp.
|
inline |
Definition at line 225 of file SaberCondAllocator.h.
Get/Set instruction based on Z3 expression id.
Definition at line 128 of file SaberCondAllocator.h.
|
inline |
Definition at line 79 of file SaberCondAllocator.h.
Get current value for branch condition evaluation.
Definition at line 187 of file SaberCondAllocator.h.
|
private |
Get a condition, evaluate the value for conditions if necessary (e.g., testNull like express)
Definition at line 157 of file SaberCondAllocator.cpp.
|
inline |
Definition at line 103 of file SaberCondAllocator.h.
|
inline |
Definition at line 208 of file SaberCondAllocator.h.
|
inline |
Statistics.
Definition at line 71 of file SaberCondAllocator.h.
|
virtual |
Get complement condition (from B1 to B0) according to a complementBB (BB2) at a phi e.g., B0: dstBB; B1:incomingBB; B2:complementBB
Get complement phi condition e.g., B0: dstBB; B1:incomingBB; B2:complementBB Assume B0 (phi node) is the successor of both B1 and B2. If B1 dominates B2, and B0 not dominate B2 then condition from B1-->B0 = neg(B1-->B2)^(B1-->B0)
avoid both BB0 and BB1 dominate BB2 (e.g., while loop), then BB2 is not necessarily a complement BB
Definition at line 469 of file SaberCondAllocator.cpp.
|
inline |
Definition at line 244 of file SaberCondAllocator.h.
|
inline |
Definition at line 99 of file SaberCondAllocator.h.
whether condition is satisfiable for all possible boolean guards
Definition at line 200 of file SaberCondAllocator.h.
|
private |
Whether this basic block contains program exit function call
Definition at line 447 of file SaberCondAllocator.cpp.
Evaluate test null/not null like expressions.
Return true if the predicate of this compare instruction is equal
Definition at line 343 of file SaberCondAllocator.cpp.
bool SaberCondAllocator::isEquivalentBranchCond | ( | const Condition & | lhs, |
const Condition & | rhs | ||
) | const |
Whether lhs and rhs are equivalent branch conditions.
check equal using z3 solver
Definition at line 614 of file SaberCondAllocator.cpp.
Return true if the predicate of this compare instruction is not equal.
Definition at line 348 of file SaberCondAllocator.cpp.
Definition at line 142 of file SaberCondAllocator.h.
whether condition is satisfiable
Definition at line 625 of file SaberCondAllocator.cpp.
Return true if two values on the predicate are what we want.
Return true if: (1) cmp contains a null value (2) there is an indirect/direct edge from cur evaluated SVFG node to cmp operand
e.g., indirect edge: cur svfg node -> 1. store i32* %0, i32** p, align 8, !dbg !157 cmp operand -> 2. %1 = load i32*, i32** p, align 8, !dbg !159
direct edge: cur svfg node -> 1. %3 = tail call i8* @malloc(i64 16), !dbg !22 (cmp operand) 2. %4 = icmp eq i8* %3, null, !dbg !28
Definition at line 399 of file SaberCondAllocator.cpp.
Return true if this is a test not null expression.
Definition at line 366 of file SaberCondAllocator.cpp.
Return true if this is a test null expression.
Definition at line 353 of file SaberCondAllocator.cpp.
SaberCondAllocator::Condition SaberCondAllocator::newCond | ( | const ICFGNode * | inst | ) |
Allocate a new condition.
Definition at line 601 of file SaberCondAllocator.cpp.
|
inline |
Definition at line 147 of file SaberCondAllocator.h.
void SaberCondAllocator::printPathCond | ( | ) |
Print out the path condition information.
Print path conditions
Definition at line 574 of file SaberCondAllocator.cpp.
|
private |
Get/Set a branch condition, and its terminator instruction.
Set branch condition
Set a branch condition
we only care about basic blocks have more than one successor
FIXME: llvm getNumSuccessors allows duplicated block in the successors, it makes this assertion fail In this case we may waste a condition allocation, because the overwrite of the previous cond
Definition at line 168 of file SaberCondAllocator.cpp.
|
inline |
Get/Set control-flow conditions.
Definition at line 215 of file SaberCondAllocator.h.
|
inline |
Definition at line 135 of file SaberCondAllocator.h.
Set current value for branch condition evaluation.
Definition at line 182 of file SaberCondAllocator.h.
|
inline |
mark neg Z3 expression
Definition at line 238 of file SaberCondAllocator.h.
|
protected |
map basic block to its successors/predecessors branch conditions
Definition at line 312 of file SaberCondAllocator.h.
|
private |
map a basic block to its path condition starting from root
Definition at line 303 of file SaberCondAllocator.h.
|
private |
bit vector for distinguish neg
Definition at line 307 of file SaberCondAllocator.h.
current llvm value to evaluate branch condition when computing guards
Definition at line 304 of file SaberCondAllocator.h.
|
private |
map a function to all its basic blocks calling program exit
Definition at line 302 of file SaberCondAllocator.h.
|
private |
Definition at line 305 of file SaberCondAllocator.h.
|
private |
key: z3 expression id, value: instruction
Definition at line 306 of file SaberCondAllocator.h.
|
private |
a counter for fresh condition
Definition at line 309 of file SaberCondAllocator.h.
|
staticprivate |
vector storing z3expression
Definition at line 308 of file SaberCondAllocator.h.