a = &x;
b = &y;
c = b;
a = *b;
a : {x, y}
b : {y}
c : {y}
x = y | copy statement |
x = &y | address-of statement |
x = *y | load statement |
x = op(y1 y2 ... yn) | scalar operator |
x = allocate(y) | dynamic memory allocation |
*x = y | store statement |
x = fun(f1 . . . fn) | function call statement |
x1 x2 ... xm = p(y1 . . . yn) | bitwise construction of pointer |
flow-insensitive analysis : Control structures are irrelevant
x = y
x
a
b
y
p
q
x = &y
x
a
b
y
p
q
x = *y
x
a
b
y
p
q
r
s
*x = y
x
a
b
y
p
q
x = y
points-to(x) \( \supseteq \) points-to(y)
where x can be of the form: x, *x
y can be of the form: y, *y, &y
p1 = &a
p2 = &b
p1 = p2
r = &p1
p3 = *r
p2 = &d
a\(\in\)points-to(p1)
b\(\in\)points-to(p2)
p1\(\supseteq\)points-to(p2)
p1\(\in\) points-to(r)
points-to(p3) \(\supseteq\) points-to(*r)
d\(\in\) points-to(p2)
r
p1
p2
a
b
d
p3
r |
p1 |
p2 |
p3 |
{} |
{} |
{} |
{} |
{p1} |
{a, b} |
{b, d} |
{a, b} |
{p1} |
{a, b, d} |
{b, d} |
{a, b, d} |
x = y
points-to(x) \( \supseteq \) points-to(y)
points-to(y) \( \supseteq \) points-to(x)
where x can be of the form: x, *x
y can be of the form: y, *y, &y
For the statement x=y, merge the points-to sets of x and y.
p1 = &a
p2 = &b
p1 = p2
r = &p1
p3 = *r
p2 = &d
r
p1
p2
a
b
d
p3
p1 = &a
p2 = &b
p1 = p2
r = &p1
p3 = *r
p2 = &d
r
p1
p2
a,b
d
p3
p1 = &a
p2 = &b
p1 = p2
r = &p1
p3 = *r
p2 = &d
r
p1
p2
a,b,d
p3
a = &x;
b = &y;
c = b;
a
b
c
x
y
\( \bot \)
\( \bot \)
\( \bot \)
\( \bot \)
\( \bot \)
a
b
c
x
y
Variables
Memory Locations
Types
a = &x;
b = &y;
c = b;
a
b
c
x
y
\( \bot \)
\( \bot \)
\( \bot \)
a
b
c
x
y
Variables
Memory Locations
Types
\( \bot \)
Naive approach
Less constrained approach
a
x
y
\( \bot \)
a
x
y
a
x
y
\( \bot \)
a
x
y
\( \bot \)
\( \bot \)
a = 4
x = a
y = x
m
\( \bot \)
\( \bot \)
\( \bot \)
p1 = &a
p2 = &b
p1 = p2
r = &p1
p3 = *r
p2 = &d
r
p1
p2
a,b,d
p3
r
p1
p2
a
b
d
p3
r
p1
p2
a,b
d
p3
To satisfy \(t1 \trianglelefteq t2\)
r
p1
p2
a
b
d
p3
r
p1
p2
a,b,d
p3
Time | O(n^3) | O(n) |
---|---|---|
Outgoing edges | O(n^2) | O(1) |
Precision | High | Low |
Even with a very conservative analysis, a lot of types point to only one variable.
Every problem in Computer Science can be solved by using another level of indirection.
- David Wheeler