cs618: program analysis 2016-17 ist semester - pointer ... filecs618: program analysis 2016-17 ist...
TRANSCRIPT
CS618: Program Analysis
2016-17 Ist Semester
Pointer Analysis
Amey Karkare
Department of CSE, IIT Kanpur/Bombay
karkare, CSE, IITK/B CS618 1/27
Why Pointer Analysis?
Static analysis of pointers & references
S1. . . .
S2. q = p;S3. do {S4. q = q.next ;S5. } while (. . .)S6. p.data = r1;S7. q.data = q.data + r2;S8. p.data = r1;S9. r3 = p.data + r2;S10. . . .
p
q
m1 m2 m3 mkp next next
q
HeapStack
Superimposition of memory graphs after do-while loop
p and q are definitely not aliases statement S6 onwards.
Statement S8 is redundant.
karkare, CSE, IITK/B CS618 2/27
Why Pointer Analysis?
Static analysis of pointers & references
S1. . . .
S2. q = p;S3. while (. . .) {S4. q = q.next ;S5. }S6. p.data = r1;S7. q.data = q.data + r2;S8. p.data = r1;S9. r3 = p.data + r2;S10. . . .
p
q
m1 m2 m3 mkp next next
q
q
HeapStack
Superimposition of memory graphs after while loop
p and q may be aliases statement S6 onwards.
Statement S8 is not redundant.
karkare, CSE, IITK/B CS618 2/27
Why Pointer Analysis?
x = &a;
a = 5; *x = 15;
c = a + 1;
Reaching definitions analysis
karkare, CSE, IITK/B CS618 3/27
Why Pointer Analysis?
x = &a;
a = 5; *x = 15;
c = a + 1;
Reaching definitions analysis
Which defs
of a reach
here?
karkare, CSE, IITK/B CS618 3/27
Flow Sensitivity in Data Flow Analysis
Flow Sensitive Analysis
Order of execution: Determined by the semantics of
language
karkare, CSE, IITK/B CS618 4/27
Flow Sensitivity in Data Flow Analysis
Flow Sensitive Analysis
Order of execution: Determined by the semantics of
language
Point-specific information computed at each program point
within a procedure
karkare, CSE, IITK/B CS618 4/27
Flow Sensitivity in Data Flow Analysis
Flow Sensitive Analysis
Order of execution: Determined by the semantics of
language
Point-specific information computed at each program point
within a procedureA statement can “override” information computed by aprevious statement
karkare, CSE, IITK/B CS618 4/27
Flow Sensitivity in Data Flow Analysis
Flow Sensitive Analysis
Order of execution: Determined by the semantics of
language
Point-specific information computed at each program point
within a procedureA statement can “override” information computed by aprevious statement
Kill component in the flow function
karkare, CSE, IITK/B CS618 4/27
Flow Sensitivity in Data Flow Analysis
Flow Insensitive Analysis
Order of execution: Statements are assumed to execute in
any order
karkare, CSE, IITK/B CS618 5/27
Flow Sensitivity in Data Flow Analysis
Flow Insensitive Analysis
Order of execution: Statements are assumed to execute in
any orderAs a result, all the program points in a procedure receiveidentical data flow information.
karkare, CSE, IITK/B CS618 5/27
Flow Sensitivity in Data Flow Analysis
Flow Insensitive Analysis
Order of execution: Statements are assumed to execute in
any orderAs a result, all the program points in a procedure receiveidentical data flow information.
“Summary” for the procedure
karkare, CSE, IITK/B CS618 5/27
Flow Sensitivity in Data Flow Analysis
Flow Insensitive Analysis
Order of execution: Statements are assumed to execute in
any orderAs a result, all the program points in a procedure receiveidentical data flow information.
“Summary” for the procedure
Safe approximation of flow-sensitive point-specific
information for any point, for any given execution order
karkare, CSE, IITK/B CS618 5/27
Flow Sensitivity in Data Flow Analysis
Flow Insensitive Analysis
Order of execution: Statements are assumed to execute in
any orderAs a result, all the program points in a procedure receiveidentical data flow information.
“Summary” for the procedure
Safe approximation of flow-sensitive point-specific
information for any point, for any given execution order
A statement can not “override” information computed byanother statement
karkare, CSE, IITK/B CS618 5/27
Flow Sensitivity in Data Flow Analysis
Flow Insensitive Analysis
Order of execution: Statements are assumed to execute in
any orderAs a result, all the program points in a procedure receiveidentical data flow information.
“Summary” for the procedure
Safe approximation of flow-sensitive point-specific
information for any point, for any given execution order
A statement can not “override” information computed byanother statement
NO Kill component in the flow function
karkare, CSE, IITK/B CS618 5/27
Flow Sensitivity in Data Flow Analysis
Flow Insensitive Analysis
Order of execution: Statements are assumed to execute in
any orderAs a result, all the program points in a procedure receiveidentical data flow information.
“Summary” for the procedure
Safe approximation of flow-sensitive point-specific
information for any point, for any given execution order
A statement can not “override” information computed byanother statement
NO Kill component in the flow function
If statement s kills some data flow information, there is an
alternate path that excludes s
karkare, CSE, IITK/B CS618 5/27
Examples of Flow Insensitive Analyses
Type checking, Type inferencing
karkare, CSE, IITK/B CS618 6/27
Examples of Flow Insensitive Analyses
Type checking, Type inferencing
Compute/Verify type of a variable/expression
karkare, CSE, IITK/B CS618 6/27
Examples of Flow Insensitive Analyses
Type checking, Type inferencing
Compute/Verify type of a variable/expression
Address taken analysis
karkare, CSE, IITK/B CS618 6/27
Examples of Flow Insensitive Analyses
Type checking, Type inferencing
Compute/Verify type of a variable/expression
Address taken analysis
Which variables have their addresses taken?
karkare, CSE, IITK/B CS618 6/27
Examples of Flow Insensitive Analyses
Type checking, Type inferencing
Compute/Verify type of a variable/expression
Address taken analysis
Which variables have their addresses taken?
A very simple form of pointer analysis
karkare, CSE, IITK/B CS618 6/27
Examples of Flow Insensitive Analyses
Type checking, Type inferencing
Compute/Verify type of a variable/expression
Address taken analysis
Which variables have their addresses taken?
A very simple form of pointer analysis
Side effects analysis
karkare, CSE, IITK/B CS618 6/27
Examples of Flow Insensitive Analyses
Type checking, Type inferencing
Compute/Verify type of a variable/expression
Address taken analysis
Which variables have their addresses taken?
A very simple form of pointer analysis
Side effects analysis
Does a procedure modify address / global variable /
reference parameter / . . . ?
karkare, CSE, IITK/B CS618 6/27
Realizing Flow Insensitivity
b0
b1
b2 b3
b4
b5
ENTRY
b0 b1 b2 b3 b4 b5
EXIT
karkare, CSE, IITK/B CS618 7/27
Realizing Flow Insensitivity
b0
b1
b2 b3
b4
b5
ENTRY
b0 b1 b2 b3 b4 b5
EXIT
Allows arbitrary compositions of flow functions in any order ⇒Flow insensitivity
karkare, CSE, IITK/B CS618 7/27
Realizing Flow Insensitivity
b0
b1
b2 b3
b4
b5
ENTRY
b0 b1 b2 b3 b4 b5
EXIT
In practice, dependent constraints are collected in a global
repository in one pass and solved independently
karkare, CSE, IITK/B CS618 7/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
Reflexive?
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
Reflexive? No Yes
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
Reflexive? No Yes
Symmetric?
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
Reflexive? No Yes
Symmetric? No Yes
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
Reflexive? No Yes
Symmetric? No Yes
Transitive?
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
Reflexive? No Yes
Symmetric? No Yes
Transitive? No
karkare, CSE, IITK/B CS618 8/27
Alias Analysis vs. Points-to Analysis
Points-to Analysis Alias Analysis
x = &a x = a
x points-to a x and a are aliases
x → a x ≡ a
Reflexive? No Yes
Symmetric? No Yes
Transitive? No Must alias: Yes,
May alias: No
karkare, CSE, IITK/B CS618 8/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
karkare, CSE, IITK/B CS618 9/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Plhs ⊇ Prhs
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
karkare, CSE, IITK/B CS618 9/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Plhs ⊇ Prhs
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}a b
karkare, CSE, IITK/B CS618 9/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Plhs ⊇ Prhs
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 Pc ⊇ Pa
a
c
b
karkare, CSE, IITK/B CS618 9/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Plhs ⊇ Prhs
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 Pc ⊇ Pa
3 Pa ⊇ {d}
a
c
b
d
karkare, CSE, IITK/B CS618 9/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Plhs ⊇ Prhs
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 Pc ⊇ Pa
3 Pa ⊇ {d}4 Pa ⊇ {e}
a
c
b
d
e
karkare, CSE, IITK/B CS618 9/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Plhs ⊇ Prhs
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 Pc ⊇ Pa
3 Pa ⊇ {d}4 Pa ⊇ {e}5 Pb ⊇ Pa
a
c
b
d
eb
karkare, CSE, IITK/B CS618 9/27
Andersen’s Flow Insensitive Points-to Analysis
Subset based analysis
Plhs ⊇ Prhs
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 Pc ⊇ Pa
3 Pa ⊇ {d}4 Pa ⊇ {e}5 Pb ⊇ Pa
a
c
b
d
e
karkare, CSE, IITK/B CS618 9/27
Steensgaard’s Flow Insensitive Points-to Analysis
Equality based analysis: Plhs ≡ Prhs
Only one Points-to successor at any time, merge
(potential) multiple successors
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
karkare, CSE, IITK/B CS618 10/27
Steensgaard’s Flow Insensitive Points-to Analysis
Equality based analysis: Plhs ≡ Prhs
Only one Points-to successor at any time, merge
(potential) multiple successors
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}
a b
karkare, CSE, IITK/B CS618 10/27
Steensgaard’s Flow Insensitive Points-to Analysis
Equality based analysis: Plhs ≡ Prhs
Only one Points-to successor at any time, merge
(potential) multiple successors
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 MERGE(Pc ,Pa)
a
c
b
karkare, CSE, IITK/B CS618 10/27
Steensgaard’s Flow Insensitive Points-to Analysis
Equality based analysis: Plhs ≡ Prhs
Only one Points-to successor at any time, merge
(potential) multiple successors
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 MERGE(Pc ,Pa)
3 Pa ⊇ {d}
a
c
b
d
karkare, CSE, IITK/B CS618 10/27
Steensgaard’s Flow Insensitive Points-to Analysis
Equality based analysis: Plhs ≡ Prhs
Only one Points-to successor at any time, merge
(potential) multiple successors
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 MERGE(Pc ,Pa)
3 Pa ⊇ {d}4 Pa ⊇ {e}
a
c
b
d
e
karkare, CSE, IITK/B CS618 10/27
Steensgaard’s Flow Insensitive Points-to Analysis
Equality based analysis: Plhs ≡ Prhs
Only one Points-to successor at any time, merge
(potential) multiple successors
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 MERGE(Pc ,Pa)
3 Pa ⊇ {d}4 Pa ⊇ {e}5 MERGE(Pb,Pa)
a
c
b
d
e
karkare, CSE, IITK/B CS618 10/27
Steensgaard’s Flow Insensitive Points-to Analysis
Equality based analysis: Plhs ≡ Prhs
Only one Points-to successor at any time, merge
(potential) multiple successors
Program Constraints Points-to Graph
1 a = &b
2 c = a
3 a = &d 4 a = &e
5 b = a
# Constraint
1 Pa ⊇ {b}2 MERGE(Pc ,Pa)
3 Pa ⊇ {d}4 Pa ⊇ {e}5 MERGE(Pb,Pa)
a
c
b
d
e
karkare, CSE, IITK/B CS618 10/27
Comparing Anderson’s and Steensgaard’s Analyses
Program Subset based Equality based
Points-to Graph Points-to Graph
a = &b
c = a
a = &d a = &e
b = a
a
c
b
d
e
a
c
b
d
e
karkare, CSE, IITK/B CS618 11/27
Comparing Anderson’s and Steensgaard’s Analyses
a = &b;
a b
b = &c;
karkare, CSE, IITK/B CS618 12/27
Comparing Anderson’s and Steensgaard’s Analyses
a = &b;
a b
b = &c;
a b c
karkare, CSE, IITK/B CS618 12/27
Comparing Anderson’s and Steensgaard’s Analyses
a = &b;
a b
b = &c;
a b c
d = &e;
karkare, CSE, IITK/B CS618 12/27
Comparing Anderson’s and Steensgaard’s Analyses
a = &b;
a b
b = &c;
a b c
d = &e;
a b c
d e
karkare, CSE, IITK/B CS618 12/27
Comparing Anderson’s and Steensgaard’s Analyses
a = &b;
a b
b = &c;
a b c
d = &e;
a b c
d e
a = &d;
karkare, CSE, IITK/B CS618 12/27
Comparing Anderson’s and Steensgaard’s Analyses
a = &b;
a b
b = &c;
a b c
d = &e;
a b c
d e
a = &d;
Subset based Equality based
a
b c
d e
a b,c d,e
karkare, CSE, IITK/B CS618 12/27
Pointer Indirection Constraints
Stmt Subset based Equality based
a = *b Pa ⊇ Pc , ∀c ∈ Pb MERGE(Pa,Pc), ∀c ∈ Pb
*a = b Pc ⊇ Pb, ∀c ∈ Pa MERGE(Pb,Pc), ∀c ∈ Pa
karkare, CSE, IITK/B CS618 13/27
Must Points-to Analysis
1 x = &a;
2 3
4
x definitely points-to a at various points in the program
xD→ a
karkare, CSE, IITK/B CS618 14/27
May Points-to Analysis
1 x = &a;
2 x = &b; 3
4
At OUT of 2, x definitely points-to b
At OUT of 3, x definitely points-to a
At IN of 4, x possibly points-to a (or b)
xP→ a, x
P→ b
karkare, CSE, IITK/B CS618 15/27
May Points-to Analysis
1 x = &a;
2 x = &b; 3
4
At OUT of 2, x definitely points-to b
At OUT of 3, x definitely points-to a
At IN of 4, x possibly points-to a (or b)
xP→ {a,b}
karkare, CSE, IITK/B CS618 15/27
Must Alias Analysis
1 x = a;
2 3
4 y = a;
x and a always refer to same memory location
xD
≡ a
karkare, CSE, IITK/B CS618 16/27
Must Alias Analysis
1 x = a;
2 3
4 y = a;
x and a always refer to same memory location
xD
≡ a
x , y and a refer to same location at OUT of 4.
xD
≡ yD
≡ a
karkare, CSE, IITK/B CS618 16/27
May Alias Analysis
1 x = a;
2 x = b; 3
4
At OUT of 2, x and b are must aliases
At OUT of 3, x and a are must aliasesAt IN of 4, x can possibly be aliased with either a (or b)
xP
≡ a, xP
≡ b
karkare, CSE, IITK/B CS618 17/27
May Alias Analysis
1 x = a;
2 x = b; 3
4
At OUT of 2, x and b are must aliases
At OUT of 3, x and a are must aliasesAt IN of 4, x can possibly be aliased with either a (or b)
(x ,a), (x ,b)
karkare, CSE, IITK/B CS618 17/27
May Alias Analysis
1 x = a;
2 x = b; 3
4
At OUT of 2, x and b are must aliases
At OUT of 3, x and a are must aliasesAt IN of 4, x can possibly be aliased with either a (or b)
(x ,a), (x ,b)
If we say: (x , a, b), Is it Precise?
karkare, CSE, IITK/B CS618 17/27
May Alias Analysis
1 x = a;
2 x = b; 3
4
At OUT of 2, x and b are must aliases
At OUT of 3, x and a are must aliasesAt IN of 4, x can possibly be aliased with either a (or b)
(x ,a), (x ,b)
If we say: (x , a, b), Is it Precise? Safe?
karkare, CSE, IITK/B CS618 17/27
Must Pointer Analysis
Makes sense only for Flow Sensitive analysis
Why?
karkare, CSE, IITK/B CS618 18/27
Must Pointer Analysis
Makes sense only for Flow Sensitive analysis
Why?
Must analysis ⇒ Flow sensitive analysis
karkare, CSE, IITK/B CS618 18/27
Must Pointer Analysis
Makes sense only for Flow Sensitive analysis
Why?
Must analysis ⇒ Flow sensitive analysis
Flow insensitive analysis ⇒ May analysis
karkare, CSE, IITK/B CS618 18/27
Must Pointer Analysis
Makes sense only for Flow Sensitive analysis
Why?
Must analysis ⇒ Flow sensitive analysis
Flow insensitive analysis ⇒ May analysis
Why?
karkare, CSE, IITK/B CS618 18/27
Updating Information: When Can We Kill?
Never if flow insensitive analysis
karkare, CSE, IITK/B CS618 19/27
Updating Information: When Can We Kill?
Never if flow insensitive analysis
For flow sensitive
1 x = &a;
2y = &b;
w = &c;
3 z = &x ; 4 z = &y ;
5∗z = NULL;
∗w = NULL;
karkare, CSE, IITK/B CS618 19/27
Updating Information: When Can We Kill?
Never if flow insensitive analysis
For flow sensitive
1 x = &a;
2y = &b;
w = &c;
3 z = &x ; 4 z = &y ;
5∗z = NULL;
∗w = NULL;
x , y may or may not get modified in 5: Weak update
karkare, CSE, IITK/B CS618 19/27
Updating Information: When Can We Kill?
Never if flow insensitive analysis
For flow sensitive
1 x = &a;
2y = &b;
w = &c;
3 z = &x ; 4 z = &y ;
5∗z = NULL;
∗w = NULL;
x , y may or may not get modified in 5: Weak update
c definitely gets modified in 5: Strong update
karkare, CSE, IITK/B CS618 19/27
Updating Information: When Can We Kill?
Never if flow insensitive analysis
For flow sensitive
1 x = &a;
2y = &b;
w = &c;
3 z = &x ; 4 z = &y ;
5∗z = NULL;
∗w = NULL;
x , y may or may not get modified in 5: Weak update
c definitely gets modified in 5: Strong update
Must information is killed by Strong and Weak updates
karkare, CSE, IITK/B CS618 19/27
Updating Information: When Can We Kill?
Never if flow insensitive analysis
For flow sensitive
1 x = &a;
2y = &b;
w = &c;
3 z = &x ; 4 z = &y ;
5∗z = NULL;
∗w = NULL;
x , y may or may not get modified in 5: Weak update
c definitely gets modified in 5: Strong update
Must information is killed by Strong and Weak updates
May information is killed only by Strong updates
karkare, CSE, IITK/B CS618 19/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
x = *y
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
x = *y
*x = y
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
x = *y
*x = y
Other statements can be rewritten in terms of above
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
x = *y
*x = y
Other statements can be rewritten in terms of above
*x = *y ⇒ t = *y, *x = t
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
x = *y
*x = y
Other statements can be rewritten in terms of above
*x = *y ⇒ t = *y, *x = t
x = NULL ⇒ treat NULL as a special variable
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
x = *y
*x = y
Other statements can be rewritten in terms of above
*x = *y ⇒ t = *y, *x = t
x = NULL ⇒ treat NULL as a special variable
OUT = IN − kill ∪ gen
karkare, CSE, IITK/B CS618 20/27
Flow Functions for Points-to Analysis
Basic statements for pointer manipulation
x = y
x = &y
x = *y
*x = y
Other statements can be rewritten in terms of above
*x = *y ⇒ t = *y, *x = t
x = NULL ⇒ treat NULL as a special variable
OUT = IN − kill ∪ gen
with a twist!
karkare, CSE, IITK/B CS618 20/27
Flow Function: x = y
Maygen = {x → p | y → p ∈ MayIN}
Maykill =⋃
p∈Vars
{x → p}
karkare, CSE, IITK/B CS618 21/27
Flow Function: x = y
Maygen = {x → p | y → p ∈ MayIN}
Maykill =⋃
p∈Vars
{x → p}
Mustgen = {x → p | y → p ∈ MustIN}
Mustkill =⋃
p∈Vars
{x → p}
karkare, CSE, IITK/B CS618 21/27
Flow Function: x = &y
Maygen = {x → y}
Maykill =⋃
p∈Vars
{x → p}
Mustgen = {x → y}
Mustkill =⋃
p∈Vars
{x → p}
karkare, CSE, IITK/B CS618 22/27
Flow Function: x = *y
Maygen = {x → p | y → p′ ∈ MayIN and p′ → p ∈ MayIN}
Maykill =⋃
p∈Vars
{x → p}
karkare, CSE, IITK/B CS618 23/27
Flow Function: x = *y
Maygen = {x → p | y → p′ ∈ MayIN and p′ → p ∈ MayIN}
Maykill =⋃
p∈Vars
{x → p}
Maygen = {x → p | y → p′ ∈ MustIN and p′ → p ∈ tin}
Maykill =⋃
p∈Vars
{x → p}
karkare, CSE, IITK/B CS618 23/27
Flow Function: *x = y
Maygen = {p → p′ | x → p ∈ MayIN , y → p′ ∈ MayIN}
Maykill =⋃
p′∈Vars
{p → p′ | x → p ∈ MustIN}
karkare, CSE, IITK/B CS618 24/27
Flow Function: *x = y
Maygen = {p → p′ | x → p ∈ MayIN , y → p′ ∈ MayIN}
Maykill =⋃
p′∈Vars
{p → p′ | x → p ∈ MustIN}
Mustgen = {p → p′ | x → p ∈ MustIN , y → p′ ∈ MustIN}
Mustkill =⋃
p′∈Vars
{p → p′ | x → p ∈ MayIN}
karkare, CSE, IITK/B CS618 24/27
Flow Function: *x = y
Maygen = {p → p′ | x → p ∈ MayIN , y → p′ ∈ MayIN}
Maykill =⋃
p′∈Vars
{p → p′ | x → p ∈ MustIN} Strong update!!
Mustgen = {p → p′ | x → p ∈ MustIN , y → p′ ∈ MustIN}
Mustkill =⋃
p′∈Vars
{p → p′ | x → p ∈ MayIN} Weak update!!
karkare, CSE, IITK/B CS618 24/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
karkare, CSE, IITK/B CS618 25/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
⇒ should remove only strong updates
karkare, CSE, IITK/B CS618 25/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
⇒ should remove only strong updates
⇒ should kill using Must Points-To information
karkare, CSE, IITK/B CS618 25/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
⇒ should remove only strong updates
⇒ should kill using Must Points-To information
Must Points-To analysis
karkare, CSE, IITK/B CS618 25/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
⇒ should remove only strong updates
⇒ should kill using Must Points-To information
Must Points-To analysis
A points-to pair should be removed if it can be removed
along some path
karkare, CSE, IITK/B CS618 25/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
⇒ should remove only strong updates
⇒ should kill using Must Points-To information
Must Points-To analysis
A points-to pair should be removed if it can be removed
along some path
⇒ should remove all weak updates
karkare, CSE, IITK/B CS618 25/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
⇒ should remove only strong updates
⇒ should kill using Must Points-To information
Must Points-To analysis
A points-to pair should be removed if it can be removed
along some path
⇒ should remove all weak updates
⇒ should kill using May Points-To information
karkare, CSE, IITK/B CS618 25/27
Summarizing Flow Functions
May Points-To analysis
A points-to pair should be removed only if it must be
removed along all paths
⇒ should remove only strong updates
⇒ should kill using Must Points-To information
Must Points-To analysis
A points-to pair should be removed if it can be removed
along some path
⇒ should remove all weak updates
⇒ should kill using May Points-To information
Must Points-To ⊆ May Points-To
karkare, CSE, IITK/B CS618 25/27
Safe Approximations for May and Must Points-to
A pointer variable
May Must
Points-to points to every possible
location
points to nothing
Alias aliased to every other
pointer variable
only to itself
karkare, CSE, IITK/B CS618 26/27
Non-Distributivity of Points-to Analysis
May Information Must Information
1
2 x = &z 3 y = &w
4 ∗x = y
1 x = a;
2b = &c
c = &d3
b = &e
e = &d
4 a = ∗b
karkare, CSE, IITK/B CS618 27/27
Non-Distributivity of Points-to Analysis
May Information Must Information
1
2 x = &z 3 y = &w
4 ∗x = y
1 x = a;
2b = &c
c = &d3
b = &e
e = &d
4 a = ∗b
z → w is spurious
karkare, CSE, IITK/B CS618 27/27