Detecting Type-Based Alias Analysis Violations in C Iain Ireland (University of Alberta) Jose Nelson Amaral (University of Alberta) Raul Silvera (IBM Canada)

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Rational XL C/C++ Compiler Development © 2007 IBM Corporation Identifying Aliasing Violations in Source Code A Points-to Analysis Approach Ettore Tiotto,
Variables Names Bindings Type Scope. L-Value versus R-Value Not complicated Associated with assignment statements Left hand side represents an address.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
© 2002 IBM Corporation IBM Toronto Software Lab October 6, 2004 | CASCON2004 Interprocedural Strength Reduction Shimin Cui Roch Archambault Raul Silvera.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 3: Objects, Types, and Values 1 Based on slides.
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
Parameter Passing Mechanisms Reference Parameters Read § §
Parameter Passing Mechanisms Reference Parameters § §
CSC 107 – Programming For Science. The Week’s Goal.
These notes were originally developed for CpSc 210 (C version) by Dr. Mike Westall in the Department of Computer Science at Clemson.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Using Types to Analyze and Optimize Object-Oriented Programs By: Amer Diwan Presented By: Jess Martin, Noah Wallace, and Will von Rosenberg.
Names, Scope, and Bindings Programming Languages and Paradigms.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Lecture 1 Data Structures Aamir Zia. Introduction Course outline Rules and regulations Course contents Good Programming Practices Data Types and Data.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Object Lifetime and Pointers
Buffer Overflow By Collin Donaldson.
Chapter # 2 Part 2 Programs And data
A History Lesson Adapted from Chapter 1 in C++ for Java Programmers by Weiss and C for Java Programmers: a Primer by McDowell Development of language by.
Functions Students should understand the concept and basic mechanics of the function call/return pattern from CS 1114/2114, but some will not. A function.
Data Types In Text: Chapter 6.
The Machine Model Memory
Introduction to the C Language
Arrays Low level collections.
Templates.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
The Three Attributes of an Identifier
Objectives Identify the built-in data types in C++
CSE 374 Programming Concepts & Tools
C Basics.
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.
Programmazione I a.a. 2017/2018.
Dynamic Memory Allocation
Pointers and References
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Introduction to the C Language
C Structures, Unions, Bit Manipulations and Enumerations
Starting JavaProgramming
CSCE 121- Spring 2016 J. Michael Moore
Data.
Introduction to CS Your First C Programs
A History Lesson Adapted from Chapter 1 in C++ for Java Programmers by Weiss and C for Java Programmers: a Primer by McDowell Development of language by.
Programming in C Pointer Basics.
Pointer to Structures Lesson xx
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Tim Ehrlich Growing Arrays in C.
Introduction to Programming
Programming in C Pointer Basics.
CS 363 – Chapter 7 Chapter 7 – type systems Types that are supported
Homework Starting K&R Chapter 5 Good tutorial on pointers
UNIT V Run Time Environments.
Pointers Pointers point to memory locations
Pass-by-Pointer Pointers are also used in C to enable a function to modify a variable held by the caller: void findExtrema(const int *pA, int Sz, int *pMin,
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
Type compatibility and pointer operation
The C Language: Intro.
Quiz Points 1 Rules Raise your hand if you know the question
Setting up a basic program with Arduino
Testing & Security Dr. X.
Pointers and pointer applications
Variables and Constants
SPL – PS2 C++ Memory Handling.
Introduction to Classes and Objects
Presentation transcript:

Detecting Type-Based Alias Analysis Violations in C Iain Ireland (University of Alberta) Jose Nelson Amaral (University of Alberta) Raul Silvera (IBM Canada) Shimin Cui (IBM Canada)

Contents Background Analysis Future Work

Use programming language types to rule out potential aliases: Type-Based Alias Analysis int * double * ?

History Amer Diwan, Kathryn S. McKinley, and J. Eliot B. Moss 'Type-based alias analysis' August G. Reinig 'Alias Analysis in the DEC C and Digital C++ Compilers' Rakesh Ghiya, Daniel Lavery, and David Sehr 'On the importance of points-to analysis and other memory disambiguation methods for C programs'

Status Quo General adoption: Compiler support: gcc XL C/C++ Clang (as of April 2011) C standard So what's the problem?

The C Standard

The Problem Lots of code violates the standard TBAA on non-compliant programs is unsafe "Solution": turn off TBAA

The Problem Can we do better?

The Problem Problem: Identify points in a program where memory objects may be accessed in a way which violates the restrictions in the C standard.

6.5: [...] 7. An object shall have its stored value accessed only by an lvalue expression that has one of the following types: — a type compatible with the effective type of the object, — a qualified version of a type compatible with the effective type of the object, — a type that is the signed or unsigned type corresponding to the effective type of the object, — a type that is the signed or unsigned type corresponding to a qualified version of the effective type of the object, — an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or — a character type. The C Standard: Valid Accesses Case 2: There is structural aliasing. Case 3: The access is through a character type. Case 1: The types are the same, ignoring qualifiers and signedness. (The type of the lvalue, and the effective type of the accessed object)

6.5: [...] 6. The effective type of an object for an access to its stored value is the declared type of the object, if any. (Allocated objects have no declared type.) If a value is stored into an object having no declared type through an lvalue having a type that is not a character type, then the type of the lvalue becomes the effective type of the object for that access and for subsequent accesses that do not modify the stored value. If a value is copied into an object having no declared type using memcpy or memmove, or is copied as an array of character type, then the effective type of the modified object for that access and for subsequent accesses that do not modify the value is the effective type of the object from which the value is copied, if it has one. For all other accesses to an object having no declared type, the effective type of the object is simply the type of the lvalue used for the access. The C Standard: Effective Types Case 1: The object has a declared type. The effective type is the same. Case 2: The object has no declared type. Use the type of the last store. Case 3: memcpy, memmove, and char arrays: type of the copied object Case 4: Otherwise, type of the lvalue used for the access

High Level Reasoning Everything starts safe. If every statement preserves safety, then everything stays safe. Approach: find the statements that do not preserve safety.

Analysis implementation in XL C compiler pass over the intermediate representation on-demand flow sensitivity requires points-to analysis can't use TBAA

Example int *ip = […]; double *dp = […]; ip = (int *) dp; for (…) *dp += (double) *ip;

Example int i, *ip; double d, *dp; void *vp; ip = &i; vp = ip; dp = &d; for (…) ip = (int *) vp; *ip += 1; vp = dp; dp = (double *) vp; *dp += 1.0; Prev {}{double}{int}{int,double}

Future Work Interprocedural analysis Automatic adjustment

Conclusion TBAA is not safe on arbitrary C code We can detect points where it becomes unsafe Long run: a safer TBAA

Thanks.