Separation Logic for Non-local Control Flow and Block Scope - - PowerPoint PPT Presentation

separation logic for non local control flow and block
SMART_READER_LITE
LIVE PREVIEW

Separation Logic for Non-local Control Flow and Block Scope - - PowerPoint PPT Presentation

Separation Logic for Non-local Control Flow and Block Scope Variables Robbert Krebbers Joint work with Freek Wiedijk Radboud University Nijmegen February 4, 2013 @ Gallium, INRIA Rocquencourt, France What is this program supposed to do? int


slide-1
SLIDE 1

Separation Logic for Non-local Control Flow and Block Scope Variables

Robbert Krebbers Joint work with Freek Wiedijk

Radboud University Nijmegen

February 4, 2013 @ Gallium, INRIA Rocquencourt, France

slide-2
SLIDE 2

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; }

slide-3
SLIDE 3

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p NULL

slide-4
SLIDE 4

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p NULL

slide-5
SLIDE 5

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p NULL j 10

slide-6
SLIDE 6

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p

  • j

10

slide-7
SLIDE 7

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p

  • j

10

slide-8
SLIDE 8

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p

slide-9
SLIDE 9

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p

slide-10
SLIDE 10

What is this program supposed to do?

int *p = NULL; l: if (p) { return (*p); } else { int j = 10; p = &j; goto l; } memory: p

  • It exhibits undefined behavior, thus it may do anything
slide-11
SLIDE 11

Why is catching undefined behavior important

◮ C allows a program to do anything on undefined behavior

slide-12
SLIDE 12

Why is catching undefined behavior important

◮ C allows a program to do anything on undefined behavior ◮ It cannot be checked statically

slide-13
SLIDE 13

Why is catching undefined behavior important

◮ C allows a program to do anything on undefined behavior ◮ It cannot be checked statically ◮ Not catching it means that

◮ programs can be proven to be correct with respect to the

formal semantics . . .

slide-14
SLIDE 14

Why is catching undefined behavior important

◮ C allows a program to do anything on undefined behavior ◮ It cannot be checked statically ◮ Not catching it means that

◮ programs can be proven to be correct with respect to the

formal semantics . . .

◮ whereas they may crash when compiled with an actual compiler

slide-15
SLIDE 15

Goto considered harmful?

http://xkcd.com/292/

slide-16
SLIDE 16

Goto considered harmful?

http://xkcd.com/292/ Not necessarily: ⊢ {P} . . . goto main_sub3; . . . {Q}

slide-17
SLIDE 17

Why goto

Goto can be useful

