270 likes | 405 Vues
This paper explores innovative methods in abstract interpretation, specifically addressing the challenges of analyzing alien expressions and heap structures using a base domain. We present techniques that leverage the polyhedra abstract domain to enhance the inference of predicates on variables and fields. Key focuses include handling uninterpreted functions, various heap update scenarios, and ensuring congruence closure while maintaining aliasing properties. Our approach utilizes e-graphs to track equivalences in expressions, proving effective in dealing with complex program semantics.
E N D
Abstract Interpretation with Alien Expressions and Heap Structures Bor-Yuh Evan Chang K. Rustan M. Leino UC Berkeley Microsoft Research November 11, 2004 OSQ Meeting
Standard Abstract Interpretation y := 8; x := 0; while (*) { y := y + x; x++; } y ¸ 8 • Can do this inference with the polyhedra abstract domain [CH79]
Standard 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
Achieving the Goal • Handling Alien Expressions / Uninterpreted Functions • Handling Heap Updates
Abstract 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 }
Fooling 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
2 x y z H o f Understandable to the Base Domain Understands : FunSymbol £ Expr[] ! bool ¸ + | | ² sel 2 ¢ x +sel(H,o,f)· |y - z|
2 x y z H o f Understandable to the Base Domain Understands : FunSymbol £ Expr[] ! bool ¸ Yes + | | Yes ² sel Yes No Yes 2 ¢ x +sel(H,o,f)· |y - z|
2 x y z Understandable to the Base Domain Understands : FunSymbol £ Expr[] ! bool ¸ + | | No ² No 2 ¢ x +· |y - z|
Understandable to the Base Domain Understands : FunSymbol £ Expr[] ! bool ¸ + No ² Yes = y - z 2 x y z 2 ¢ x+·
Congruence-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
x y w b g f f g d h E-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
Join • 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 Gh’,’i if x G0’ and x G1’ f(h,i)Gh’,’i if f()G0’ and f(b)G1b’ • Rename distinct pairs to fresh symbolic values
Join • Complexity: O(n¢m) • Complete? As precise as possible? • No, e-graphs do not form a lattice! x = y tg(x) = g(y)Æ x = f(x)Æ y = f(y) = Æi : i ¸ 0g(fi(x)) = g(fi(y)) • Only relatively complete [Gulwani et al.] • Tell base domains about renaming h,iÃgConstrainB0(=), ConstrainB1(=)
So 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
Achieving the Goal • Handling Alien Expressions / Uninterpreted Functions • Handling Heap Updates
Heap Updates Java/C# if (p.g == 8) { o.f = x; } Abstract assume H[p,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’
Heap Updates Java/C# if (p.g == 8) { o.f = x; } Abstract assume H[p,g] == 8; Interpreter H := H’ where H’ ´o,f H and sel(H’,o,f)= x
Heap Updates Abstract assume H[p,g] == 8; Interpreter H := H’ where H’ ´o,f H and sel(H’,o,f)= x Abstract Constrain(sel(H,p,g) = 8) DomainConstrain( H’ ´o,f H ) Constrain(sel(H’,o,f)= x ) Eliminate( H ) Rename( H’, H ) ToPredicate() Tracked by a new base domain: Heap Succession
Heap 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,fH E-Graph sel(H,p,g) 8 sel(H’,o,f) x H H p p H’ H’gg o off
Heap 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,fH E-Graph sel(H,p,g) 8 sel(H’,o,f) x H H p p H’ H’gg o off
Heap 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,fH E-Graph sel(H,p,g) 8 sel(H’,o,f) x H H p p H H’gg o off
Can you give me an equivalent expression without H? Heap 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,fH E-Graph sel(H,p,g) 8 sel(H’,o,f) x H H p p H H’gg o off • “Collect Garbage” (H) • EquivalentExpr : Queryable £ Expr £ Var ! Expr
Heap 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,fH E-Graph sel(H’,p,g) 8 sel(H’,o,f) x H H p p H H’gg o off 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
Related Work • Join for Uninterpreted Functions [Gulwani, Tiwari, Necula] • Shape Analysis [many] and TVLA [Sagiv, Reps, Wilhelm, …]
Conclusion • 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
Thank you! Questions? Comments?