C. M. Overstreet Old Dominion University Fall 2005

Slides:



Advertisements
Similar presentations
Chair of Software Engineering From Program slicing to Abstract Interpretation Dr. Manuel Oriol.
Advertisements

Basic Control Structures Control order of execution of statements sequential selection iteration - Repeat some action while a certain condition is true.
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.
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Computer programming1 Arrays. Computer programming2 ARRAYS Motivation Introduction to Arrays Static arrays Arrays and Functions Arrays, Classes, and typedef.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
Smoking is prohibited 1 CS 101 Second Exam Review Prepared by Dr. Amer Al-Badarneh 
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
CSC 221: Computer Programming I Fall 2001  top-down design  approach to problem solving, program design  focus on tasks, subtasks, …  reference parameters.
CSE1222: Lecture 6The Ohio State University1. Common Mistakes with Conditions (1)  Consider the following code: int age(26); if (age = 18) { cout
CPS120: Introduction to Computer Science Functions.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 6 Looping CS185/09 - Introduction to Programming Caldwell College.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 4 Pointers and Dynamic Arrays Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
CS101 Computer Programming I Chapter 4 Extra Examples.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
Overview Go over parts of quiz? Another iteration structure for loop.
CS 0401 Debugging Hints and Programming Quirks for Java by John C. Ramirez University of Pittsburgh.
User-Defined Functions II TK1914: C++ Programming.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Fundamental Programming Fundamental Programming More on Repetition.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
C++ Programming Lecture 12 Functions – Part IV
C++ Programming: CS102 LOOP. Not everything that can be counted counts, and not every thing that counts can be counted. −Albert Einstein Who can control.
01/05/100 1 Loops/Iteration Used to repeat an action Must have a STOP condition Three flavors - for, while, do/while.
Loop Design What goes into coding a loop. Considerations for Loop Design ● There are basically two kinds of loops: ● Those that form some accumulated.
Copyright © 2016 Curt Hill Static Code Analysis What it is and does.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Object Lifetime and Pointers
EGR 2261 Unit 11 Pointers and Dynamic Variables
Static Code Analysis What it is and does. Copyright © 2016 Curt Hill.
REPETITION CONTROL STRUCTURE
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Recursion A problem solving technique where an algorithm is defined in terms of itself A recursive method is a method that calls itself A recursive algorithm.
Computing and Statistical Data Analysis Lecture 2
CS161 Introduction to Computer Science
CSE 311 Foundations of Computing I
Control Structures II (Repetition)
SwE 455 Program Slicing.
User-defined Functions
CS149D Elements of Computer Science
Iteration with While You can say that again.
User-defined Functions
Recursion Data Structures.
Let’s all Repeat Together
Object-Oriented Programming (OOP) Lecture No. 43
Dynamic Memory.
C. M. Overstreet Old Dominion University Spring 2006
Multiple Files Revisited
CS149D Elements of Computer Science
Impossible problems.
Repetition Statements (Loops) - 2
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
CS31 Discussion 1D Winter19: week 4
CSE 373: Data Structures and Algorithms
Recursion.
C. M. Overstreet Old Dominion University Fall 2007
Lecture 3 More on Flow Control, More on Functions,
Presentation transcript:

C. M. Overstreet Old Dominion University Fall 2005 CS 110: Code Analysis C. M. Overstreet Old Dominion University Fall 2005

Overview Some motivation for code analysis Some examples: some easy, some hard, some impossible Some examples of where used 1/10/05

Example 1: elimination of infinite loops Infinite loops are usually undesirable. But not always. Why? Can you write a program that checks another program for infinite loops? That works all of the time? Initial idea: just consider while loops: Check loop body to see if any action modifies some loop control variables. Does this work? If no change, is loop infinite? Can one always do this? How? What about input data? What about for loops? 1/10/05

Example 1 (cont.) Point: often partial solutions are useful even if a general solution does not exist. Question: What is the Halting Problem and why is it important? 1/10/05

Static & Dynamic Analysis From their beginning, compilers have tried to optimize code. Done by primarily by static analysis Figure things out by analyzing source code Many types of useful information about code itself can only be obtained by running to code and monitoring its behaviors. This is dynamic analysis 1/10/05

Possible Common Compiler Optimizations Flag unused variables Very common Make loops more efficient by moving code around Eliminating code that cannot affect program output Not done; too hard! Worked on a project for Navy a few years ago in which program manager suspected ~80% of code was useless About 1,000,000 lines of source code 1/10/05

Examples of analysis tools gcov: Tool to identify which statements have been executed while testing a program gprof: Tool to tell a programmer which parts of a program use the most execution time. Useful when improving program speed. What are memory leaks? 1/10/05

Example 3: uninitialized variables Uninitialized variables are usually undesirable. Should compilers make them illegal? Can compilers make them illegal? Can you write a program which detects uninitialized variables? Always? Sometimes? Using static analysis? i.e., uninitialized vars detected at compile time Using dynamic analysis? i.e. uninitialized vars detected at run time 1/10/05

Another example: side effects of function calls Consider the statement: x = f(a,b) + a + g(a,c); Considered to be a dangerous statement. "Careful" programmers avoid this type of coding. Why? 1/10/05

Weiser: Program Slices slice criterion: <13, {z}> 1, 2, 3, 6, 8, 9, 11, 13 slice criterion: <10, {x}> 1, 2, 3, 13 slice criterion: <13, {total}> 1, 2, 3, 4, 6, 8, 10, 11, 13 1 void main() 2 { int x, y, total, sum, z; 3 cin >> x >> y; 4 total = 0.0; 5 sum = 0.0; 6 if ( x < 1 ) 7 sum = y; 8 else { 9 cin >> z; 10 total = x*y; 11 } 12 cout << total << sum << endl; 13 } 1/10/05