26.8.2004 Model Checking C++ Daniel Kroening. 26.8.2004 Daniel Kroening 2 Warning! No new research in this talk Talk is about doing existing stuff for.

Slides:



Advertisements
Similar presentations
CH4.1 Type Checking Md. Fahim Computer Engineering Department Jamia Millia Islamia (A Central University) New Delhi –
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
CPSC 388 – Compiler Design and Construction
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Semantics Static semantics Dynamic semantics attribute grammars
Intermediate Code Generation
Programming Languages and Paradigms
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Compiler construction in4020 – lecture 10 Koen Langendoen Delft University of Technology The Netherlands.
C++ Programming Languages
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
Symmetry-Aware Predicate Abstraction for Shared-Variable Concurrent Programs Alastair Donaldson, Alexander Kaiser, Daniel Kroening, and Thomas Wahl Computer.
Compiler Construction
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Encapsulation by Subprograms and Type Definitions
Predicate Abstraction for Software and Hardware Verification Himanshu Jain Model checking seminar April 22, 2005.
Context-sensitive Analysis, II Ad-hoc syntax-directed translation, Symbol Tables, andTypes.
Utah Verifier Group Research Overview Robert Palmer.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
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.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Formal Verification of SpecC Programs using Predicate Abstraction Himanshu Jain Daniel Kroening Edmund Clarke Carnegie Mellon University.
Templates. Example… A useful routine to have is void swap(int &a, int &b){ int tmp = a; a = b; b = tmp; }
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
CS 363 Comparative Programming Languages Semantics.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
An Undergraduate Course on Software Bug Detection Tools and Techniques Eric Larson Seattle University March 3, 2006.
Chapter 1 Introduction Major Data Structures in Compiler
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
R-Verify: Deep Checking of Embedded Code James Ezick † Donald Nguyen † Richard Lethin † Rick Pancoast* (†) Reservoir Labs (*) Lockheed Martin The Eleventh.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
Language Implementation Overview John Keyser Spring 2016.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Lecture 9 Symbol Table and Attributed Grammars
The architecture of the P416 compiler
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2017.
Names and Attributes Names are a key programming language feature
Constructing Precedence Table
Semantic Analysis with Emphasis on Name Analysis
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018.
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Over-Approximating Boolean Programs with Unbounded Thread Creation
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2016.
Overview of C++ Polymorphism
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2017.
Compiler Construction
Advanced Compiler Design
Predicate Abstraction
Review: What is an activation record?
Compiler Construction
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Spring 2019.
Presentation transcript:

Model Checking C++ Daniel Kroening

Daniel Kroening 2 Warning! No new research in this talk Talk is about doing existing stuff for different language only You might consider this trivial and nod off  !

