• Keine Ergebnisse gefunden

Statische Analyse durch abstrakte Interpretation

N/A
N/A
Protected

Academic year: 2021

Aktie "Statische Analyse durch abstrakte Interpretation"

Copied!
21
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Statische Analyse

durch abstrakte Interpretation

Jan Peleska Helge L¨ oding

hloeding@informatik.uni-bremen.de

Universit¨ at Bremen — Technologiezentrum Informatik TZI

Tutorium

28. November 2007

(2)

Uberblick ¨

Programm

Semantik

Abstraktion

Berechnung

(3)

Programm

sample1.c

f l o a t x , y ; i f( x< y ){

x = s q r t ( y−x ) ; }

e l s e{ x = 0 ; } r e t u r n x ;

(4)

Konkrete Semantik

Locations: Loc = Lang (G ) Variablen: X

Valuationen:

D x = float D y = float D = S

v∈X D v = float

Σ = X 6→ D

(5)

Konkrete Semantik

Erweiterte Valuationsfunktionen:

σ ∈ exp 6→ D σ (v ) = def σ(v)

σ (exp 1 − exp 2 ) = def σ (exp 1 ) − σ (exp 2 ) σ (sqrt (exp)) = def sqrt (σ (exp))

σ + ∈ bexp 6→ B

σ + (v 1 < v 2 ) = def σ(v 1 ) < σ(v 2 )

(6)

Konkrete Semantik

Zustandsraum: S = Loc × Σ

Startzust¨ ande: S 0 = {(c , σ) ∈ S | c = P ∧ dom σ = {x, y}}

Transitionsrelation −→:

(v = exp; P , σ) −→ (P , σ[v 7→ σ (exp)]) σ + (bexp) = true

(if (bexp){P 1 }else{P 2 }; P 3 , σ) −→ (P 1 ; P 3 , σ) σ + (bexp) = false

(if (bexp){P 1 }else{P 2 }; P 3 , σ) −→ (P 2 ; P 3 , σ)

Transitionssystem: TS = (S, S 0 , −→)

(7)

Potenzmengentransitionssystem

Zustandsraum: S P = P(S ) Startzustandsmenge: S 0

P

= {S 0 } Transitionsrelation −→ P :

∀i ∈ I , s i , s i 0 ∈ S : s i −→ s i 0 {s i |i ∈ I } −→ P {s i 0 | i ∈ I}

Transitionssystem: TS P = (S P , S 0

P

, −→ P )

(8)

Abstraktionssemantik

Verwendung von IR als Wertigkeiten von Variablen (L(D)).

Valuationen:

L(D x ) = IR L(D y ) = IR L(D) = S

v∈X L(D v ) = IR Σ L = X 6→ L(D)

Kleinste obere Schranke:

F ∈ P(L(D)) → L(D)

F {[a 1 , a 1 ], . . . , [a n , a n ]} = def [min({a 1 , . . . , a n }), max ({a 1 , . . . , a n }]

(9)

Abstraktionssemantik

GC zwischen P(D) und L(D):

B ∈ P(D) → L(D) V ∈ P(float)

V B = def [min(v ), max (v)]

C ∈ L(D) → P(D) w = [w , w ] ∈ IR

w C = def {f ∈ float | w ≤ f ≤ w }

(10)

Abstraktionssemantik

Lifting von −:

a, b ∈ IR , a[−]b = def {x − y | x ∈ a C ∧ y ∈ b C } B

⇔ [a, a][−][b, b] = [a − b, a − b]

(11)

Abstraktionssemantik

Lifting von sqrt :

a ∈ IR , [sqrt ](a) = def {sqrt(x) | x ∈ a C } B

⇔ [sqrt]([a, a]) = [sqrt(a), sqrt (a)]

(12)

Abstraktionssemantik

Lifting von <:

a, b ∈ IR , a[<]b = def {x < y | x ∈ a C ∧ y ∈ b C }

⇔ [a, a][<][b, b] =

{true} falls a < b

{false} falls b < a

{true, false } sonst

(13)

Abstraktionssemantik

Erweiterte Valuationsfunktionen:

λ ∈ exp 6→ L(D) λ (v) = def λ(v )

λ (exp 1 − exp 2 ) = def λ (exp 1 )[−]λ (exp 2 ) λ (sqrt(exp)) = def [sqrt](λ (exp))

λ + ∈ bexp 6→ B

λ + (v 1 < v 2 ) = def λ(v 1 )[<]λ(v 2 )

(14)

Abstraktionssemantik

Zusammenfassen von Zust¨ anden aus P(Loc × Σ L ) nach Locations:

κ ∈ P(Loc × Σ L ) → P(Loc × Σ L ) κ(U ) = {(c , λ) ∈ Loc × Σ L | ∀x ∈ X :

λ(x) = F {w ∈ IR |

∃(c 0 , λ 0 ) ∈ U : c = c 0 ∧ λ 0 (x ) = w }}

(15)

Abstraktionssemantik

GC zwischen L und S P :

B ∈ P(Loc × Σ) → P(Loc × Σ L ) S ∈ P(Loc × Σ)

S B = def κ({(c , λ) ∈ Loc × Σ L | ∃σ ∈ Σ : (c , σ) ∈ S ∧ dom σ = dom λ ∧ (∀x ∈ dom σ : {σ(x)} B = λ(x))})

C ∈ P(Loc × Σ L ) → P(Loc × Σ) U ∈ P(Loc × Σ L )

U C = def {(c , σ) ∈ Loc × Σ | ∃λ ∈ Σ L : (c , λ) ∈ U ∧ dom σ = dom λ ∧

(∀x ∈ dom σ : {σ(x)} ⊆ λ(x) C )}

(16)

Abstraktionssemantik

Zustandsraum:

L = def P(Loc × Σ L ) Startzustandsmenge:

L 0 = S 0

P

B

Transitionsrelation −→ L (Sei p, p 0 ∈ S P und a ∈ S L ):

p BC −→ P p 0 p B −→ L p 0B

a C −→ P p 0 a −→ L p 0B Transitionssystem:

TS = (L, L , −→ )

(17)

Berechnung

Betrachte konkreten Zustand:

S = {(P , σ) | x ≤ σ(x) ≤ x ∧ y ≤ σ(y) ≤ y}

Daraus wird unter B :

S B = {(P , λ) | λ(x) = [x, x] ∧ λ(y) = [y, y]}

Und wieder unter C :

S BC = S

(18)

Berechnung

S = {(P , σ) | x ≤ σ(x) ≤ x ∧ y ≤ σ(y) ≤ y}

Betrachte Folgezustand S 0 mit S −→ P S 0 : S 0 = {x = sqrt (y − x); return x, σ) |

x ≤ σ(x) ≤ x ∧ y ≤ σ(y) ≤ y ∧ σ + (x < y) = true }∪

