lecture10
lecture10
Kihong Heo
1
Advanced Analysis Techniques
• From now on, we will cover several advanced techniques to achieve e cient
and accurate analysis
ffi
Iteration Strategies
• Compute weaker and weaker abstract states until stabilization (via join and widening)
F ] : (L ! M] ) ! (L ! M] )
Worklist : }(L)
begin
Worklist L
X ?
repeat
(w, Worklist) pop(Worklist)
m]old X(w) Widening Everywhere?
G ]
m]new {min | hl, X(l)i ,!] hw, m]in i}
m]new m]old O m]new
if m]new 6v m]old then
X(w) m]new
Worklist Worklist [ {l | hw, m]new i ,!] hl, i}
endif
until Worklist = ;
return X
end
2
1 x = 1
x = 0
x [1,1]
3
x [0,0]
t ❓
5 x [0,1] = x [0,+∞] 😟
• Apply widening only when the label is the target of a cycling control ow
fl
Case 1: Loop Heads
// i = [0,0]
// x = [0,1]
if (x == 1)
x = x - 1 x = x + 1
… …
i++
g++
5
void f() {
g++; f();
f();
…
return; …
} 5
return;
g++
int main() {
g++; f(); entry
f(); // non-recursive
f();
return; f(); exit
}
5
return;
• Possible solutions:
• The abstract value for x with a naive approach would be [-∞, +∞]
x = ?; // any value
i = 1;
}
x = ?; // any value if(x < 0 || x > 1000) {
i = 1; x = 0;
} else { rst iter.
while (i > 0) {
if(x < 0 || x > 1000) { x = x + 1;
x = 0; }
} else { input(i);
// x is in [0, 1001]
}
x = x + 1;
} while (i > 0) {
input(i); if(x < 0 || x > 1000) {
} x = 0;
// actually, x is in [0, 1001] } else { rest
x = x + 1;
}
input(i);
}
// x is in [0, 1001]
x = 0;
while (*) {
if(*) {
x = -1;
} else { x [0,0] 5 x [-1,1] = x [-∞,+∞]
x = x + 1;
}
}
// x >= -1
// x >= -1
Fixed Point!
x = 0;
// actually, x is in [0, 50]
while (x <= 100) {
if(x >= 50) { x [0,0] 5 x [0,1] = x [0,+∞]
x = 10;
} else {
x = x + 1;
}
}
• Take several small steps and stops at pre-de ned threshold values
( 8
>
<[n, p] if p q
[n, p] if p q
[n, p] O [n, q] = [n, p] O [n, q] = [n, B] if p < q B
[n, +1] if p < q >
:
[n, +1] if B < q
Thresholds = {50}
x = 0;
while (x <= 100) { 5
x [0,0] x [0,1] = x [0,50]
if(x >= 50) {
x = 10;
} else { x [0,50] 5 x [0,50] = x [0,50]
x = x + 1;
}
}
Fixed Point!
• no universal solutions