Title: Program Analysis via 3-Valued Logic
1Program Analysisvia 3-Valued Logic
- Thomas Reps
- University of Wisconsin
Joint work with Mooly Sagiv and Reinhard Wilhelm
2Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
3Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
4Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
5Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
6Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
7Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
8Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
9Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
10Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
11Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
12Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
13Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
14Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
15Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
16Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
1
2
3
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
17Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
18Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
19Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
20Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
21Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
Materialization
22Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
23Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
24Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
25Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
26Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
27Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
28Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
29Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
30Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
31Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
32Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
33Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
34Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
35Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
36Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
37Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
38Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
39Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
40Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
41Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
42Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
43Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
y
t
NULL
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
x
44Original Problem Shape Analysis
- Characterize dynamically allocated data
- x points to an acyclic list, cyclic list, tree,
dag, etc. - data-structure invariants
- Identify may-alias relationships
- Establish disjointedness properties
- x and y point to structures that do not share
cells
45Formalizing . . .
Informal
x
Summary node
46Why is Shape Analysis Difficult?
- Destructive updating through pointers
- p?next q
- Produces complicated aliasing relationships
- Dynamic storage allocation
- No bound on the size of run-time data structures
- Data-structure invariants typically only hold at
the beginning and end of operations - Need to verify that data-structure invariants are
re-established
47Applications Code Optimization
- Machine-independent optimizations
- constant propagation
- loop-invariant code motion
- common subexpression elimination
- Machine-dependent optimizations
- register allocation
- parallelization
- software prefetching
- Insert storage-reclamation operations
- Eliminate or move checking code
48Applications Software Tools
- Static detection of memory errors (cleanness)
- dereferencing NULL pointers
- dereferencing dangling pointers
- memory leaks
- Static detection of logical errors
- Is a shape invariant restored?
- What is in the heap?
- list? doubly-linked list? tree? DAG?
- disjoint? intertwined?
49Properties of reverse(x)
- On entry x points to an acyclic list
- On exit y points to an acyclic list
- On exit x NULL
- On each iteration, x and y point to disjoint
acyclic lists - All the pointer dereferences are safe
- No memory leaks
50A Yacc for Shape Analysis TVLA
- Parametric framework
- Some instantiations ? known analyses
- Other instantiations ? new analyses
51A Yacc for Shape Analysis TVLA
- Parametric framework
- Some instantiations ? known analyses
- Other instantiations ? new analyses
- Applications beyond shape analysis
- Partial correctness of sorting algorithms
- Safety of mobile code
- Deadlock detection in multi-threaded programs
- Partial correctness of mark-and-sweep gc alg.
52A Yacc for Static Analysis TVLA
- Parametric framework
- Some instantiations ? known analyses
- Other instantiations ? new analyses
- Applications beyond shape analysis
- Partial correctness of sorting algorithms
- Safety of mobile code
- Deadlock detection in multi-threaded programs
- Partial correctness of mark-and-sweep gc alg.
53A Yacc for Static Analysis(Using Logic)
- Correctness proofs via inductive-assertion
method - Proof derivation via weakest-precondition
calculus - Annotate your loops with invariants!
54A Yacc for Static Analysis(Using Logic)
I learned many things and equally important
I unlearned many things. S.K. Allison
- Correctness proofs via inductive-assertion
method - Proof derivation via weakest-precondition
calculus - Annotate your loops with invariants!
55A Yacc for Static Analysis(Using Logic)
- First-order structures ( predicate tables)
- hold recorded information
- model-theoretic approach, not proof-theoretic
- Formulae
- means for observing information
- Predicate-update formulae
- operational semantics
- update recorded information
56Recorded Information (for reverse)
57Recorded Information (for reverse)
58Formulae for Observing Properties
- Are x and y pointer aliases?
- ?v x(v) ? y(v)
- Does x point to a cell with a self cycle?
- ?v x(v) ? n(v,v)
- Is cell v heap-shared?
- ?v1,v2 n(v1,v) ? n(v2,v) ? v1 ? v2
59Are x and y Pointer Aliases?
?v x(v) ? y(v)
u2
u3
u4
u1
60Predicate-Update Formulae for y NULL
- x(v) x(v)
- y(v) 0
- t(v) t(v)
- n(v1,v2) n(v1,v2)
61Predicate-Update Formulae for y NULL
y(v) 0
62Predicate-Update Formulae for y x
- x(v) x(v)
- y(v) x(v)
- t(v) t(v)
- n(v1,v2) n(v1,v2)
63Predicate-Update Formulae for y x
y(v) x(v)
64Predicate-Update Formulae for x x ? n
- x(v) ?v1 x(v1) ? n(v1,v)
- y(v) y(v)
- t(v) t(v)
- n(v1, v2) n(v1, v2)
65Predicate-Update Formulae for x x ? n
x(v) ?v1 x(v1) ? n(v1,v)
x
y
u2
u3
u4
u1
66Predicate-Update Formulae for y ? n t
- x(v) x(v)
- y(v) y(v)
- t(v) t(v)
- n(v1,v2) ?y(v1)?? n(v1,v2) ? y(v1) ? t(v2)
67Outline
- Logic and box/arrow diagrams
- Kleenes 3-valued logic
- The abstraction principle
- Using 3-valued structures to represent sets of
stores - Conservative extraction of store properties
- Abstract interpretation
- More precise abstract interpretation
68Two- vs. Three-Valued Logic
0 ? 0,1
1 ? 0,1
69Two- vs. Three-Valued Logic
70Two- vs. Three-Valued Logic
Three-valued logic
71Two- vs. Three-Valued Logic
72Two- vs. Three-Valued Logic
0 ?3½
1 ?3½
73Boolean Connectives Kleene
74Three-Valued Logic
- 1 True
- 0 False
- 1/2 Unknown
- A join semi-lattice 0 ? 1 1/2
75Outline
- Logic and box/arrow diagrams
- Kleenes 3-valued logic
- The abstraction principle
- Using 3-valued structures to represent sets of
stores - Conservative extraction of store properties
- Abstract interpretation
- More precise abstract interpretation
76Why is Shape Analysis Difficult?
- Destructive updating through pointers
- p?next q
- Produces complicated aliasing relationships
- Dynamic storage allocation
- No bound on the size of run-time data structures
- Data-structure invariants typically only hold at
the beginning and end of operations - Need to verify that data-structure invariants are
re-established
77The Abstraction Principle
78The Abstraction Principle
- Partition the individuals into equivalence
classes based on the values of their unary
predicates - Collapse other predicates via ?
79What StoresDoes a 3-Valued Structure Represent?
- Example 3-valued structure
- individuals u1
- predicates
- graphical presentation
- concrete stores represented
80What StoresDoes a 3-Valued Structure Represent?
- Example 3-valued structure
- graphical presentation
- concrete stores
81What StoresDoes a 3-Valued Structure Represent?
- Example 3-valued structure
- graphical presentation
- concrete stores
82Property-Extraction Principle
- Questions about store properties can be answered
conservatively by evaluating formulae in
three-valued logic - Formula evaluates to 1
- ? formula always holds in every store ?
- Formula evaluates to 0
- ? formula never holds in any store ?
- Formula evaluates to 1/2
- ? dont know
? ?
83Are x and y Pointer Aliases?
?v x(v) ? y(v)
84Is Cell u Heap-Shared?
?v1,v2 n(v1,u) ? n(v2,u) ? v1 ? v2
85Outline
- Logic and box/arrow diagrams
- Kleenes 3-valued logic
- The abstraction principle
- Using 3-valued structures to represent sets of
stores - Conservative extraction of store properties
- Abstract interpretation
- More precise abstract interpretation
86Abstract Interpretation
87Abstract Interpretation
f (a,b) (16 b 3) (2 a 1)
O
O
O
E
O
O
E
?
E
E
?
f _ ? _ ? O
88Shape Analysis viaAbstract Interpretation
- Iteratively compute a set of 3-valued structures
for every program point - Every statement transforms structures according
to the predicate-update formulae - use 3-valued logic instead of 2-valued logic
- use exactly the predicate-update formulae of the
concrete semantics!!
89Predicate-Update Formulae for y x
y(v) x(v)
90Predicate-Update Formulae for x x ? n
x(v) ? v1 x(v1) ? n(v1,v)
91Abstract Interpretation
Concrete
Sets of stores
92Abstract Interpretation
Concrete
Sets of stores
93Abstract Interpretation
Concrete
94Abstract Interpretation
Concrete
95Abstract Interpretation
Concrete
96Abstract Interpretation
Concrete
97The Embedding Theorem
No
?v x(v) ? y(v)
No
No
Maybe
98The Embedding Theorem
No
?v x(v) ? y(v)
No
99The Embedding Theorem
- If a structure B can be embedded in a structure S
via a surjective (onto) function f such that
basic predicates are preserved, i.e., pB(u1,
.., uk) ? pS (f(u1), ..., f(uk)) - Then, every formula ? is preserved
- If ?1 in S, then ?1 in B
- If ?0 in S, then ?0 in B
- If ?1/2 in S, then ? could be 0 or 1 in B
100How Are We Doing?
- Conservative ?
- Convenient ?
- But not very precise ?
- Advancing a pointer down a list loses precision
- Cannot distinguish an acyclic list from a cyclic
list
101Cyclic versus Acyclic Lists
102Outline
- Logic and box/arrow diagrams
- Kleenes 3-valued logic
- The abstraction principle
- Using 3-valued structures to represent sets of
stores - Conservative extraction of store properties
- Abstract interpretation
- More precise abstract interpretation
103The Instrumentation Principle
- Increase precision by storing the truth-value of
some chosen formulae - Introduce predicate-update formulae to update the
extra predicates
104Example Heap Sharing
is(v) ?v1,v2 n(v1,v) ? n(v2,v) ? v1 ? v2
105Example Heap Sharing
is(v) ?v1,v2 n(v1,v) ? n(v2,v) ? v1 ? v2
is 1
x
x
u
u
u1
u1
is 0
is 1
is 0
106Is Cell u Heap-Shared?
is 0
is 0
?v1,v2 n(v1,u) ? n(v2,u) ? v1 ? v2
107Predicate-Update Formulae for y NULL
- x(v) x(v)
- y(v) 0
- t(v) t(v)
- n(v1,v2) n(v1,v2)
- is(v) is(v)
108Predicate-Update Formulae for y x
- x(v) x(v)
- y(v) x(v)
- t(v) t(v)
- n(v1,v2) n(v1,v2)
- is(v) is(v)
109Example Heap Sharing
is(v) ?v1,v2 n(v1,v) ? n(v2,v) ? v1 ? v2
110Predicate-Update Formulae for x x ? n
- x(v) ?v1 x(v1) ? n(v1,v)
- y(v) y(v)
- t(v) t(v)
- n(v1,v2) n(v1, v2)
- is(v) is(v)
111Predicate-Update Formulae for y ? n t
- x(v) x(v)
- y(v) y(v)
- t(v) t(v)
- n(v1,v2) ?y(v1)?? n(v1,v2) ? y(v1) ? t(v2)
- is(v)
?v1,v2 (is(v) ? n(v1,v) ? n(v2,v) ? v1 ?
v2) ? (t(v) ? n(v1,v) ? ?y(v1))
112Predicate-Update Formulae for y ? n t
- x(v) x(v)
- y(v) y(v)
- t(v) t(v)
- n(v1,v2) ?y(v1)?? n(v1,v2) ? y(v1) ? t(v2)
- is(v)
( ?((?v1 y(v1) ? n(v1,v2)) ? t(v)) ?
is(v)) ? ( ((?v1 y(v1) ? n(v1,v2)) ? t(v))
? (is(v) ? t(v)) ? ?v1,v2
n(v1,v) ? n(v1,v) ? v1 ? v2 )
113Additional Instrumentation Predicates
- reachable-from-variable-x(v)
- acyclic-along-dimension-d(v)
- à la ADDS
- doubly-linked(v)
- tree(v)
- dag(v)
- AVL trees
- balanced(v), left-heavy(v), right-heavy(v)
- . . . but not via height arithmetic
114Materialization
115Materialization
Chase, Wegman, Zadeck 90
x x ? n
116The Focusing Principle
- Bring the structure into better focus
- Selectively force 1/2 to 0 or 1
- Avoid indefiniteness
- Then apply the predicate-update formulae
117(1) Focus on ?v1 x(v1) ? n(v1,v)
u
118(2) Evaluate Predicate-Update Formulae
x (v) ?v1 x(v1) ? n(v1,v)
u
y
u1
u.1
u.0
119The Coercion Principle
- Increase precision by exploiting some structural
properties possessed by all stores - Structural properties captured by constraints
- Apply a constraint solver
120(3) Apply Constraint Solver
u1
x
y
u1
u.1
u.0
121(3) Apply Constraint Solver
x
y
u1
u.1
u.0
n(v1, v ) ? n(v2, v)?? v1 ? v2 ? is(v)
?is(v) ? n(v1, v)?? v1 ? v2 ? ?n(v2, v)
122(3) Apply Constraint Solver
x
y
u1
u.1
u.0
123(3) Apply Constraint Solver
x
y
u1
u.1
u.0
n(v1, v ) ? n(v2, v)?? v1 ? v2 ? is(v)
?is(v) ? n(v1, v)?? v1 ? v2 ? ?n(v2, v)
124(3) Apply Constraint Solver
x
y
u1
u.1
u.0
x(v1) ? x(v2) ? v1 v2
125(3) Apply Constraint Solver
x
y
u1
u.1
u.0
126Formalizing . . .
Informal
x
y
127Formalizing . . .
Informal
t1
x
y
t2
128Formalizing . . .
Informal
x
y
129Formalizing . . .
Informal
t1
x
y
t2
130Additional Instrumentation Predicates
- reachable-from-variable-x(v)
- acyclic-following-field-f(v)
- doubly-linked(v)
- tree(v)
- dag(v)
- AVL trees
- balanced(v), left-heavy(v), right-heavy(v)
- . . . but not via height arithmetic
131A Yacc for Shape Analysis
pointer-field predicates n(v1,v2)
instrumentation-predicate definitions is(v)
?v1,v2 n(v1,v) ? n(v2,v) ? v1 ? v2
predicate-update formulae stmt x NULL
is(v) is(v) x t
is(v) is(v) x
t ? n is(v) is(v)
x ? n t is(v)
?v1,v2 (is(v) ? n(v1,v) ? n(v2,v) ? v1 ? v2)
? (t(v) ? n(v1,v) ?
?y(v1)) x malloc(INT)
is(v) is(v) ? ?NEW(v)
132Example In-Situ List Reversal
typedef struct list_cell int val
struct list_cell next List
List reverse (List x) List y, t y
NULL while (x ! NULL) t y
y x x x ? next y ? next
t return y
Run Demo
133Example Mark and Sweep
void Sweep() unexplored Universe
collected ? while (unexplored ? ?) x
SelectAndRemove(unexplored) if (x ? marked)
collected collected ? x
assert(collected Universe
Reachset(root) )
void Mark(Node root) if (root ? NULL)
pending ? pending pending ? root
marked ? while (pending ? ?)
x SelectAndRemove(pending) marked
marked ? x t x ? left if (t
? NULL) if (t ? marked)
pending pending ? t t x ? right
if (t ? NULL) if (t ? marked)
pending pending ? t
assert(marked Reachset(root))
Run Demo
134TVLA - A YACC for Static Analysis
- TVLA - Three Valued Logic Analyzer
- Abstract interpretation
- Concrete and abstract elements represented using
3-valued logical structures - Operational semantics described using logical
formulae - Automatically derives the abstract semantics
135TVLA Specifications
- TVP Three-Valued Program
- Predicate declarations
- Action declarations
- action class of edge transformer
- Control flow graph
- Instantiation of actions
- TVS Three-Valued Structure
- 3-valued structures for the entry point
1363-Valued Logical Structures
137Predicate Declarations
- p n(v1, v2)
- foreach (z in PVars) p z(v) i rn,z(v)
?v1 z(v1)?? n(v1, v)
138Action Declaration(Operational Semantics)for y
x
- action Copy_Var_Elements(y, x)
-
- y(v) x(v)
- rn,y(v) rn,x(v)
-
139Predicate-Update Formulae for y x
y(v) x(v) rn,y(v) rn,x(v)
Old
140Action Instantiation in TVP FileEdge in CFG for
a b
- n17 Copy_Var_Elements(a, b) n18
141Action Declaration(Operational Semantics)for x
y-gtn
- action Get_Next_Element(x, y)
- f ?v1 y(v1)?? n(v1, v)
-
- x(v) ?v1 y(v1)?? n(v1, v)
- rn,x(v) rn,y(v) ? ?y(v)
-
142Predicate-Update Formulae forx x-gtn
x(v) ? v1 x(v1) ? n(v1,v) rn,x(v)
rn,x(v) ? ?x(v)
Old
143More Precise Abstract Semantics
- Six stages
- Focus
- Coerce (apply constraint solver)
- Evaluate preconditions
- Evaluate update formulae
- Coerce (apply constraint solver)
- Blur (re-abstract)
- TVLA flag fcpucb
144(1) Focus on ? v1 x(v1) ? n(v1,v)
145(4) Evaluate Predicate-Update Formulae
x(v) ? v1 x(v1) ? n(v1,v)
146(5) Apply Constraint Solver
147Cleanness Analysis
- Describe cleanness conditions as formulae
- Evaluate the formula before each statement
- Report a message when a cleanness condition is
violated
148Action Declaration(Operational Semantics)for x
y-gtn
- action Get_Next_Element(x, y)
- f ?v1 y(v1)?? n(v1, v)
- message (? ?v y(v)) -gt
- Possible dereference of NULL pointer
- x(v) ?v1 y(v1)?? n(v1, v)
- rn,x(v) rn,y(v) ? ?y(v)
149More Precise Abstract Semantics
- Six stages
- Focus
- Coerce (apply constraint solver)
- Evaluate preconditions
- Evaluate update formulae
- Coerce (apply constraint solver
- TVLA flag fcpucb
150TVLA Applications
- Cleanness analysis
- Singly linked lists
- Doubly linked lists
- Proving partial correctness of sorting programs
- delete, insert, reverse, merge functions
- insert and bubble sort
- But not quick sort yet
- Mobile Ambients
- Java concurrency (synchronization, deadlocks)
151TVLA Experience
- Quite fast on small programs
- Not a panacea
- More instrumentation may lead to faster (and more
precise) analysis
152Further Work
- Scalability
- Space
- Inter-procedural Analysis
- Automatic generation of update formulae
- Multi-sorted logic to simulate types
- C front-end
153Conclusions
- TVLA - a parametric framework for building static
analysis algorithms - Useful for a variety of analysis problems
- Scalability issues
154Why is Shape Analysis Difficult?
- Destructive updating through pointers
- p?next q
- Produces complicated aliasing relationships
- Track aliasing on 3-valued structures
- Dynamic storage allocation
- No bound on the size of run-time data structures
- Abstraction principle ? finite-sized 3-valued
structures - Data-structure invariants typically only hold at
the beginning and end of operations - Need to verify that data-structure invariants are
re-established - Evaluate formulas over 3-valued structures
155TVLA vs. Model Checking
TVLA
Model checking
- Determine properties of a transition system
- State-space exploration
- State labels 1st-order structures
- 3-valued structures represent commonalities
- Properties checked Formulas in FOTC
- Determine properties of a transition system
- State-space exploration
- State labels Propositions
- BDDs represent commonalities
- Properties checked Formulas in temporal logic
156(No Transcript)