Mechanized semantics for Clight Sandrine Blaxy, Xavier Leroy Pim - - PowerPoint PPT Presentation

mechanized semantics for clight
SMART_READER_LITE
LIVE PREVIEW

Mechanized semantics for Clight Sandrine Blaxy, Xavier Leroy Pim - - PowerPoint PPT Presentation

Mechanized semantics for Clight Sandrine Blaxy, Xavier Leroy Pim Jager - Type Theory and Coq The CompCert C project Formally proving a compiler The CompCert project investigates the formal verification of realistic compilers usable


slide-1
SLIDE 1

Mechanized semantics for Clight

Sandrine Blaxy, Xavier Leroy Pim Jager - Type Theory and Coq

slide-2
SLIDE 2

The CompCert C project – Formally proving a compiler

  • ” The CompCert project investigates the formal verification of realistic

compilers usable for critical embedded software”

  • Goal: Formally verify the transformation of C programs to machine

executable assembly.

slide-3
SLIDE 3

Today we focus on Clight, a large subset of C

slide-4
SLIDE 4

Clight is a (very large) subset of C

Including:

  • Most of C types
  • Most C operators
  • Pointers (and pointer arithmetic)
  • Function pointers
  • Structs
  • Unions
  • Almost all control structures

Differences:

  • No GOTO statement
  • Expressions must be pure
  • Ensures termination
  • Ensures deterministic evaluation

a = print(..) + print(..);

slide-5
SLIDE 5

Clight Syntax: Types

slide-6
SLIDE 6

Clight Syntax : Expressions

slide-7
SLIDE 7

Clight syntax: Statements

slide-8
SLIDE 8

C: calculating a least common multiple

int n1, n2; int main() { int lcm; n1 = 42; n2 = 34; lcm = (n1>n2) ? n1 : n2; while(1) { if(lcm%n1==0 && lcm%n2==0){ break; } lcm++; } return lcm; }

slide-9
SLIDE 9

Clight: calculating a least common multiple

int(I32, Signed) n1; int(I32, Signed) n2; int f() { int(I32, Signed) lcm; n1 = 42; n2 = 34; lcm = (n1>n2) ? n1 : n2; while(1) { if(lcm%n1==0 ? (lcm%n2==0 ? 1 : 0) : 0){ break; } else { skip; } lcm = lcm + 1; } return lcm; } main = f

slide-10
SLIDE 10

Semantics of Clight

Expression in left position Expression in right position Execution of terminating statement Execution of diverging statement

  • Big step semantics: 𝑑,𝑡 ⟹ 𝑡%
slide-11
SLIDE 11

Judgment of terminating statements

  • G: Global environment
  • E: Local environment
  • s: statement to be executed
  • M: Current state of memory
  • t: trace of IO events
  • out: statement outcomes:
  • Normal
  • Continue
  • Break
  • Return
  • Return(v)
  • M’: new state of memory
slide-12
SLIDE 12

Semantics of statements (except loops)

Coq

slide-13
SLIDE 13

Recall: Semantics for IMP statements

  • Assignment:
  • Sequencing:
slide-14
SLIDE 14

Semantics of while loops

Coq

slide-15
SLIDE 15

Recall: while in IMP

slide-16
SLIDE 16

Judgment of diverging statements

  • G: Global environment
  • E: Local environment
  • s: statement to be executed
  • M: Current state of memory
  • T: (infinite) trace of IO events
slide-17
SLIDE 17

A statement diverges if any of its components diverges.

Coq

slide-18
SLIDE 18

Just like commands in IMP diverge when any of their components diverge

slide-19
SLIDE 19

Semantics are defined by 8 10 judgments

Calling of terminating functions Calling of diverging functions

slide-20
SLIDE 20

Function calls

Coq

slide-21
SLIDE 21

Function invocation

slide-22
SLIDE 22

2009 to 2016 Big step to Small step

  • CompCert changed semantics model to small step: 𝑡, 𝑛 → (𝑡%, 𝑛%)
  • Small step based on continuations
  • Coq
slide-23
SLIDE 23

Questions?

slide-24
SLIDE 24

Judgment for expressions (in right position)

  • G: Global environment
  • E: Local environment
  • a: expression to be evaluated
  • M: Current state of memory
  • v: result value, either:
  • int(n)
  • float(f)
  • ptr(l)
  • undef
slide-25
SLIDE 25

Semantics for expressions in right position

slide-26
SLIDE 26

Semantics for (a1 op a2) a1 op a2)