Daniel Kroening 3 Example from NASA JPL class RCPNAM{ public: RCPNAM(); //!< DND for STRICT protocol. ~RCPNAM(); //!< Decr cntr, delete if zero. RCPNAM(RCPNOD* p); //!< New ptr at given object. RCPNOD* operator->(); RCPNOD& operator*(); RCPNAM(const RCPNAM& rhs); //!< Copy of existing RCPNAM. […] RCPNAM& operator=(const RCPNAM& rhs); //!< Assign to existing RCPNAM. int nullp(){return ref_ == 0;}; //!< DND for STRICT. […] public: RCPNOD* ref_; static RCPNOD* copyAndInc(const RCPNOD*const* p,int RCPNOD::*cntr); };

Daniel Kroening 4 Example from NASA JPL Want to verify the code that goes into space Container class with reference counting Concurrent Mostly low-level, performance-oriented C and C++ Uses assembly-language constructs for atomic accesses to pointers and counters

Daniel Kroening 5 Example from NASA JPL Verification:  Extensive testing  SPIN failed Main challenge: pointers and references How many threads are enough?

Daniel Kroening 6 Outline 1.Frontend What’s so hard about C++? Parsing, Type Checking STL 2.Backend Verification Backends Dynamic Objects

Daniel Kroening 7 What’s so hard about C++ ? Existing model checkers: compile, and work on binary Infrastructure is difficult  Parsing is complicated (LR k )  Complex name resolution rules (namespaces, templates, class hierarchy, overloading) But: there are tools that flatten C++ to C

Daniel Kroening 8 Why C++? Main advantage of C++: Encapsulation of complex data structures in template libraries Also main challenge when model checking C++

Daniel Kroening 9 What’s so hard about C++ ? What kind of C++ are we going to see?  Heavy use of references and pointers  Class/Module hierarchy  Overloading  Templates  new / delete

Daniel Kroening 10 Model Extraction for C++ Parser Type Checker CFG-Generator Backend... Frontend

Daniel Kroening 11 Type Checker  Parse tree to symbol table  Both represented as DAGs  Algorithm: 1. Expand templates 2. Resolve overloading 3. Class hierarchy 4. Annotate each sub-expression with type

Daniel Kroening 12 Type Checker cpp::f(9_reference(7_subtype=8_signedbv(5_width=2_32))) type: code * arguments: 0: argument * type: reference * subtype: signedbv * width: 32 * return_type: empty value: code * statement: block * type: code * arguments: 0: argument * type: reference * subtype: signedbv * width: 32 * return_type: empty void f(int &r) { }

Daniel Kroening 13 Control Flow Graph Symbol table to Control Flow Graph (CFG)  Essentially a guarded GOTO program, but with direct function calls  virtual methods and virtual classes and function pointers require alias analysis

Daniel Kroening 14 Alias Analysis For  References  Pointers  virtual tables Fixed-point iteration on the CFG  Interleaved with the computation of the CFG Control flow sensitive (concurrency!) Field sensitive

Daniel Kroening 15 Alias Analysis int var; void f() { var=1; } void g() { var=2; } int main() { bool c; void (*p)()=c?f:g; (*p)(); } MAIN: INIT var = 0; main() cpp::main(): p = c ? f() : g(); (*p)(); cpp::main()::1::p = { &f, &g }

Daniel Kroening 16 Alias Analysis int var; void f() { var=1; } void g() { var=2; } int main() { bool c; void (*p)()=c?f:g; (*p)(); } MAIN: INIT var = 0; main(); cpp::f(): var = 1; cpp::g(): var = 2; cpp::main(): p = c ? f : g; IF p != &g THEN GOTO 1 g(); GOTO 2 1: f(); 2: SKIP

Daniel Kroening 17 STL Standard Template Library Encapsulates complex data structures and algorithms typedef std::hash_map symbolst;... typedef std::vector nodest;

Daniel Kroening 18 STL “Interesting” programs using STL have > 1000 data structures Flatten to C?  STL implementation highly complex and optimized  Don’t want to verify STL together with program Let’s assume STL is correct

Daniel Kroening 19 Model Extraction for C++ Parser Type Checker CFG-Generator Backend... Frontend

Daniel Kroening 20 Model Extraction with the STL Parser Type Checker CFG-Generator Backend... Frontend Inject modifications of class definitions

Daniel Kroening 21 Abstract STL Manually written abstractions of common STL data types  std::vector  std::list  std::set  std::map Catch errors when using STL Catch errors in program that depend on data in containers

Daniel Kroening 22 STL typedef std::vector T; T v; v.push_back(…); v.reserve(2); T::const_iterator it=v.begin(); x=*it; v.push_back(…); x=*it; 

Daniel Kroening 23 Predicate Abstraction Predicate Abstraction is a successful method to verify programs C/C++ Program with threads Concurrent Boolean Program Model Checker Verification Initial Abstraction No error or bug found Simulator Property holds Simulation successful Bug found Refinement

Daniel Kroening 24 Dynamic Objects C++ code tends to make excessive use of dynamic objects Algorithm:  Allow * and & in predicates, including pointer arithmetic  New: also have quantifiers 8, 9  Maintain active bit  (o) and object size state variables  Flow control-sensitive points-to analysis

Daniel Kroening 25 Dynamic Objects struct s { s *n; int i; } *p;... p=new s; p->n=new s; p->n->i=p->i+1;  (* p )  (* p ),  (*( p -> n )) p -> n -> i = p -> i+1 Postconditions   (* p )  (* p ),  (*( p -> n )) Preconditions

Daniel Kroening 26 Questions?