• Nie Znaleziono Wyników

Computer aided verification

N/A
N/A
Protected

Academic year: 2022

Share "Computer aided verification"

Copied!
86
0
0

Pełen tekst

(1)

Computer aided verification

lecture 9

Abstract interpretation

Sławomir Lasota

University of Warsaw

(2)

Literature

F. Nielson, H.R. Nielson, C. Hankin, Principles of Program Analysis, Springer, 2005.

http://www.imm.dtu.dk/~riis/PPA/slides2.pdf

V. D'Silva, D. Kroening, G. Weissenbacher, A Survey of Automated Techniques for Formal Software Verification.

IEEE Trans. on CAD of Integrated Circuits and Systems 27(7):1165-1178, 2008.

(3)

Pionieers

P. Naur 1965

P. Cousot, R. Cousot 1977

(4)

Approximate analysis

surely ✔ perhaps ✘

(5)

123 · 457 + 76543 = 132654?

(6)

123 · 457 + 76543 = 132654?

6 · 7 + 7 =? 3 (mod 9) 6 + 7 =? 3 (mod 9)

(7)
(8)

the least information

the greatest information

(9)

Approximate analysis

static analysis

source code is analyzed (control-flow diagram)

false alarms (false positives)

typically oriented towards specific properties

fully automatic

scalable

a diagnostic information if error

(10)

Approximate analysis - methods

data-flow analysis

control-flow analysis

type analysis

WCET analysis

...

abstract interpretation

(11)

Approximate analysis - applications

code optimization, program transformations

program verification (static analysis)

estimation of quality of code

abstract interpretation - systematization

(12)

Code optimization

constants propagation (at compile time)

copies propagation

available expressions analysis (elimination of comp.)

live variables analysis (elimination of dead code)

definition-use and use-definition analysis

strictness analysis

array bounds analysis

...

(13)

Program verification

division by 0, exceptions

pointers

NULL dereferences

static and dynamic data (stack and heap)

shape analysis

aliasing analysis

array bounds

detection of invariants

...

(14)

Data-flow analyses

(15)

Data-flow analysis

(while-programs)

(16)

finite set of control locations

State = S ⇥ Store Store = Var ! Val

S = {1, . . . , n}, ✓ S ⇥ S init(S) ✓ S

(17)

Data-flow analyses

reaching definitions analysis

available expressions analysis

live variables analysis

very busy expressions analysis

constants propagation

...

(18)

Reaching definitions analysis

In each control location compute the set of

assignments that possibly have been executed (and not „overwritten”) prior to reaching this location.

(19)

Reaching definitions analysis

(20)

Reaching definitions analysis

kill(i) gen(i)

formalize the problem as a set of equations

variables represent

information before and after each instruction

the lest solution

iterative algorithm

(21)

Reaching definitions analysis

