pointer analysis
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, pointer analysis, or points-to analysis, is a
static code analysis In computer science, static program analysis (or static analysis) is the analysis of computer programs performed without executing them, in contrast with dynamic program analysis, which is performed on programs during their execution. The term i ...
technique that establishes which pointers, or heap references, can point to which variables, or storage locations. It is often a component of more complex analyses such as
escape analysis In compiler optimization, escape analysis is a method for determining the dynamic scope of pointers where in the program a pointer can be accessed. It is related to pointer analysis and shape analysis. When a variable (or an object) is allocate ...
. A closely related technique is shape analysis. This is the most common colloquial use of the term. A secondary use has ''pointer analysis'' be the collective name for both ''points-to analysis'', defined as above, and
alias analysis Alias may refer to: * Pseudonym * Pen name * Nickname Arts and entertainment Film and television * ''Alias'' (2013 film), a 2013 Canadian documentary film * ''Alias'' (TV series), an American action thriller series 2001–2006 * ''Alias the ...
. Points-to and alias analysis are closely related but not always equivalent problems.


Example

For the following example program, a points-to analysis would compute that the points-to set of p is . int x; int y; int* p = unknown() ? &x : &y;


Introduction

As a form of static analysis, fully precise pointer analysis can be shown to be undecidable. Most approaches are
sound In physics, sound is a vibration that propagates as an acoustic wave, through a transmission medium such as a gas, liquid or solid. In human physiology and psychology, sound is the ''reception'' of such waves and their ''perception'' by the ...
, but range widely in performance and precision. Many design decisions impact both the precision and performance of an analysis; often (but not always) lower precision yields higher performance. These choices include: * ''Field sensitivity'' (also known as ''structure sensitivity''): An analysis can either treat each field of a
struct In computer science, a record (also called a structure, struct, or compound data) is a basic data structure. Records in a database or spreadsheet are usually called "rows". A record is a collection of '' fields'', possibly of different data typ ...
or
object Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an ...
separately, or merge them. * ''Array sensitivity'': An array-sensitive pointer analysis models each index in an array separately. Other choices include modelling just the first entry separately and the rest together, or merging all array entries. * ''Context sensitivity'' or ''
polyvariance In program analysis, polyvariance is an analysis in which functions are analyzed multiple times—typically once at each call site In programming, a spot of a function or subroutine is the location (line of code) where the function is called ...
'': Pointer analyses may qualify points-to information with a summary of the control flow leading to each program point. * ''Flow sensitivity'': An analysis can model the impact of intraprocedural control flow on points-to facts. * ''Heap modeling'': Run-time allocations may be abstracted by: ** their allocation sites (the statement or instruction that performs the allocation, e.g., a call to malloc or an object constructor), ** a more complex model based on a shape analysis, ** the type of the allocation, or ** one single allocation (this is called ''heap-insensitivity''). * ''Heap cloning'': Heap- and context-sensitive analyses may further qualify each allocation site by a summary of the control flow leading to the instruction or statement performing the allocation. * ''Subset constraints'' or ''equality constraints'': When propagating points-to facts, different program statements may induce different constraints on a variable's points-to sets. Equality constraints (like those used in Steensgaard's algorithm) can be tracked with a
union-find data structure In computer science, a disjoint-set data structure, also called a union–find data structure or merge–find set, is a data structure that stores a collection of disjoint (non-overlapping) sets. Equivalently, it stores a partition of a se ...
, leading to high performance at the expense of the precision of a subset-constraint based analysis (e.g., Andersen's algorithm).


Context-Insensitive, Flow-Insensitive Algorithms

Pointer analysis algorithms are used to convert collected raw pointer usages (assignments of one pointer to another or assigning a pointer to point to another one) to a useful graph of what each pointer can point to. Steensgaard's algorithm and Andersen's algorithm are common context-insensitive, flow-insensitive algorithms for pointer analysis. They are often used in compilers, and have implementations in the
LLVM LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate represen ...
codebase.


Flow-Insensitive Approaches

Many approaches to flow-insensitive pointer analysis can be understood as forms of
abstract interpretation In computer science, abstract interpretation is a theory of sound approximation of the semantics of computer programs, based on monotonic functions over ordered sets, especially lattices. It can be viewed as a partial execution of a computer prog ...
, where heap allocations are abstracted by their allocation site (i.e., a program location). Many flow-insensitive algorithms are specified in
Datalog Datalog is a declarative logic programming language. While it is syntactically a subset of Prolog, Datalog generally uses a bottom-up rather than top-down evaluation model. This difference yields significantly different behavior and properties ...
, including those in the Soot analysis framework for Java. Context-sensitive, flow-insensitive algorithms achieve higher precision, generally at the cost of some performance, by analyzing each procedure several times, once per ''context''. Most analyses use a "context-string" approach, where contexts consist of a list of entries (common choices of context entry include call sites, allocation sites, and types). To ensure termination (and more generally, scalability), such analyses generally use a ''k''-limiting approach, where the context has a fixed maximum size, and the least recently added elements are removed as needed. Three common variants of context-sensitive, flow-insensitive analysis are: * Call-site sensitivity * Object sensitivity * Type sensitivity


Call-site sensitivity

In call-site sensitivity, the points-to set of each variable (the set of abstract heap allocations each variable could point to) is further qualified by a context consisting of a list of callsites in the program. These contexts abstract the control-flow of the program. The following program demonstrates how call-site sensitivity can achieve higher precision than a flow-insensitive, context-insensitive analysis. int *id(int* x) int main() For this program, a context-insensitive analysis would (soundly but imprecisely) conclude that can point to either the allocation holding or that of , so and may alias, and both could point to either allocation. A callsite-sensitive analysis would analyze twice, once for call-site 1 and once for call-site 2, and the points-to facts for would be qualified by the call-site, enabling the analysis to deduce that when returns, can only point to the allocation holding and can only point to the allocation holding .


Object sensitivity

In an object sensitive analysis, the points-to set of each variable is qualified by the abstract heap allocation of the receiver object of the method call. Unlike call-site sensitivity, object-sensitivity is ''non-syntactic'' or ''non-local'': the context entries are derived during the points-to analysis itself.


Type sensitivity

Type sensitivity is a variant of object sensitivity where the allocation site of the receiver object is replaced by the class/type containing the method containing the allocation site of the receiver object. This results in strictly fewer contexts than would be used in an object-sensitive analysis, which generally means better performance.


References


Bibliography

* * * * * * {{Compiler optimizations Static program analysis