Vous êtes sur la page 1sur 10

Lazy Abstraction with Pointer

12/17/08 Nguyen Mai Xuan 1
Overview

 Abstractions from Proofs
 Problems with Pointers
 A few ideas to deal with Pointers

    2
Abstractions from Proofs
Entry

x = ctr x1 = ctr1
ctr = ctr + 1 ctr2 = ctr1 + 1
y = ctr y1 = ctr2

G10001 {x1 = y1 ­ 1}

if (x = m) (x1 = m1)

G10002 {y1 = m1 + 1}

if (y != m + 1)  (y1 != m1 + 1)

Error
    3
Abstractions from Proofs (cont.)
Entry True

x = ctr
ctr = ctr + 1
y = ctr

G10001 {x1 = y1 ­ 1}

x = y ­ 1
if (x = m)

G10002 {y1 = m1 + 1}

if (y != m + 1) y = m + 1

Error False
    4
Problems with Pointers
Entry
i = 1 i1 = 1
j = 2 j1 = 2

G10001

a = &i a1 = &i1
b = &j b1 = &j1

G10002
tmp_b = *b tmp_b1 = (*b1, 1)
tmp_a = *a tmp_a1 = (*a1, 1)
*b = tmp_a (*b1, 2) = tmp_a1
*a = tmp_b (*a1, 2) = tmp_b1
G10003

if (i != 2 || j != 1) (i1 !=2 || j1 != 1)

  Error Reach to Error Node ☹
  5
Idea 1: use Integer ­ Table
Entry
i = 1 i1 = 1
j = 2 j1 = 2

G10001 {i1 = 1; j1 = 2} 

a = &i a1 = &i1 (*a1, 1) = i1


b = &j b1 = &j1 (*b1, 1) = j1

{(*a1, 1) = 1; (*b1, 1) = 2} 0 1
G10002
i j a b
tmp_b = *b tmp_b1 = (*b1, 1)
tmp_a = *a tmp_a1 = (*a1, 1)
*b = tmp_a (*b1, 2) = tmp_a1 j2 = tmp_a1
*a = tmp_b (*a1, 2) = tmp_b1 i2 = tmp_b1
0 1
G10003 {i2 = 2; j2 = 1}
i j a b

if (i != 2 || j != 1) (i2 !=2 || j2 != 1)

  Error   6
Refinement: problems with Idea 1
Entry True
i = 1
j = 2

G10001 {i1 = 1; j1 = 2} 

a = &i (i = 1) /\ (j = 2)
b = &j

G10002 {(*a1, 1) = 1; (*b1, 1) = 2}

tmp_b = *b (*a = 1) /\ (*b = 2)
tmp_a = *a
*b = tmp_a
*a = tmp_b
G10003 {i2 = 2; j2 = 1}

if (i != 2 || j != 1) []

  Error   7
True
Idea 2: 
Entry 0 1
i j a b
i = 1 i1 = 1
j = 2 j1 = 2

G10001 {i1 = 1; j1 = 2} 

a = &i a1 = &i1 (*a1, 1) = i1


b = &j b1 = &j1 (*b1, 1) = j1

G10002 {a1 = &i1; (*a1, 1) = 1; b1 = &j1; (*b1, 1) = 2}

tmp_b = *b tmp_b1 = (*b1, 1)
tmp_a = *a tmp_a1 = (*a1, 1)
*b = tmp_a (*b1, 2) = tmp_a1 (b1 = &j1) => (j2 = tmp_a1)
*a = tmp_b (*a1, 2) = tmp_b1 (a1 = &i1) => (i2 = tmp_b1)
G10003 {i2 = 2; j2 = 1}

if (i != 2 || j != 1) (i2 !=2 || j2 != 1)

  Error   8
Refine successfully !!!
True
Entry
i = 1
j = 2

G10001 {i1 = 1; j1 = 2} 

a = &i
 (i = 1) /\  (j = 2) 
b = &j

G10002 {a1 = &i1; (*a1, 1) = 1; b1 = &j1; (*b1, 1) = 2}
tmp_b = *b
(a = &i) /\ (*a = 1) /\ (b = &j)  /\ (*b = 2)
tmp_a = *a
*b = tmp_a 0 1
*a = tmp_b i j a b

G10003 {i2 = 2; j2 = 1}

if (i != 2 || j != 1)  (i = 2) /\ (j = 1)

  Error False   9
Thinking... ☺

 Complexity time?
 What is the problem when deals with recursive 
structures & arrays?

    10

Vous aimerez peut-être aussi