{x = 0; return x , σ) |

x ≤ σ(x) ≤ x ∧ y ≤ σ(y) ≤ y ∧ σ + (x < y) = false } Dieses unter B :

S 0 B = {x = sqrt(y − x); return x , λ) |

λ(x) = [x, x] ∧ λ(y ) = [y, y ] ∧ λ + (x < y) = {true}}∪

{x = 0; return x, σ) |

λ(x) = [x, x] ∧ λ(y ) = [y, y ] ∧ λ + (x < y) = {false}}

(19)

Berechnung

Aus Regel

p BC −→ P p 0 p B −→ L p 0 B geht hervor, dass S B −→ L S 0 B , also:

λ + (x < y) = {true } (P , hx 7→ [x, x], y 7→ [y , y]i) −→ L

(x = sqrt(y − x); return x , hx 7→ [x, x], y 7→ [y , y]i)

(20)

Berechnung

Ein Fehler tritt im n¨ achsten Schritt auf, wenn y − x < 0, oder abstrakt:

[y, y ][−][x, x][<][0, 0] = {true}

⇔ [y − x, y − x][<][0, 0] = {true}

⇔ y − x < 0

(21)

Berechnung

Aus der Voraussetzung wissen wir jedoch:

λ + (x < y) = {true }

⇔ x < y

⇒ x < y

⇔ 0 < y − x

Referenzen

ÄHNLICHE DOKUMENTE

Der neue Algorithmus soll korrekt und vollst¨ andig sein und auf jeder Eingabe terminieren (Beweise sind aber nicht gefordert).. Wenn dies der Fall ist, gib die

Hinweis: (i) passe die Definition von “schlechter Typ” geeignet an und (ii) beachte, dass nun auch ¨ uber Existenz- restriktionen der Form 9 r .C iteriert werden muss. Aufgabe

Der neue Algorithmus soll korrekt und vollst¨andig sein und auf jeder Eingabe terminieren (Beweise sind aber

AG Theorie der k¨ unstlichen Intelligenz FB Mathematik und Informatik, Universit¨at

Bestimme einen geeigneten logischen Formalismus, in dem das R¨atsel repr¨asen- tiert werden kann und ein logisches Schlußfolgerungsproblem, das zur automatischen L¨osung der

Verwenden Sie die ¨ Ubersetzung aus der Vorlesung, um das Konzept C und die TBox T aus Aufgabe 6 in die Logik erster Stufe zu ¨ ubersetzen. Aufgabe 9:

Hinweis 1: formuliere zun¨achst eine geeignete Behauptung, die die Rollentiefe von Konzepten zur Tiefe von Knoten in I k in Verbindung bringt und die sich per Induktion ¨uber

Verwende den Tableau Algorithmus f¨ ur ALC mit generellen TBoxen aus der Vorlesung, um Erf¨ ullbarkeit der folgenden Konzepte C 0 bzgl.. Im Fall (b), gib das Modell aus dem Beweis