◮ Breaking from multiple nested loops for (int i = 0; i++; i < n) { // do something here for (int j = i; j++; j < m) { // do some work here goto outer; } }

  • uter:;
slide-18
SLIDE 18

Why goto

Goto can be useful

◮ Breaking from multiple nested loops ◮ Systematically cleaning up resources after errors if (!openDataFile()) goto quit; if (!getDataFromFile()) goto closeFileAndQuit; if (!allocateSomeResources) goto freeResourcesAndQuit; // do actual work here freeResourcesAndQuit: // free resources closeFileAndQuit: // close file quit: // quit!

slide-19
SLIDE 19

Why goto

Goto can be useful

◮ Breaking from multiple nested loops ◮ Systematically cleaning up resources after errors ◮ To increase performance

slide-20
SLIDE 20

Why goto

Goto can be useful

◮ Breaking from multiple nested loops ◮ Systematically cleaning up resources after errors ◮ To increase performance

Goto is used in practice

◮ The Linux kernel contains about ∼ 100.000 uses of goto $ grep -w -r goto ~/src/linux-3.5.5 --include \*.c | wc -l 101026 $ find ./ -name \*.c -exec cat ’{}’ \; | wc -l 11152601

slide-21
SLIDE 21

This talk

An elegant small step semantics, and axiomatic semantics for goto, supporting:

◮ local variables (and pointers to those), ◮ mutual recursion, ◮ separation logic, ◮ soundness proof fully checked by Coq

slide-22
SLIDE 22

Approach

◮ Small step semantics by traversal through the program

slide-23
SLIDE 23

Approach

◮ Small step semantics by traversal through the program ◮ Traversal in four directions:

◮ ց downwards to the next statement ◮ ր upwards to the next statement

slide-24
SLIDE 24

Approach

◮ Small step semantics by traversal through the program ◮ Traversal in four directions:

◮ ց downwards to the next statement ◮ ր upwards to the next statement ◮ l to a label l: after a goto l

slide-25
SLIDE 25

Approach

◮ Small step semantics by traversal through the program ◮ Traversal in four directions:

◮ ց downwards to the next statement ◮ ր upwards to the next statement ◮ l to a label l: after a goto l ◮ ↑

↑ to the top after a return

slide-26
SLIDE 26

Approach

◮ Small step semantics by traversal through the program ◮ Traversal in four directions:

◮ ց downwards to the next statement ◮ ր upwards to the next statement ◮ l to a label l: after a goto l ◮ ↑

↑ to the top after a return

◮ Gotos and returns are also executed in small steps

slide-27
SLIDE 27

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l

slide-28
SLIDE 28

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p NULL

slide-29
SLIDE 29

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p NULL

slide-30
SLIDE 30

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p NULL

slide-31
SLIDE 31

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p NULL j 10

slide-32
SLIDE 32

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p NULL j 10

slide-33
SLIDE 33

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p

  • j

10

slide-34
SLIDE 34

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ր

memory: p

  • j

10

slide-35
SLIDE 35

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ր

memory: p

  • j

10

slide-36
SLIDE 36

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p

  • j

10

slide-37
SLIDE 37

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p

  • j

10

slide-38
SLIDE 38

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

l

memory: p

  • j

10

slide-39
SLIDE 39

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

l

memory: p

  • j

10

slide-40
SLIDE 40

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

l

memory: p

  • j

10

slide-41
SLIDE 41

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

l

memory: p

slide-42
SLIDE 42

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

l

memory: p

slide-43
SLIDE 43

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p

slide-44
SLIDE 44

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p

slide-45
SLIDE 45

Example

int *p = NULL l: if (p) return (*p) int j = 10 ; p = &j goto l direction:

ց

memory: p

slide-46
SLIDE 46

How to model the current location in the program

Huet’s zipper Purely functional way to store a pointer into a data structure

slide-47
SLIDE 47

Statement contexts

◮ Statements:

s ::= block s | el := er | f ( e) | skip | goto l | l : s | s1 ; s2 | if (e) s1 s2 | return

slide-48
SLIDE 48

Statement contexts

◮ Statements:

s ::= block s | el := er | f ( e) | skip | goto l | l : s | s1 ; s2 | if (e) s1 s2 | return

◮ Singular statement contexts:

ES ::= ; s2 | s1 ; | if (e) s2 | if (e) s1 | l :

slide-49
SLIDE 49

Statement contexts

◮ Statements:

s ::= block s | el := er | f ( e) | skip | goto l | l : s | s1 ; s2 | if (e) s1 s2 | return

◮ Singular statement contexts:

ES ::= ; s2 | s1 ; | if (e) s2 | if (e) s1 | l :

◮ A pair (

ES, s) forms a zipper for statements, where

  • ES is a statement turned inside-out

◮ s is the focused substatement

slide-50
SLIDE 50

Stacks

◮ A stack is a list of memory indexes ◮ A variable xi refers to the ith element on the stack

Stack x0

  • x1
  • x2
  • Memory

10

  • 12
slide-51
SLIDE 51

Stacks

◮ A stack is a list of memory indexes ◮ A variable xi refers to the ith element on the stack

Stack x0

  • x1
  • x2
  • Memory

10

  • 12

◮ Uniform way of dealing with pointers to local variables

slide-52
SLIDE 52

Program contexts (1)

Singular program contexts: E ::= ES | blockb | call f e | params b where:

slide-53
SLIDE 53

Program contexts (1)

Singular program contexts: E ::= ES | blockb | call f e | params b where:

◮ blockb associates a block scope variable with its

corresponding memory index b

slide-54
SLIDE 54

Program contexts (1)

Singular program contexts: E ::= ES | blockb | call f e | params b where:

◮ blockb associates a block scope variable with its

corresponding memory index b

◮ call f

e contains the location of the caller so that it can be restored when f returns

slide-55
SLIDE 55

Program contexts (1)

Singular program contexts: E ::= ES | blockb | call f e | params b where:

◮ blockb associates a block scope variable with its

corresponding memory index b

◮ call f

e contains the location of the caller so that it can be restored when f returns

◮ params

b contains the memory indexes of the function parameters

slide-56
SLIDE 56

Program contexts (1)

Singular program contexts: E ::= ES | blockb | call f e | params b where:

◮ blockb associates a block scope variable with its

corresponding memory index b

◮ call f

e contains the location of the caller so that it can be restored when f returns

◮ params

b contains the memory indexes of the function parameters Program contexts k are lists of singular program contexts

slide-57
SLIDE 57

Program contexts (2)

◮ Program contexts contain the stack:

getstack (ES :: k) := getstack k getstack (blockb :: k) := b :: getstack k getstack (call f e :: k) := [ ] getstack (params b :: k) := b + + getstack k

slide-58
SLIDE 58

Program contexts (2)

◮ Program contexts contain the stack:

getstack (ES :: k) := getstack k getstack (blockb :: k) := b :: getstack k getstack (call f e :: k) := [ ] getstack (params b :: k) := b + + getstack k

◮ Remark: not getstack (call f

e :: k) := getstack k

slide-59
SLIDE 59

States

A state S(k, φ, m) consists of a program context k, focus φ, and memory m

slide-60
SLIDE 60

States

A state S(k, φ, m) consists of a program context k, focus φ, and memory m We consider the following focuses:

◮ (d, s) execution of a statement s in direction d

slide-61
SLIDE 61

States

A state S(k, φ, m) consists of a program context k, focus φ, and memory m We consider the following focuses:

◮ (d, s) execution of a statement s in direction d ◮ call f

v calling a function f ( v)

slide-62
SLIDE 62

States

A state S(k, φ, m) consists of a program context k, focus φ, and memory m We consider the following focuses:

◮ (d, s) execution of a statement s in direction d ◮ call f

v calling a function f ( v)

◮ return returning from a function

slide-63
SLIDE 63

Example

int *p = NULL l: if (p) return int j = 10 ; p = &j goto l

The corresponding state is S(k, φ, m), where:

◮ k = [

; goto l, x0 := int 10 ; , blockbj , if (load x0) return , l : , x0 := NULL ; , blockbp ]

◮ φ = (ր, x1 := x0) ◮ m = {bp → ptr bj, bj → 10}

slide-64
SLIDE 64

The small step semantics

Some rules:

◮ S(k, (ց, e1 := e2), m) S(k, (ր, e1 := e2), m[a := v])

for a and v s.t. [ [ e1 ] ]k,m = ptr a, [ [ e2 ] ]k,m = v and m a = ⊥.

slide-65
SLIDE 65

The small step semantics

Some rules:

◮ S(k, (ց, e1 := e2), m) S(k, (ր, e1 := e2), m[a := v])

for a and v s.t. [ [ e1 ] ]k,m = ptr a, [ [ e2 ] ]k,m = v and m a = ⊥.

◮ S(k, (ց, s1 ; s2), m) S(( ; s2) :: k, (ց, s1), m)

slide-66
SLIDE 66

The small step semantics

Some rules:

◮ S(k, (ց, e1 := e2), m) S(k, (ր, e1 := e2), m[a := v])

for a and v s.t. [ [ e1 ] ]k,m = ptr a, [ [ e2 ] ]k,m = v and m a = ⊥.

◮ S(k, (ց, s1 ; s2), m) S(( ; s2) :: k, (ց, s1), m) ◮ S(( ; s2) :: k, (ր, s1), m) S((s1 ; ) :: k, (ց, s2), m)

slide-67
SLIDE 67

The small step semantics

Some rules:

◮ S(k, (ց, e1 := e2), m) S(k, (ր, e1 := e2), m[a := v])

for a and v s.t. [ [ e1 ] ]k,m = ptr a, [ [ e2 ] ]k,m = v and m a = ⊥.

◮ S(k, (ց, s1 ; s2), m) S(( ; s2) :: k, (ց, s1), m) ◮ S(( ; s2) :: k, (ր, s1), m) S((s1 ; ) :: k, (ց, s2), m) ◮ S((s1 ; ) :: k, (ր, s2), m) S(k, (ր, s1 ; s2), m)

slide-68
SLIDE 68

The small step semantics

Some rules:

◮ S(k, (ց, e1 := e2), m) S(k, (ր, e1 := e2), m[a := v])

for a and v s.t. [ [ e1 ] ]k,m = ptr a, [ [ e2 ] ]k,m = v and m a = ⊥.

◮ S(k, (ց, s1 ; s2), m) S(( ; s2) :: k, (ց, s1), m) ◮ S(( ; s2) :: k, (ր, s1), m) S((s1 ; ) :: k, (ց, s2), m) ◮ S((s1 ; ) :: k, (ր, s2), m) S(k, (ր, s1 ; s2), m) ◮ S(k, (ց, goto l), m) S(k, ( l, goto l), m)

slide-69
SLIDE 69

The small step semantics

Some rules:

◮ S(k, (ց, e1 := e2), m) S(k, (ր, e1 := e2), m[a := v])

for a and v s.t. [ [ e1 ] ]k,m = ptr a, [ [ e2 ] ]k,m = v and m a = ⊥.

◮ S(k, (ց, s1 ; s2), m) S(( ; s2) :: k, (ց, s1), m) ◮ S(( ; s2) :: k, (ր, s1), m) S((s1 ; ) :: k, (ց, s2), m) ◮ S((s1 ; ) :: k, (ր, s2), m) S(k, (ր, s1 ; s2), m) ◮ S(k, (ց, goto l), m) S(k, ( l, goto l), m) ◮ S(k, ( l, l : s), m) S((l : ) :: k, (ց, s), m)

slide-70
SLIDE 70

The small step semantics

Some rules:

◮ S(k, (ց, e1 := e2), m) S(k, (ր, e1 := e2), m[a := v])

for a and v s.t. [ [ e1 ] ]k,m = ptr a, [ [ e2 ] ]k,m = v and m a = ⊥.

◮ S(k, (ց, s1 ; s2), m) S(( ; s2) :: k, (ց, s1), m) ◮ S(( ; s2) :: k, (ր, s1), m) S((s1 ; ) :: k, (ց, s2), m) ◮ S((s1 ; ) :: k, (ր, s2), m) S(k, (ր, s1 ; s2), m) ◮ S(k, (ց, goto l), m) S(k, ( l, goto l), m) ◮ S(k, ( l, l : s), m) S((l : ) :: k, (ց, s), m) ◮ S(k, (ց, f (

e)), m) S(call f e :: k, call f v, m) provided that [ [ ei ] ]k,m = vi for each i

slide-71
SLIDE 71

The small step semantics

Lemma

The small step semantics behaves as traversing through a zipper. That is, if S(k, (d, s), m) ∗

k S(k, (d′, s′), m′)

then s = s′.

slide-72
SLIDE 72

Hoare triples

Traditional Hoare triples are of the shape {P} s {Q} Intuitive meaning:

◮ If P holds for the state before execution of s, ◮ and execution of s terminates, ◮ then Q will hold afterwards

slide-73
SLIDE 73

Extended Hoare ‘triples’ (1)

Our Hoare sextuples are of the shape ∆; J; R ⊢ {P} s {Q}

slide-74
SLIDE 74

Extended Hoare ‘triples’ (1)

Our Hoare sextuples are of the shape ∆; J; R ⊢ {P} s {Q} where:

◮ ∆ maps function names to their pre- and postconditions

slide-75
SLIDE 75

Extended Hoare ‘triples’ (1)

Our Hoare sextuples are of the shape ∆; J; R ⊢ {P} s {Q} where:

◮ ∆ maps function names to their pre- and postconditions ◮ J maps labels to their jumping condition

When executing a goto l, the assertion J l has to hold

slide-76
SLIDE 76

Extended Hoare ‘triples’ (1)

Our Hoare sextuples are of the shape ∆; J; R ⊢ {P} s {Q} where:

◮ ∆ maps function names to their pre- and postconditions ◮ J maps labels to their jumping condition

When executing a goto l, the assertion J l has to hold

◮ R has to hold to execute a return

slide-77
SLIDE 77

Extended Hoare ‘triples’ (2)

Our Hoare sextuples are of the shape ∆; J; R ⊢ {P} s {Q} Observations:

◮ The assertions P, Q, J and R correspond to the four

directions ց, ր, and ↑

slide-78
SLIDE 78

Extended Hoare ‘triples’ (2)

Our Hoare sextuples are of the shape ∆; J; R ⊢ {P} s {Q} Observations:

◮ The assertions P, Q, J and R correspond to the four

directions ց, ր, and ↑

↑ ◮ We thus treat the sextuple as

∆; ¯ P ⊢ s where ¯ P ց = P, ¯ P ր = Q, ¯ P ( l) = J l and ¯ P ↑

↑ = R

slide-79
SLIDE 79

Some Hoare rules

Weakening: (∀l ∈ labels s . J′l → Jl) (∀l / ∈ labels s . Jl → J′l) R → R′ P′ → P ∆; J; R ⊢ {P} s {Q} Q → Q′ ∆; J′; R′ ⊢ {P′} s {Q′}

slide-80
SLIDE 80

Some Hoare rules

Weakening: (∀l ∈ labels s . J′l → Jl) (∀l / ∈ labels s . Jl → J′l) R → R′ P′ → P ∆; J; R ⊢ {P} s {Q} Q → Q′ ∆; J′; R′ ⊢ {P′} s {Q′} Composition: ∆; J; R ⊢ {P} s1 {P′} ∆; J; R ⊢ {P′} s2 {Q} ∆; J; R ⊢ {P} s1 ; s2 {Q}

slide-81
SLIDE 81

Some Hoare rules

Weakening: (∀l ∈ labels s . J′l → Jl) (∀l / ∈ labels s . Jl → J′l) R → R′ P′ → P ∆; J; R ⊢ {P} s {Q} Q → Q′ ∆; J′; R′ ⊢ {P′} s {Q′} Composition: ∆; J; R ⊢ {P} s1 {P′} ∆; J; R ⊢ {P′} s2 {Q} ∆; J; R ⊢ {P} s1 ; s2 {Q} Non-local control: ∆; J; R ⊢ {R} return {Q}

slide-82
SLIDE 82

Some Hoare rules

Weakening: (∀l ∈ labels s . J′l → Jl) (∀l / ∈ labels s . Jl → J′l) R → R′ P′ → P ∆; J; R ⊢ {P} s {Q} Q → Q′ ∆; J′; R′ ⊢ {P′} s {Q′} Composition: ∆; J; R ⊢ {P} s1 {P′} ∆; J; R ⊢ {P′} s2 {Q} ∆; J; R ⊢ {P} s1 ; s2 {Q} Non-local control: ∆; J; R ⊢ {R} return {Q} ∆; J; R ⊢ {J l} goto l {Q} ∆; J; R ⊢ {J l} s {Q} ∆; J; R ⊢ {J l} l : s {Q}

slide-83
SLIDE 83

The frame rule

Used for local reasoning ∆; J; R ⊢ {P} s {Q} ∆; J ∗ A; R ∗ A ⊢ {P ∗ A} s {Q ∗ A}

slide-84
SLIDE 84

The frame rule

Used for local reasoning ∆; J; R ⊢ {P} s {Q} ∆; J ∗ A; R ∗ A ⊢ {P ∗ A} s {Q ∗ A} Using our alternative notation: ∆; ¯ P ⊢ s ∆; ¯ P ∗ A ⊢ s

slide-85
SLIDE 85

The block scope variable rule

The assertion A ↑ lifts the DeBruijn indexes in A ∆; J ↑ ∗ x0 → -; R ↑ ∗ x0 → - ⊢ {P ↑ ∗ x0 → -} s {Q ↑ ∗ x0 → -} ∆; J; R ⊢ {P} block s {Q}

slide-86
SLIDE 86

The block scope variable rule

The assertion A ↑ lifts the DeBruijn indexes in A ∆; J ↑ ∗ x0 → -; R ↑ ∗ x0 → - ⊢ {P ↑ ∗ x0 → -} s {Q ↑ ∗ x0 → -} ∆; J; R ⊢ {P} block s {Q} Using our alternative notation ∆; ¯ P ↑ ∗ x0 → - ⊢ s ∆; ¯ P ⊢ block s

slide-87
SLIDE 87

Example

void swap(int *p, int *q) { int z = *p; *p = *q; *q = z; }

slide-88
SLIDE 88

Example

{x0 → p ∗ x1 → q ∗ p → y ∗ q → z} block ( x0 := load (load x1) ; load x1 := load (load x2) ; load x2 := load x0 ) {x0 → p ∗ x1 → q ∗ p → z ∗ q → y}

slide-89
SLIDE 89

Example

{x0 → p ∗ x1 → q ∗ p → y ∗ q → z} block ( {x0 → - ∗ x1 → p ∗ x2 → q ∗ p → y ∗ q → z} x0 := load (load x1) ; load x1 := load (load x2) ; load x2 := load x0 ) {x0 → p ∗ x1 → q ∗ p → z ∗ q → y}

slide-90
SLIDE 90

Example

{x0 → p ∗ x1 → q ∗ p → y ∗ q → z} block ( {x0 → - ∗ x1 → p ∗ x2 → q ∗ p → y ∗ q → z} x0 := load (load x1) ; {x0 → y ∗ x1 → p ∗ x2 → q ∗ p → y ∗ q → z} load x1 := load (load x2) ; load x2 := load x0 ) {x0 → p ∗ x1 → q ∗ p → z ∗ q → y}

slide-91
SLIDE 91

Example

{x0 → p ∗ x1 → q ∗ p → y ∗ q → z} block ( {x0 → - ∗ x1 → p ∗ x2 → q ∗ p → y ∗ q → z} x0 := load (load x1) ; {x0 → y ∗ x1 → p ∗ x2 → q ∗ p → y ∗ q → z} load x1 := load (load x2) ; {x0 → y ∗ x1 → p ∗ x2 → q ∗ p → z ∗ q → z} load x2 := load x0 ) {x0 → p ∗ x1 → q ∗ p → z ∗ q → y}

slide-92
SLIDE 92

Example

{x0 → p ∗ x1 → q ∗ p → y ∗ q → z} block ( {x0 → - ∗ x1 → p ∗ x2 → q ∗ p → y ∗ q → z} x0 := load (load x1) ; {x0 → y ∗ x1 → p ∗ x2 → q ∗ p → y ∗ q → z} load x1 := load (load x2) ; {x0 → y ∗ x1 → p ∗ x2 → q ∗ p → z ∗ q → z} load x2 := load x0 {x0 → y ∗ x1 → p ∗ x2 → q ∗ p → z ∗ q → y} ) {x0 → p ∗ x1 → q ∗ p → z ∗ q → y}

slide-93
SLIDE 93

Soundness of the axiomatic semantics

◮ Define ∆; J; R {P} s {Q} in terms of operational semantics

slide-94
SLIDE 94

Soundness of the axiomatic semantics

◮ Define ∆; J; R {P} s {Q} in terms of operational semantics ◮ Prove ∆; J; R ⊢ {P} s {Q} implies ∆; J; R {P} s {Q}

slide-95
SLIDE 95

Soundness of the axiomatic semantics

◮ Define ∆; J; R {P} s {Q} in terms of operational semantics ◮ Prove ∆; J; R ⊢ {P} s {Q} implies ∆; J; R {P} s {Q} ◮ Tricky definition of ∆; J; R {P} s {Q} because

◮ The frame rule ◮ Undefined behavior ◮ Non-local control ◮ Mutual recursion

slide-96
SLIDE 96

Formalization in Coq

◮ Extremely useful for debugging

slide-97
SLIDE 97

Formalization in Coq

◮ Extremely useful for debugging ◮ Notations close to those on paper

slide-98
SLIDE 98

Formalization in Coq

◮ Extremely useful for debugging ◮ Notations close to those on paper ◮ Also supports while and functions with return values

slide-99
SLIDE 99

Formalization in Coq

◮ Extremely useful for debugging ◮ Notations close to those on paper ◮ Also supports while and functions with return values ◮ Axiomatic semantics as derived lemmas instead of inference

system

slide-100
SLIDE 100

Formalization in Coq

◮ Extremely useful for debugging ◮ Notations close to those on paper ◮ Also supports while and functions with return values ◮ Axiomatic semantics as derived lemmas instead of inference

system

◮ Uses lots of automation

slide-101
SLIDE 101

Formalization in Coq

◮ Extremely useful for debugging ◮ Notations close to those on paper ◮ Also supports while and functions with return values ◮ Axiomatic semantics as derived lemmas instead of inference

system

◮ Uses lots of automation ◮ 3500 lines of code

slide-102
SLIDE 102

Future research

◮ Expressions with side effects ◮ The C type system ◮ Non-aliasing restrictions ◮ Verification condition generator in Coq ◮ Correspondence with CompCert

slide-103
SLIDE 103

Questions

Sources: see http://robbertkrebbers.nl/research/ch2o/