xexiti = xentryi \ kill(i) [ gen(i) xentryi = [

j i

xexitj

xentry1 = {(x, ?), (y, ?), (z, ?)}

we are interested in the least solution

(22)

Reaching definitions analysis

xexiti = xentryi \ kill(i) [ gen(i) xentryi = [

j i

xexitj

xentry1 = {(x, ?), (y, ?), (z, ?)}

we are interested in the least solution

kill(b) = ; kill(skip) = ;

gen(skip) = ; gen(b) = ;

kill(z := e) = {(z, ?)} [ {(z, j) | j 2 S}

gen([z := e]i) = {(z, i)}

(23)

Reaching definitions analysis

(24)

Reaching definitions analysis

we are interested in the least solution

solutions: xentryl0 ◆ {(x, ?), (y, ?), (z, l)}

(25)

Available expressions analysis

In each control location compute the set of expressions whose value is surely computed

whenever this location is entered.

(26)

xexiti = xentryi \ kill(i) [ gen(i) xentryi = \

j i

xexitj xentry1 = ;

we are interested in the greatest solution

Available expressions analysis

(27)

we are interested in the greatest solution i xentryi xexiti xexiti = xentryi \ kill(i) [ gen(i)

xentryi = \

j i

xexitj xentry1 = ;

Available expressions analysis

(28)

we are interested in the greatest solution two solutions:

xexiti = xentryi \ kill(i) [ gen(i) xentryi = \

j i

xexitj xentry1 = ; xentryl0 = {x + y}, ;

Available expressions analysis

(29)

Live variables analysis

In each program location compute the set of variables that are live (possibly used in future before being

redefined) when exiting this location.

backwards analysis

(30)

Live variables analysis

xexiti = [

i j

xentryj

xentryi = xexiti \ kill(i) [ gen(i)

xexit6 = ;

we are interested in the least solution

(31)

Very busy expressions analysis

In each control location compute the set of expressions that will surely be computed in future before redefinition

of any of variables appearing in the expression.

backwards analysis

(32)

Very busy expressions analysis

xentryi = xexiti \ kill(i) [ gen(i) xentryi = \

i j

xentryj

xexit6 = ;

we are interested in the greatest solution

(33)

Very busy expressions analysis

xentryi = xexiti \ kill(i) [ gen(i) xentryi = \

i j

xentryj

xexit6 = ;

we are interested in the greatest solution two solutions:

xexitl = {x + 1}, ;

(34)

Abstract interpretation

(35)

Generalization

- abstract space

- complete lattice

L

(L, v)

t, u - bounds

S = {1, . . . , n}, ✓ S ⇥ S init(S) ✓ S

f : S ! Mon(L ! L)

xexiti = f (x)(xentryi ) xentryi = G

j i

xexitj t finit(x) finit : init(S) ! L

(36)

Generalization

- abstract space

- complete lattice

L

(L, v)

t, u - bounds

S = {1, . . . , n}, ✓ S ⇥ S init(S) ✓ S

f : S ! Mon(L ! L)

xexiti = f (x)(xentryi ) xentryi = G

j i

xexitj t finit(x) finit : init(S) ! L

abstract

interpretation

(37)

Data-flow analyses

reaching definitions analysis

available expressions analysis

live variables analysis

very busy expressions analysis

constants propagation

...

(38)

Data-flow analyses

reaching definitions analysis

available expressions analysis

live variables analysis

very busy expressions analysis

constants propagation

...

P(Var ⇥ (S [ {?}))

(39)

Data-flow analyses

reaching definitions analysis

available expressions analysis

live variables analysis

very busy expressions analysis

constants propagation

...

P(Expr) P(Var ⇥ (S [ {?}))

(40)

Data-flow analyses

reaching definitions analysis

available expressions analysis

live variables analysis

very busy expressions analysis

constants propagation

...

P(Expr) P(Var) P(Var ⇥ (S [ {?}))

(41)

Data-flow analyses

reaching definitions analysis

available expressions analysis

live variables analysis

very busy expressions analysis

constants propagation

...

P(Expr)

P(Expr) P(Var) P(Var ⇥ (S [ {?}))

(42)

Data-flow analyses

reaching definitions analysis

available expressions analysis

live variables analysis

very busy expressions analysis

constants propagation

...

P(Expr)

P(Expr) P(Var) P(Var ⇥ (S [ {?}))

Var ! Z>

(43)

Distributivity

f (s)(l1 t l2) = f (s)(l1) t f(s)(l2)

f (s)(l) = l \ l1 [ l2

holds whenever:

may not hold

L = P(D) D f inite

(44)

Constants propagation

In each control location compute the set of variables that have a constant value independent from the history.

(45)

L = Var ! Z>

f (6)(l1 t l2)(z) = >

f (6)(l1)(z) = f (6)(l2)(z) = 25 l1(y) = 5 l2(y) = 5

Constants propagation

(46)

Algorithm

the lest fix-point of the monotonic function

LS⇥{entry,exit} with the coordinate-wise order complete lattice

xexiti = f (x)(xentryi ) xentryi = G

j i

xexitj t finit(x)

~x = ~f (~x)

f~ iterative algorithm

we assume that L has only finite chains

(47)

LFP

- abstract space

- complete lattice

L

(L, v)

t, u - bounds

S = {1, . . . , n}, ✓ S ⇥ S init(S) ✓ S

f : S ! Mon(L ! L)

xexiti = f (x)(xentryi ) xentryi = G

j i

xexitj t finit(x) finit : init(S) ! L

(48)

MOP

- abstract space

- complete lattice

L

(L, v)

t, u - bounds

S = {1, . . . , n}, ✓ S ⇥ S init(S) ✓ S

f : S ! Mon(L ! L)

finit : init(S) ! L

yientry = G

{f(p) | p 2 pathsentry(i)} yiexit = G

{f(p) | p 2 pathsexit(i)}

(49)

MOP LFP v

~y v ~x

(50)

MOP LFP v

~y v ~x

not always computable

(51)

MOP = LFP

~y = ~x

when distributivity holds

(52)

Abstract domains

(53)

Non-relational domains

signs

intervals

parity

congruence modulo k

[n, m]

P( , 0, +)

(54)
(55)
(56)

Expressive power

signs

intervals

DBM (difference bounds matrices)

octagon

octahedra

polyhedra a1x1 + . . . + anxn  c

+ x + y  c x y  c

+ x1 . . . + xn  c

precision

(57)

Pointer analyses domains

points-to graphs

(58)

Example: alias analysis

a and b do not point to the same location x and y may point to the same location

(59)

Abstract semantics

(60)

S = {A, B, C, D, E, F, G}

State = S ⇥ Store Store = Var ! Val

(61)

concrete semantics

abstract semantics

(62)

concrete semantics

abstract semantics

V = Store = Var ! Z

L = Var ! {?, even, odd, >}

Domains

(63)

Abstract semantics

? 7! ? odd, even, > 7! >

? 7! ?

odd 7! even even 7! odd

> 7! >

(64)

concrete semantics

abstract semantics

V = Store = Var ! Z

L = Var ! {?, even, odd, >}

do these two semantics agree?

(65)

Representation function

concrete semantics

abstract semantics

V = Store = Var ! Z

L = Var ! {?, even, odd, >}

: V ! L

monotonic (v) =

(even if v even odd if v odd

(66)

Representation function

concrete semantics

abstract semantics

V = Store = Var ! Z

L = Var ! {?, even, odd, >}

the best approximation

: V ! L

monotonic (v) =

(even if v even odd if v odd

(67)

7 22

β β

odd even

(68)

β is not always a homomorphism!

7 22

β β

odd even

(69)

β is not always a homomorphism!

β β

[n 7! 1, m 7! 2] m := n + m

m := n + m

[n 7! 1, m 7! 1]

[n 7! +, m 7! ] [n 7! +, m 7! >]

[n 7! +, m 7! ]v

(70)

standard semantics

abstract semantics

(71)

standard semantics

abstract semantics cumulative

semantics

(72)

{1} {5}

{5, 16, 8, 4, 2} {16, 8, 4, 2}

{5}

{8, 4, 2, 1}

{16}

(73)

Abstraction function

concrete semantics

abstract

semantics L = Var ! {?, even, odd, >}

abstraction

P(V )

↵ : P(V ) ! L ↵(X) = t{ (v) | v 2 X}

(74)

{1} {5}

{5, 16, 8, 4, 2} {16, 8, 4, 2}

{5}

{8, 4, 2, 1}

{16}

(75)

odd

odd

even

even odd

>

>

(76)

Abstraction function (example)

α maps a set of concrete values to the most exact abstract value

(77)

Concretization function (example)

γ maps an abstract value to the set of represented concrete values

(78)

x ⊆ γ⋅α(x)

(79)

α⋅γ(a) ≤ a

(80)

α⋅γ(a) ≤ a

>0.5

(81)

Galois connection

(82)

P(V ) L

the most exact abstraction

set of represented values

Concrete and abstract domain

(83)

Example

P(Z)

↵(X) = the smallest interval containing X

(I) = I

Intervals

(84)

M is more abstract (less exact) than L

Two abstract domains

(85)

Example

Intervals

(86)

Example

Intervals

Cytaty

Powiązane dokumenty

Which famous sportsperson appears in “The Hangover”?. What is the name of the hospital where Dr Gregory

boolean hasMonetaryCost() boolean requiresCell() boolean requiresNetwork() boolean requiresSatellite() boolean supportsAltitude() boolean supportsBearing() boolean supportsSpeed().

SuperK-Gd pre-SN warning system ( from M. Vagins talk at Sendai conference 6-9 March 2019 ) Hyper-Kamiokande project starting construction next year, operating 2027 other low

We study a projection method with level control for nonsmoooth convex minimization problems.. We introduce a changeable level pa- rameter to

(For the case q = 1, this proof was also given in [11].) In fact, it shows that certain cases of Theorem (3.1) are equivalent to Doob’s results.. We end the section by deriving the

In Section 3 we for- mulate and prove a theorem on the existence and uniqueness for the linear problem which is the same as Theorem 1 of [3] but the proof is slightly

We show that a generalized upper and lower solution method is still valid, and develop a monotone iterative technique for finding minimal and maximal solutions.. In our situation,

(b) If fees continue to rise at the same rate, calculate (to the nearest dollar) the total cost of tuition fees for the first six years of high school.. The population of Bangor