29.01.2014 Views

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

A CIL Tutorial - Department of Computer Science - ETH Zürich

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11<br />

Program Verication<br />

In this tutorial, we will use the Why3 [3] verication framework to prove things about C code. In<br />

particular we will generate verication conditions (VCs) from preconditions, postconditions, and<br />

loop invariants given by an annotation syntax that we will add to C using function type attributes<br />

and block attributes. Suppose a function f is annotated with precondition pre and postcondition<br />

post. We ask Why3 to prove the validity <strong>of</strong> pre → V C(f, post).<br />

An introduction to the generation <strong>of</strong> verication conditions for imperative languages can be<br />

found in the textbook by Winskel [6]. In this example we will use the backwards method <strong>of</strong> VC<br />

generation. This will preclude a straightforward handling <strong>of</strong> C constructs like goto, break, and<br />

continue statements. For these, a forwards method <strong>of</strong> VC generation is more suitable. However,<br />

the backwards method is able to handle all the other features <strong>of</strong> C including while loops, for loops,<br />

if statements, and switch statements.<br />

This module allows expression preconditions, postconditions, and loop invariants in C code with<br />

syntax extensions embodied in the following example:<br />

void (pre(p1) post(p2) f)(...) {<br />

while(c) { invariant(c, p3, v1, ..., vn)<br />

}<br />

}<br />

Here, p1, p2, and p3 are propositions that may include universal quantications and implications.<br />

Universal quantication is written as forall(v1,...,vn,p) where v1 through vn are the<br />

variables being quantied over, and p is the formula being quantied over. Implication is written<br />

as implies(p1,p2), where p1 is the antecedent and p2 is the consequent. In the loop invariant annotation,<br />

c is the loop termination condition, p3 is the loop invariant proposition, and v1 through<br />

textttvn are the loop variant variables. Except for forall and implies, C expression syntax is<br />

used for the propositions.<br />

91

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!