1/25 Pointer Logic Changki PSWLAB Pointer Logic Daniel Kroening and Ofer Strichman Decision Procedure.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

CHP-5 LinkedList.
Symbol Table.
Intermediate Code Generation
Overview of Previous Lesson(s) Over View  Front end analyzes a source program and creates an intermediate representation from which the back end generates.
The Assembly Language Level
Kernighan/Ritchie: Kelley/Pohl:
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Compiler Construction
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Chapter 9. 2 Objectives You should be able to describe: Addresses and Pointers Array Names as Pointers Pointer Arithmetic Passing Addresses Common Programming.
Pointers Pointer - A pointer is a derived data type; that is it is a data type built from one of the standard types. Its value is any of the addresses.
Pointers. Addresses in Memory When a variable is declared, enough memory to hold a value of that type is allocated for it at an unused memory location.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 9 Pointers and Dynamic Arrays.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Chapter 9 Pointers. 2 Topics 8.1 Getting the Address of a Variable 8.2 Pointer Variables 8.3 Relationship Between Arrays and Pointers 8.4 Pointer Arithmetic.
Pointers Applications
Chapter 12 Pointers and linked structures. 2 Introduction  The data structures that expand or contract as required during the program execution is called.
Daniel Kroening and Ofer Strichman Decision Procedure
Deciding a Combination of Theories - Decision Procedure - Changki pswlab Combination of Theories Daniel Kroening, Ofer Strichman Presented by Changki.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Chapter TwelveModern Programming Languages1 Memory Locations For Variables.
Imperative Programming
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Binary Decision Diagrams (BDDs)
Quantified Formulas - Decision Procedure Daniel Kroening, Ofer Strichman Presented by Changki Hong 07 NOV 08.
1 Automatic Refinement and Vacuity Detection for Symbolic Trajectory Evaluation Orna Grumberg Technion Haifa, Israel Joint work with Rachel Tzoref.
Compiler Construction
Chapter 0.2 – Pointers and Memory. Type Specifiers  const  may be initialised but not used in any subsequent assignment  common and useful  volatile.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Basic Semantics Associating meaning with language entities.
Semantics of Arrays and Pointers By: M. Reza Heydarian Introduction Pointers Arrays Semantics of Arrays Semantics of Pointers.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
Dynamic Memory Allocation. Domain A subset of the total domain name space. A domain represents a level of the hierarchy in the Domain Name Space, and.
Pointers in C++. 7a-2 Pointers "pointer" is a basic type like int or double value of a pointer variable contains the location, or address in memory, of.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
ISBN Chapter 10 Implementing Subprograms.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
SE424 Languages with Context A Block Structured Language.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
Pointers in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Memory and Addresses Memory is just a sequence of byte-sized.
Review 1 List Data Structure List operations List Implementation Array Linked List.
Pointers *, &, array similarities, functions, sizeof.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
1 First order theories (Chapter 1, Sections 1.4 – 1.5) From the slides for the book “Decision procedures” by D.Kroening and O.Strichman.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Pointers and Dynamic Arrays.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 9 Pointers and Dynamic Arrays.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
1/20 Arrays Changki PSWLAB Arrays Daniel Kroening and Ofer Strichman Decision Procedure.
A FIRST BOOK OF C++ CHAPTER 8 ARRAYS AND POINTERS.
Programming Languages Meeting 3 September 9/10, 2014.
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
You learned how to declare pointer variables how to store the address of a variable into a pointer variable of the same type as the variable how to manipulate.
Computer Organization and Design Pointers, Arrays and Strings in C
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Memory and Addresses Memory is just a sequence of byte-sized storage devices. The bytes are assigned numeric addresses, starting with zero, just like the.
Compiler Construction
Data Structures and Algorithms Introduction to Pointers
A simple function.
Compiler Construction
Presentation transcript:

1/25 Pointer Logic Changki PSWLAB Pointer Logic Daniel Kroening and Ofer Strichman Decision Procedure

2/25 Pointer Logic Changki PSWLAB Why pointer logic?  A pointer is a program variable whose sole purpose is to refer to some other program construct.  Other program construct - variable, procedures, or another pointer  A Pointer is useful but common source of programming errors.  Aliasing  Null pointer dereference error

3/25 Pointer Logic Changki PSWLAB Table of Contents  Introduction  Pointer logic  Modeling Heap-Allocated Data Structures  A Decision Procedure  Conclusion

4/25 Pointer Logic Changki PSWLAB Memory model  The implementation of pointer relies on the fact that the memory cells of a computer have addresses, i.e., each cell has a unique number.  Definition 1. Memory model  A memory model describes the assumptions that are made about the way memory cells are addressed. We assume that the architecture provides a continuous, uniform address space. Each address corresponds to a memory cell that is able to store one data word. A memory valuation M: A  D is a mapping from a set of address A into the domain D of data words.

5/25 Pointer Logic Changki PSWLAB Memory layout  The compiler assigns a particular memory location to each static variable.  The mapping is called memory layout.  Definition 2. Memory layout  A memory layout L: V  A is a mapping from each variable v ∊ V to an address a ∊ A, where V denote the set of variables and A denote the set of addresses.  Memory layout is nonoverlapping which means that the memory locations of the statically allocated variables are distinct.  How about dynamic memory allocation?

