Techniques for proving programs with pointers A. Tikhomirov.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Simplifications of Context-Free Grammars
Mathematical Preliminaries
1
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Objectives: Generate and describe sequences. Vocabulary:
UNITED NATIONS Shipment Details Report – January 2006.
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure Definitions 10.3Initializing Structures 10.4Accessing.
Break Time Remaining 10:00.
Turing Machines.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
Data Structures Using C++
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
1 DATA STRUCTURES. 2 LINKED LIST 3 PROS Dynamic in nature, so grow and shrink in size during execution Efficient memory utilization Insertion can be.
EU market situation for eggs and poultry Management Committee 20 October 2011.
Bright Futures Guidelines Priorities and Screening Tables
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
VOORBLAD.
Name Convolutional codes Tomashevich Victor. Name- 2 - Introduction Convolutional codes map information to code bits sequentially by convolving a sequence.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Adding Up In Chunks.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
1 Termination and shape-shifting heaps Byron Cook Microsoft Research, Cambridge Joint work with Josh Berdine, Dino Distefano, and.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
10 -1 Chapter 10 Amortized Analysis A sequence of operations: OP 1, OP 2, … OP m OP i : several pops (from the stack) and one push (into the stack)
Analyzing Genes and Genomes
Speak Up for Safety Dr. Susan Strauss Harassment & Bullying Consultant November 9, 2012.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Clock will move after 1 minute
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
User Defined Functions Lesson 1 CS1313 Fall User Defined Functions 1 Outline 1.User Defined Functions 1 Outline 2.Standard Library Not Enough #1.
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
Data Structures Using C++ 2E
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
Presentation transcript:

Techniques for proving programs with pointers A. Tikhomirov

Why is it important? Every program works not only with stack but stores intermediate data in heap and use pointers to operate with heap. Common program verification techniques couldn’t work with pointers and heap. 2

SEPARATION LOGIC John C. Reynolds, Peter O’Hearn 3

Fail using Hoare Logic Structure of Hoare Logic assignment judgment couldn't work with heap. int x = 5; int *y = &x; // *y = 5 x = 3; // *y = 3 Hoare logic doesn’t specify holding of *y 4 FAIL

Separation Logic Representing the Heap Assertions empty heap singleton heap separating conjunction separating implication 5

Separation Logic Asserts that x points to an adjacent pair of cells containing u, v (x stores address α and the heap maps α into u and (α +1) into v) 6

Singleton heap Reference pointer to some cell Asserts that x points to an adjacent pair of sells containing 1 and y. 7

Separating conjunction 8 The separating conjunction constructs a heap property from two disjoint heaps

Logical conjunction Could be ambiguous in heap, x and y could be aliases,or disjoint. 9

Lists List representation 10

Frame rule Frame rule: This rule holds as long as free variables in s not mentioned in R. 11

Allocation Allocation rule (local): Allocation rule (global): 12

Deallocation Dispose rule (local): Dispose rule (global): 13

Heap write (mutation) Mutation forward rule (local): Mutation forward rule (global): 14

Examples of Operational Semantics 15 Allocation x := cons(y, z) Heap lookup y := [x+1] Mutation [x + 1] := 3 Deallocation dispose(x+1) Store: [x:3, y:40, z:17] Heap: empty Store: [x:37, y:40, z:17] Heap: [37:40, 38:17] Store: [x:37, y:17, z:17] Heap: [37:40, 38:3] Store: [x:37, y:17, z:17] Heap: [37:40, 38:17] Store: [x:37, y:17, z:17] Heap: [37:40]

Example: Swap Function in which the contents of two heap cells are swapped: t1 := [v1] t2 := [v2] [v1] := t2 [v2] := t1 16

Example: Swap void swap (int* v1, int* v2) { t1:= [v1] t2 := [v2] [v1] := t2 [v2] := t1 } 17 // {v1 > v1’ * v2 > v2’} // {t1 = v1’ & v1 > v1’ * v2 > v2’} // {t1 = v1’ & t2 = v2’ & v1 > v1’ * v2 > v2’} // {t1 = v1’ & t2 = v2’ & v1 > v2’ * v2 > v2’} // {t1 = v1’ & t2 = v2’ & v1 > v2’ * v2 > v1’}

Example: Doubly Indirect References Mutating the value of a double indirect reference (a pointer to a pointer): 18

Example: Doubly Indirect References void write (int** p, int v) { t:= [p] [t] := v } 19 // {p > w * w > —} // {p > w}Frame rule – begin // {t = w & p > w}Mutation // {t = w & p > w * w > —} Frame rule — end // {t = w & w > —}Frame rule — begin // {t = w & w > v}Mutation // {t = W & p > w * w > v}Frame rule — end // {p > w * w > v}Remove extra stack assertion

Example: Doubly Indirect References Attempting to aggressively apply Frame rule to entire block would result in a stuck proof. void write (int** p, int v) { // {p > w * w > —} // {p > w}Frame rule – begin t:= [p] // {t = w & p > w}Mutation [t] := v // {??}Stuck – no mapping for w // {t = W & p > w * w > v}Frame rule — end } 20

Example: DeleteTree 21 void deleteTree (t) { local i,j; if (t != nil) { i = [t] j = [t+1] deleteTree(j) deleteTree(i) dispose(t) } // {tree(t)} // {tree(t) ^ t != nil} // { ∃ x,y. t > (x,y) * tree(x) * tree(y)} // {emp} // {t > (i,j) * tree(i) * tree(j)} // {t > (i,j) * tree(i)} // {t > (i,j) * nil} // {emp}

Example: List reverse 22 list reverse (x) { y = nil; while (x != nil) { t := [x]; x := [y]; y := x; x := t; } return y; } // {list(x)} // {list(y)} // {list(x) * list(y)} // {x != nil ^ list(x) * list(y)} // {x > t ^ list(t) * list(y)} // {x > y ^ list(x) * list(y)} // {list(t) * list(x)} // {list(t) * list(y)} // {list(x) * list(y)} // {x = nil ^ list(x) * list(y)}

Conclusion Extension of Hoare logic – Could use verification tools, that work with Hoare logic For automatic proving – Assertions – Pre and post-conditions 23

SHAPE ANALYSIS Reinhard Wilhelm, Mooly Sagiv, Thomas Reps 24

Shape Analysis Somewhat constrained view of programs Static code analysis Program verification 25

Destructive Reverse 26

Input to reverse (a) lists of length at least 2 (b) list of length 1 27

Input to reverse List structure of size from 0 to 4 28

Graph interpretation Rectangle box containing p represent pointer variable p Ovals – abstract locations – solid – represents exactly one heap cell – dotted – represent one or more heap cells Edge – label c between locations m and m’ – solid – c component of m will point to m’ – dotted - c component of m may point to m’ 29

3-value logic solid means “always holds” absent means “never hold” dotted means “don’t know” 30

Execution states (a) – shape arise before executing x=x->n (b) & – (c) after executing x=x->n on shape (a) 31

Insert algorithm The same list structure 32

Execution States (1) 33 y = x; while (y->n != NULL) {y = y->n}

Execution States (2) 34 t = malloc(); t -> data = n

Execution States (3) 35 e = y->n;

Execution States (4) 36 t->n = NULL; t->n = e;

Execution States (5) 37 y->n = NULL;

Execution States (6) 38 y->n = t;

Conclusion Code analysis – NULL-pointers; – May-Alias; – Must-Alias; – Sharing; – Reachability; – Disjointness; – Cyclicity; – Shape; 39