Taming Pointers
A Symbolic Approach
Jianwen Zhu
jzhu@eecg.toronto.edu
Electrical and Computer Engineering University of Toronto
- J. Zhu c
’04 – p.1/33
Taming Pointers A Symbolic Approach Jianwen Zhu - - PowerPoint PPT Presentation
Taming Pointers A Symbolic Approach Jianwen Zhu jzhu@eecg.toronto.edu Electrical and Computer Engineering University of Toronto 04 p.1/33 J. Zhu c Outline An Old Problem A New Strategy Taming Context Sensitivity Result and
Jianwen Zhu
jzhu@eecg.toronto.edu
Electrical and Computer Engineering University of Toronto
’04 – p.1/33
’04 – p.2/33
char *g, a, h1, h2; 1 void main() { 2 char *p, *q; 3 S0: alloc( &p, &h1 ); 4 S1: p = getg( &q ); 5 S2: g = &a; 6 } 7 8 char* getg( char** r ) { 9 char **t; 10 S0: t = &g; 11 if( g == NULL ) 12 S1: alloc( t, &h2 ); 13 S2: *r = *t; 14 S3: return *r; 15 } 16 17 void alloc( char** f, char* h ) { 18 S0: *f = h; 19 } 20
’04 – p.3/33
char *g, a, h1, h2; 1 void main() { 2 char *p, *q; 3 S0: alloc( &p, &h1 ); 4 S1: p = getg( &q ); 5 S2: g = &a; 6 } 7 8 char* getg( char** r ) { 9 char **t; 10 S0: t = &g; 11 if( g == NULL ) 12 S1: alloc( t, &h2 ); 13 S2: *r = *t; 14 S3: return *r; 15 } 16 17 void alloc( char** f, char* h ) { 18 S0: *f = h; 19 } 20
return h2 g a p t q
’04 – p.3/33
char *g, a, h1, h2; 1 void main() { 2 char *p, *q; 3 S0: alloc( &p, &h1 ); 4 S1: p = getg( &q ); 5 S2: g = &a; 6 } 7 8 char* getg( char** r ) { 9 char **t; 10 S0: t = &g; 11 if( g == NULL ) 12 S1: alloc( t, &h2 ); 13 S2: *r = *t; 14 S3: return *r; 15 } 16 17 void alloc( char** f, char* h ) { 18 S0: *f = h; 19 } 20
return h2 g a p t q
’04 – p.3/33
’04 – p.4/33
’04 – p.4/33
’04 – p.4/33
’04 – p.5/33
char *g, a, h1, h2; 1 void main() { 2 char *p, *q; 3 S0: alloc( &p, &h1 ); 4 S1: p = getg( &q ); 5 S2: g = &a; 6 } 7 8 char* getg( char** r ) { 9 char **t; 10 S0: t = &g; 11 if( g == NULL ) 12 S1: alloc( t, &h2 ); 13 S2: *r = *t; 14 S3: return *r; 15 } 16 17 void alloc( char** f, char* h ) { 18 S0: *f = h; 19 } 20
’04 – p.6/33
char *g, a, h1, h2; 1 void main() { 2 char *p, *q; 3 S0: alloc( &p, &h1 ); 4 S1: p = getg( &q ); 5 S2: g = &a; 6 } 7 8 char* getg( char** r ) { 9 char **t; 10 S0: t = &g; 11 if( g == NULL ) 12 S1: alloc( t, &h2 ); 13 S2: *r = *t; 14 S3: return *r; 15 } 16 17 void alloc( char** f, char* h ) { 18 S0: *f = h; 19 } 20
return a h1 h2 g p q t
’04 – p.6/33
char *g, a, h1, h2; 1 void main() { 2 char *p, *q; 3 S0: alloc( &p, &h1 ); 4 S1: p = getg( &q ); 5 S2: g = &a; 6 } 7 8 char* getg( char** r ) { 9 char **t; 10 S0: t = &g; 11 if( g == NULL ) 12 S1: alloc( t, &h2 ); 13 S2: *r = *t; 14 S3: return *r; 15 } 16 17 void alloc( char** f, char* h ) { 18 S0: *f = h; 19 } 20
return a h2 g p h1 q t
’04 – p.6/33
char *g, a, h1, h2; 1 void main() { 2 char *p, *q; 3 S0: alloc( &p, &h1 ); 4 S1: p = getg( &q ); 5 S2: g = &a; 6 } 7 8 char* getg( char** r ) { 9 char **t; 10 S0: t = &g; 11 if( g == NULL ) 12 S1: alloc( t, &h2 ); 13 S2: *r = *t; 14 S3: return *r; 15 } 16 17 void alloc( char** f, char* h ) { 18 S0: *f = h; 19 } 20
return h2 g a p t q
’04 – p.6/33
Single procedure analysis W.T. dynamic mem W.O. dynamic mem W.T. types W.O. types Levels ≥ 2 Levels < 2 PSPACE-Complete PSPACE-Complete Undecidable in P
’04 – p.7/33
Single procedure analysis W.T. dynamic mem W.O. dynamic mem W.T. types W.O. types Levels ≥ 2 Levels < 2 PSPACE-Complete PSPACE-Complete Undecidable in P
main getg alloc
’04 – p.7/33
Single procedure analysis W.T. dynamic mem W.O. dynamic mem W.T. types W.O. types Levels ≥ 2 Levels < 2 PSPACE-Complete PSPACE-Complete Undecidable in P
main_1 getg_1 S1 alloc_1 S0 alloc_2 S1
’04 – p.7/33
Single procedure analysis W.T. dynamic mem W.O. dynamic mem W.T. types W.O. types Levels ≥ 2 Levels < 2 PSPACE-Complete PSPACE-Complete Undecidable in P
104 105 106 107 108 109 1010 1011 1012 1013 1014 1015
’04 – p.7/33
’04 – p.8/33
’04 – p.9/33
’04 – p.10/33
’04 – p.10/33
’04 – p.10/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
’04 – p.11/33
λR(i, j) =
✂✁ ✄0, if i, j / ∈ R 1, if i, j ∈ R
i , V 1 j be the ith, jth
i V 1 j
’04 – p.12/33
λR(i, j) =
✂✁ ✄0, if i, j / ∈ R 1, if i, j ∈ R
1 2 3 4 5 6 7
i , V 1 j be the ith, jth
i V 1 j
’04 – p.12/33
λR(i, j) =
✂✁ ✄0, if i, j / ∈ R 1, if i, j ∈ R
1 2 3 4 5 6 7
i , V 1 j be the ith, jth
i V 1 j
λE = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
’04 – p.12/33
’04 – p.13/33
’04 – p.13/33
1 2 3 4 5 6 7
’04 – p.13/33
1 2 3 4 5 6 7
Given r = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
s = V 0
1
’04 – p.13/33
1 2 3 4 5 6 7
Given r = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
s = V 0
1
Step 1: s∧r = V 0
1 V 1 4
’04 – p.13/33
1 2 3 4 5 6 7
Given r = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
s = V 0
1
Step 1: s∧r = V 0
1 V 1 4
Step 2: ∃V 0.s ∧ r = V 1
4
’04 – p.13/33
1 2 3 4 5 6 7
Given r = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
s = V 0
1
Step 1: s∧r = V 0
1 V 1 4
Step 2: ∃V 0.s ∧ r = V 1
4
Step 3: [∃V 0.s ∧ r]|V 1→V 0 = V 0
4
’04 – p.13/33
1 2 3 4 5 6 7
’04 – p.14/33
1 2 3 4 5 6 7
Given r = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
s = V 0
1 + V 0 2 + V 0 3
’04 – p.14/33
1 2 3 4 5 6 7 1 2 3 4 5 6 7
Given r = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
s = V 0
1 + V 0 2 + V 0 3
Step 1: s ∧ r = V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
Step 2: ∃V 0.s ∧ r = V 1
4 + V 1 5 + V 1 6
Step 3: [∃V 0.s ∧ r]|V 1→V 0 = V 0
4 + V 0 5 + V 0 6
’04 – p.14/33
1 2 3 4 5 6 7 1 2 3 4 5 6 7
Given r = V 0
0 V 1 1 + V 0 0 V 1 2 + V 0 0 V 1 3
+ V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
+ V 0
4 V 1 7 + V 0 5 V 1 7 + V 0 6 V 1 7
s = V 0
1 + V 0 2 + V 0 3
Step 1: s ∧ r = V 0
1 V 1 4 + V 0 2 V 1 5 + V 0 3 V 1 6
Step 2: ∃V 0.s ∧ r = V 1
4 + V 1 5 + V 1 6
Step 3: [∃V 0.s ∧ r]|V 1→V 0 = V 0
4 + V 0 5 + V 0 6
’04 – p.14/33
1 2 3 4 5 6 7
1 2 3 4 5 6 7
reachable( s : V 0, g : V 0 × V 1 ) 1 : V 0 { 2 var image, reached : V 0; 3 image = s; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached ; 11 } 12
’04 – p.15/33
1 2 3 4 5 6 7
1 2 3 4 5 6 7
reachable( s : V 0, g : V 0 × V 1 ) 1 : V 0 { 2 var image, reached : V 0; 3 image = s; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached ; 11 } 12
’04 – p.15/33
1 2 3 4 5 6 7
1 2 3 4 5 6 7
reachable( s : V 0, g : V 0 × V 1 ) 1 : V 0 { 2 var image, reached : V 0; 3 image = s; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached ; 11 } 12
’04 – p.15/33
1 2 3 4 5 6 7
1 2 3 4 5 6 7
reachable( s : V 0, g : V 0 × V 1 ) 1 : V 0 { 2 var image, reached : V 0; 3 image = s; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached ; 11 } 12
’04 – p.15/33
’04 – p.16/33
light Quantum computer light
’04 – p.16/33
light Quantum computer light
’04 – p.16/33
light Quantum computer light
set Relation r : V0 * V1 set
’04 – p.16/33
light Quantum computer light
input superposition Superposed Symbolic Computer
superposition
s : I × V 0, r : I × V 0 × V 1 s ∧ r : I × V 0 × V 1 ∃V 0.s ∧ r : I × V 1 [∃V 0.s ∧ r]|V 1→V 0 : I × V 0
’04 – p.16/33
closure( g : V 0 × V 1 ) 1 : V 0 × V 1{ 2 var image, reached : V 2 × V 0; 3 image = V 2 == V 0; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached|V 2→V 0,V 1→V 1 ; 11 } 12
1 2 3 4 5 6 7
1 2 3 4 5 6 7
’04 – p.17/33
closure( g : V 0 × V 1 ) 1 : V 0 × V 1{ 2 var image, reached : V 2 × V 0; 3 image = V 2 == V 0; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached|V 2→V 0,V 1→V 1 ; 11 } 12
1 2 3 4 5 6 7
1 2 3 4 5 6 7
’04 – p.17/33
closure( g : V 0 × V 1 ) 1 : V 0 × V 1{ 2 var image, reached : V 2 × V 0; 3 image = V 2 == V 0; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached|V 2→V 0,V 1→V 1 ; 11 } 12
1 2 3 4 5 6 7
1 2 3 4 5 6 7
’04 – p.17/33
closure( g : V 0 × V 1 ) 1 : V 0 × V 1{ 2 var image, reached : V 2 × V 0; 3 image = V 2 == V 0; 4 reached = 0; 5 while( image = 0 ) { 6 image = [∃V 0.image ∧ g]|V 1→V 0 ; 7 reached = reached ∨ image; 8 image = image ∧ ¬reached; 9 } 10 return reached|V 2→V 0,V 1→V 1 ; 11 } 12
1 2 3 4 5 6 7
1 2 3 4 5 6 7
’04 – p.17/33
’04 – p.18/33
’04 – p.18/33
’04 – p.18/33
’04 – p.18/33
call : (M0 × S0 × C0) × (M1 × C1) tr : M0 × (B2 × P 0) × (B3 × P 1) path : P 0 × F 0 × P 1 inmap : M0 × S0 × (B2 × P 0) × (B3 × P 1)
: M0 × S0 × (B2 × P 0) × (B3 × P 1)
’04 – p.19/33
call : (M0 × S0 × C0) × (M1 × C1) tr : M0 × (B2 × P 0) × (B3 × P 1) path : P 0 × F 0 × P 1 inmap : M0 × S0 × (B2 × P 0) × (B3 × P 1)
: M0 × S0 × (B2 × P 0) × (B3 × P 1)
s : B0 × F 0 × B1 q : M0 × C0 × (B2 × P 0) × B0
’04 – p.19/33
call : (M0 × S0 × C0) × (M1 × C1) tr : M0 × (B2 × P 0) × (B3 × P 1) path : P 0 × F 0 × P 1 inmap : M0 × S0 × (B2 × P 0) × (B3 × P 1)
: M0 × S0 × (B2 × P 0) × (B3 × P 1)
s : B0 × F 0 × B1 q : M0 × C0 × (B2 × P 0) × B0
s =
apply(tr, q)
q =
bind(query(s, path), inmap, outmap, call)
’04 – p.19/33
A B C D E
’04 – p.20/33
A B C D E A0 C0 B0 D0 E0 C1 D1 E1
’04 – p.20/33
A B C D E A0 C0 B0 D0 E0 C1 D1 E1 A B C D E
C0 0 C1 C0 0 C1 C0 0 C1 1 C0 0 C1 0 + C0 1 C1 1 C0 0 C1 0 + C0 1 C1 1
’04 – p.20/33
A B C D E A0 C0 B0 D0 E0 C1 D1 E1 A B C D E
0, 0 0, 0 0, 1 0, 0, 1, 1 0, 0, 1, 1
’04 – p.20/33
A(1) B(0) C(0) D(0) E(0)
’04 – p.21/33
A(1) B(1) C(0) D(0) E(0)
0, 0
’04 – p.21/33
A(1) B(1) C(1) D(0) E(0)
0, 0 0, 0
’04 – p.21/33
A(1) B(1) C(2) D(0) E(0)
0, 0 0, 0 0, 1
’04 – p.21/33
A(1) B(1) C(2) D(2) E(0)
0, 0 0, 0 0, 1 0, 0, 1, 1
’04 – p.21/33
A(1) B(1) C(2) D(2) E(2)
0, 0 0, 0 0, 1 0, 0, 1, 1 0, 0, 1, 1
’04 – p.21/33
caller callee (offset) ... caller (count)
’04 – p.22/33
’04 – p.23/33
’04 – p.23/33
x0 y0 z0 x1 y1 z1 x2 y2 z2 x3 y3 z3
’04 – p.23/33
x0 y0 z0 x1 y1 z1 x2 y2 z2 x3 y3 z3 x0 y0 x1 y1 x2 y2 x3 y3
’04 – p.23/33
’04 – p.24/33
’04 – p.24/33
x0 y0 z0 x1 y1 z1 x2 y2 z2 x3 y3 z3 x0 y0 x1 y1 x2 y2 x3 y3
’04 – p.25/33
x0 y0 z0 x1 y1 z1 x2 y2 z2 x3 y3 z3 x0 y0 x1 y1 x2 y2 x3 y3
’04 – p.25/33
’04 – p.26/33
’04 – p.26/33
’04 – p.26/33
’04 – p.26/33
prolangs MediaBench SPEC2000 name #lines #contexts #blocks name #lines #contexts #blocks name #lines #contexts #blocks 315 1411 49 136 gsm 5473 267 1124 vortex 67211 9.217*1010 18433 TWMC 24032 6522 4613 pegwit 5503 1968 1121 bzip2 4665 495 995 simulator 3558 8953 1316 pgp 28065 199551 5265 vpr 16984 179905 4318 larn 9933 1750823 6180 mpeg2dec 9823 44979 2748 crafty 19478 317378 5282 moria 25002 318675286 9446 mpeg2enc 7605 1955 2997 twolf 19756 5538 4231
’04 – p.27/33
’04 – p.28/33
Flow Solver Total Benchmarks Time Time Time (s) (s) (s) prolangs 315 CS 0.01 0.01 FS 0.01 0.01 FSCS 0.04 0.01 0.05 FSCS∗ 0.04 0.01 0.05 T-W-MC CS 3.72 3.72 FS 4.43 0.59 5.02 FSCS 8.71 1.76 10.47 FSCS∗ 8.86 1.68 10.54 larn CS 0.83 0.83 FS 0.67 0.19 0.86 FSCS 21.83 1.64 23.47 FSCS∗ 21.94 1.68 23.62 moria CS 1.47 1.47 FS 2.24 0.47 2.71 FSCS 40.60 4.4 45.00 FSCS∗ 40.87 4.47 45.34 simulator CS 0.10 0.10 FS 0.06 0.04 0.1 FSCS 0.76 0.10 0.86 FSCS∗ 0.79 0.14 0.93
’04 – p.29/33
Flow Solver Total Benchmarks Time Time Time (s) (s) (s) MediaBench gsm CS 0.05 0.05 FS 0.19 0.05 0.24 FSCS 0.55 0.1 0.65 FSCS∗ 0.59 0.08 0.67 mpeg2dec CS 0.20 0.20 FS 0.29 0.23 0.52 FSCS 3.15 0.54 3.69 FSCS∗ 3.23 0.48 2.19 mpeg2enc CS 0.19 0.19 FS 0.95 0.14 1.09 FSCS 1.44 0.27 1.71 FSCS∗ 1.52 0.23 1.75 pegwit CS 0.12 0.12 FS 0.09 0.09 0.18 FSCS 0.97 0.26 1.23 FSCS∗ 0.96 0.25 1.21 pgp CS 1.05 1.05 FS 2.32 0.73 3.05 FSCS 26.28 6.03 32.31 FSCS∗ 26.19 5.90 32.09
’04 – p.30/33
Flow Solver Total Benchmarks Time Time Time (s) (s) (s) SPEC2000 255.vortex CS 4.32 4.32 FS 10.53 1.31 11.84 FSCS 135.59 7.49 143.08 FSCS∗ 136.68 7.71 144.39 186.crafty CS 0.53 0.53 FS 3.1 0.44 3.54 FSCS 12.12 2.06 14.18 FSCS∗ 12.17 2.09 14.26 256.bzip2 CS 0.02 0.02 FS 0.06 0.02 0.08 FSCS 0.3 0.06 0.36 FSCS∗ 0.32 0.06 0.38 300.twolf CS 0.09 0.09 FS 5.25 0.09 5.34 FSCS 9.19 0.26 9.45 FSCS∗ 9.21 0.20 9.41 175.vpr CS 0.23 0.23 FS 1.37 0.1 1.47 FSCS 5.96 0.4 6.36 FSCS∗ 5.84 0.34 6.18
’04 – p.31/33
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 % difference − Pointer Cardinality l a r n m
i a s i m u l a t
g s m m p e g 2 d e c m p e g 2 e n c p e g w i t p g p b z i p 2 c r a f t y t w
f v
t e x v p r CI CS
’04 – p.32/33
’04 – p.33/33
’04 – p.33/33
’04 – p.33/33
’04 – p.33/33
[Zhu(2002)] Jianwen Zhu. Symbolic pointer analysis. In Proceedings of the International Conference on Computer-Aided Design (ICCAD), San Jose, November 2002. [Berndl et al.(2003)Berndl, Lhoták, Qian, Hendren, and Umanee] Marc Berndl, Ondˇ rej Lhoták, Feng Qian, Laurie Hendren, and Navindra Umanee. Point-to analysis using BDD. In Proceedings of the ACM SIGPLAN Conference
[Zhu and Calman(2004)] Jianwen Zhu and Silvian Calman. Symbolic pointer analysis revisited. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), June 2004. [Lhoták and Hendren(2004)] Ondˇ rej Lhoták and Laurie Hendren. Jedd: A BDD-based relational extension of Java. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), June 2004. [Whaley and Lam(2004)] John Whaley and Monica Lam. Cloning-based context-sensitive pointer alias analysis using binary decision diagrams. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI), June 2004.
’04 – p.34/33