Title: Abstract Interpretation with Alien Expressions and Heap Structures
1Abstract Interpretation with Alien Expressions
and Heap Structures
- Bor-Yuh Evan Chang K. Rustan M. Leino
- UC Berkeley Microsoft Research
- November 11, 2004
- OSQ Meeting
2Standard Abstract Interpretation
- y 8 x 0
- while ()
- y y x
- x
-
- y 8
- Can do this inference with the polyhedra abstract
domain CH79 -
3Standard Abstract Interpretation
- this.y 8 this.x 0
- while ()
- this.y this.y this.x
- this.x
-
- this.y 8?
- Goal Given a base domain that can infer certain
kind of predicates on variables, use it to infer
predicates on fields
4Achieving the Goal
- Handling Alien Expressions
- / Uninterpreted Functions
- Handling Heap Updates
5Abstract Domains
- interface AbstractDomain
- type Elt
- Constrain Elt Expr ! Elt
- Eliminate Elt Var ! Elt
- Rename Elt Var Var ! Elt
- ToPredicate Elt ! Expr
- Join Elt Elt ! Elt
- AtMost Elt Elt ! bool
6Fooling the Base Domains
assume o.f 8
Constrain( sel(H,o,f) 8 )
Congruence-Closure Domain / Name Service
sel(H,o,f) ? ?
SymbolicValue
Constrain( ? 8 )
Polyhedra
Base Domains
7Understandable to the Base Domain
Understands FunSymbol Expr ! bool
sel
²
2 x sel(H,o,f) y - z
8Understandable to the Base Domain
Understands FunSymbol Expr ! bool
Yes
Yes
sel
²
Yes
No
Yes
2 x sel(H,o,f) y - z
9Understandable to the Base Domain
Understands FunSymbol Expr ! bool
No
?
²
No
2 x ? y - z
10Understandable to the Base Domain
Understands FunSymbol Expr ! bool
?
No
?
?
²
Yes
? y - z
2
x
y
z
2 x ? ?
11Congruence-Closure Domain
- Could always choose new names, but
- Should use the same name for syntactically
equivalent expressions - Even Better same name for known equalities
- Tracks equalities of uninterpreted functions
- an E-Graph with abstract domain operations
- symbolic values name equivalence classes of
expressions - implements congruence closure
12E-Graph
- w f(x) Æ g(x,y) f(y) Æ w h(w)
- A set of mappings
- w ? ?
- x ? ?
- f(?) ? ?
- y ? ?
- g(b,g) ? d
- f(?) ? d
- h(?) ? ?
- Always congruence-closed
13Join
- Join the e-graphs, then join the base domains
- Think of the lattice over conjunctions of
equalities (including infinite ones) - Let G Join(G0,G1)
- x ?G h?,?i if x ?G0 ? and x ?G1 ?
- f(h?,?i) ?G h?,?i if f(?) ?G0 ? and f(b)
?G1 b - Rename distinct pairs to fresh symbolic values
14Join
- Complexity O(nm)
- Complete? As precise as possible?
- No, e-graphs do not form a lattice!
- x y t g(x) g(y) Æ x f(x) Æ y f(y)
- Æi i 0 g(fi(x)) g(fi(y))
- Only relatively complete
- Gulwani et al.
- Tell base domains about renaming
- h?,?i à g ConstrainB0(? ?), ConstrainB1(? ?)
15So Far We Have
- Reasoning for uninterpreted functions
- Base domains that work with alien expressions
transparently - What we need for field reads
- sel is alien to all base domains
16Achieving the Goal
- Handling Alien Expressions
- / Uninterpreted Functions
- Handling Heap Updates
17Heap Updates
- Java/C if (p.g 8) o.f x
- Abstract assume Hp,g 8
- Interpreter H upd(H,o,f,x)
- sel(upd(H,o,f,e),o,f) e
- if o o and f f
- sel(upd(H,o,f,e),o,f) sel(H,o,f)
- if o ? o or f ? f
18Heap Updates
- Java/C if (p.g 8) o.f x
- Abstract assume Hp,g 8
- Interpreter H H where
- H o,f H and
- sel(H,o,f) x
19Heap Updates
- Abstract assume Hp,g 8
- Interpreter H H where
- H o,f H and
- sel(H,o,f) x
- Abstract Constrain( sel(H,p,g) 8 )
- Domain Constrain( H o,f H )
- Constrain( sel(H,o,f) x )
- Eliminate( H )
- Rename( H, H )
- ToPredicate()
Tracked by a new base domain Heap Succession
20Heap Update Example
Constrain( sel(H,p,g) 8 ) Constrain( H o,f H
) Constrain( sel(H,o,f) x ) Eliminate( H
) Rename( H, H ) ToPredicate()
- Heap Succession
- H o,f H
- E-Graph
- sel(H,p,g) ? ?
- 8 ? ?
- sel(H,o,f) ? ?
- x ? ?
- H ? H p ? p
- H ? H g ? g
- o ? o f ? f
21Heap Update Example
Constrain( sel(H,p,g) 8 ) Constrain( H o,f H
) Constrain( sel(H,o,f) x ) Eliminate( H
) Rename( H, H ) ToPredicate()
- Heap Succession
- H o,f H
- E-Graph
- sel(H,p,g) ? ?
- 8 ? ?
- sel(H,o,f) ? ?
- x ? ?
- H ? H p ? p
- H ? H g ? g
- o ? o f ? f
22Heap Update Example
Constrain( sel(H,p,g) 8 ) Constrain( H o,f H
) Constrain( sel(H,o,f) x ) Eliminate( H
) Rename( H, H ) ToPredicate()
- Heap Succession
- H o,f H
- E-Graph
- sel(H,p,g) ? ?
- 8 ? ?
- sel(H,o,f) ? ?
- x ? ?
- H ? H p ? p
- H ? H g ? g
- o ? o f ? f
23Heap Update Example
Constrain( sel(H,p,g) 8 ) Constrain( H o,f H
) Constrain( sel(H,o,f) x ) Eliminate( H
) Rename( H, H ) ToPredicate()
- Heap Succession
- H o,f H
- E-Graph
- sel(H,p,g) ? ?
- 8 ? ?
- sel(H,o,f) ? ?
- x ? ?
- H ? H p ? p
- H ? H g ? g
- o ? o f ? f
- Collect Garbage (H)
- EquivalentExpr
- Queryable Expr Var
- ! Expr
24Heap Update Example
Constrain( sel(H,p,g) 8 ) Constrain( H o,f H
) Constrain( sel(H,o,f) x ) Eliminate( H
) Rename( H, H ) ToPredicate()
- Heap Succession
- H o,f H
- E-Graph
- sel(H,p,g) ? ?
- 8 ? ?
- sel(H,o,f) ? ?
- x ? ?
- H ? H p ? p
- H ? H g ? g
- o ? o f ? f
Yes, use H
- Collect Garbage (H)
- EquivalentExpr
- Queryable Expr Var
- ! Expr option
- Eliminate(H) on Base
- ToPredicate() on Base and Convert Expr for Client
- Add Equalities
25Related Work
- Join for Uninterpreted Functions Gulwani,
Tiwari, Necula - Shape Analysis many and
- TVLA Sagiv, Reps, Wilhelm,
26Conclusion
- Extended the power of abstract domains to work
with alien expressions using the
congruence-closure domain - Added reasoning about heap updates with the heap
succession domain - Close to having cooperating abstract
interpreters? - missing propagating back equalities inferred by
base domains
27Thank you!