6/25 Pointer Logic Changki PSWLAB Dynamic memory allocation  Dynamic data structures are created at the run time of the program.  A runtime library maintains a list of the memory regions that are unused.  A function, which is part of this library, allocates a region of given size and returns a pointer to the beginning of the region. ( malloc(), …)  The memory layout changes during the runtime of the program.  The lifetime of a dynamic object is the time between its allocation and its deallocation.

7/25 Pointer Logic Changki PSWLAB Analysis of programs with pointers  Aliasing  a situation in which a data location in memory can be accessed through different symbolic names in the program.  Modifying the data through one name implicitly modifies the values associated to all aliased names, which is not expected by the programmer.  Dereferencing  a situation which a pointer doesn’t point to a proper object.  Example

8/25 Pointer Logic Changki PSWLAB Table of Contents  Introduction  Pointer logic  Modeling Heap-Allocated Data Structures  A Decision Procedure  Conclusion

9/25 Pointer Logic Changki PSWLAB Syntax  The syntax of a formula in pointer logic is defined by the following rules:  pointer-identifier is of pointer type  identifier is of integers or an array of integers

10/25 Pointer Logic Changki PSWLAB Semantics (1/2)  Define the semantics by referring to  memory layout L  L: V  A is a mapping from each variable v ∊ V to an address a ∊ A  memory valuation M  M: A  D, mapping from a set of address A into the domain D of data words  Pointer logic formulas are predicates on M, L pairs and the definition of semantics uses a reduction to integer arithmetic and array logic.  We treat M and L as array types.

11/25 Pointer Logic Changki PSWLAB Semantics (2/2)  Definition 3. Semantics of pointer logic  Let L P denote the set of pointer logic expressions, and let L D denote the set of expressions permitted by the logic for the data words.  The function [⋅] is defined [⋅] : L P  L D for e ∊ L P. The function [e] is defined recursively. The expression e ∊ L P is valid if and only if [e] is valid.

12/25 Pointer Logic Changki PSWLAB Example  a is an array identifier.  The semantic definition of the expression expands as follows:  Last equation is obviously valid, and thus so is original expression.

13/25 Pointer Logic Changki PSWLAB Table of Contents  Introduction  Pointer logic  Modeling Heap-Allocated Data Structures  A Decision Procedure  Conclusion

14/25 Pointer Logic Changki PSWLAB Lists (1/2)  The simplest dynamically allocated data structure is the linked list.  Structure type  contains fields for a next pointer and the data.  So, How to model linked list in pointer logic formulas?

15/25 Pointer Logic Changki PSWLAB Lists (2/2)  We need to model the field for a next pointer.  Recursive definition  We need to add the property that the last element of the acyclic list should point a NULL.  Add another definition

16/25 Pointer Logic Changki PSWLAB Table of Contents  Introduction  Pointer logic  Modeling Heap-Allocated Data Structures  A Decision Procedure  Conclusion

17/25 Pointer Logic Changki PSWLAB Applying the semantic translation  The semantic translation  assigns meaning to the pointer logic formulas  gives rise to a simple decision procedure  The formula generated by semantic translation contain  array read operator (recall that memory layout L and memory valuation M are considered as array read operation)  linear arithmetic for the index.  equality over the type for modeling the contents of the memory cells  Decision procedure for pointer logic 1. Apply the semantic translation to a pointer formula to obtain a formula in the combined logic of linear arithmetic and array. 2. Pass the formula to the decision procedure for the combined logic.

18/25 Pointer Logic Changki PSWLAB Examples  We want to check validity of following pointer logic formula:  The semantic translation expands as follows:  A decision procedure for array logic and equality logic easily concludes that the formula above is valid.

19/25 Pointer Logic Changki PSWLAB Pure variables (1/2)  Sometimes the semantic translation can place an undue burden on the underlying decision procedure, as illustrated by the following example:  A decision procedure for array logic and equality logic is certainly able to deduce that the original formula is valid.  Therefore, the semantic translation process is not required in this kind of situation.

20/25 Pointer Logic Changki PSWLAB  Definition 4. Pure variables  Given a formula with a set of variables V, let denote the subset of ’s variables that are not used within an argument of the “ & ” operator within. These variables are called pure.  Definition 5. [∙] P  A new translation function [e] P is identical to the definition [e] unless e denotes a variable. The new definition is: Pure variables (2/2)

21/25 Pointer Logic Changki PSWLAB Example  This no longer burdens the decision procedure for array logic:

22/25 Pointer Logic Changki PSWLAB Reachability predicate (1/2)  Definition 6.  This stands for the pointer that is obtained by starting from q and following the field f, n times:  Definition 7. reachability predicate,  We call a predicate as reachability predicate which satisfies following two conditions:  There exists some n such that q is reachable from p by following f for n times.  x is not reachable in fewer than n steps from p following f. 

23/25 Pointer Logic Changki PSWLAB Reachability predicate (2/2)  We say that a formula is a reachability predicate formula if it contains the reachability predicate.  Reachability predicate formulas often have quantifiers, which make decision problems much harder.  There is no automatic decision procedure for a logic that includes a reachability predicate.

24/25 Pointer Logic Changki PSWLAB Table of Contents  Introduction  Pointer logic  Modeling Heap-Allocated Data Structures  A Decision Procedure  Conclusion

25/25 Pointer Logic Changki PSWLAB Conclusion  The semantic translation not only assigns meaning to the pointer logic formulas, but also gives rise to a simple decision procedure.  Deciding pointer logic including reachability predicate is still an open problem.