In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
, aliasing describes a situation in which a data location in
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
can be accessed through different symbolic names in the program. Thus, modifying the data through one name implicitly modifies the values associated with all aliased names, which may not be expected by the programmer. As a result, aliasing makes it particularly difficult to understand, analyze and optimize programs.
Aliasing analysers intend to make and compute useful information for understanding aliasing in programs.
Aliased pointers
Aliasing can occur in any language that can refer to one location in memory with more than one name (for example, with
pointers
Pointer may refer to:
People with the name
* Pointer (surname), a surname (including a list of people with the name)
* Pointer Williams (born 1974), American former basketball player
Arts, entertainment, and media
* ''Pointer'' (journal), the ...
). This is a common problem with functions that accept pointer arguments, and their tolerance (or the lack thereof) for aliasing must be carefully documented, particularly for functions that perform complex manipulations on memory areas passed to them.
Specified aliasing
Controlled aliasing behaviour may be desirable in some cases (that is, aliasing behaviour that is specified, unlike that enabled by memory layout in C). It is common practice in
Fortran. The
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".
Perl was developed ...
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
specifies, in some constructs, aliasing behaviour, such as in loops. This allows certain data structures to be modified directly with less code. For example,
my @array = (1, 2, 3);
foreach my $element (@array)
print "@array \n";
will print out "2 3 4" as a result. If one wanted to bypass aliasing effects, one could copy the contents of the index variable into another and change the copy.
Conflicts with optimization
Optimizers often have to make conservative assumptions about variables when aliasing is possible. For example, knowing the value of a variable (such as
x
is 5) normally allows certain optimizations (such as
constant propagation). However, the compiler cannot use this information after an assignment to another variable (for example, in C,
*y = 10
) because it could be that
*y
is an alias of
x
. This could be the case after an assignment like
y = &x
. As an effect of this assignment to
*y
, the value of
x
would be changed as well, so propagating the information that
x
is 5 to the statements following
*y = 10
would be potentially wrong (if
*y
is indeed an alias of
x
). However, if there is information about pointers, the constant propagation process could make a query like: can
x
be an alias of
*y
? Then, if the answer is no,
x = 5
can be propagated safely.
Another optimization impacted by aliasing is code reordering. If the compiler decides that
x
is not aliased by
*y
, then code that uses or changes the value of
x
can be moved before the assignment
*y = 10
, if this would improve
scheduling
A schedule (, ) or a timetable, as a basic time-management tool, consists of a list of times at which possible tasks, events, or actions are intended to take place, or of a sequence of events in the chronological order in which such things ...
or enable more
loop optimization
In compiler theory, loop optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capa ...
s to be carried out.
To enable such optimizations in a predictable manner,
the ISO standard for the
C programming language
C (''pronounced'' '' – like the letter c'') is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of ...
(including its newer
C99 edition, see section 6.5, paragraph 7) specifies that it is illegal (with some exceptions) to access the same memory location using pointers of different types. A compiler may therefore assume that such pointers do not alias. This rule, known as the strict aliasing rule, sometimes allows for impressive increases in performance, but has been known to break some otherwise valid code. Several software projects intentionally violate this portion of the C99 standard. For example,
Python 2.x did so to implement
reference counting
In computer science, reference counting is a programming technique of storing the number of references, pointers, or handles to a resource, such as an object, a block of memory, disk space, and others.
In garbage collection algorithms, refere ...
, and required changes to the basic object structs in Python 3 to enable this optimization. The
Linux kernel
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
does this because strict aliasing causes problems with optimization of inlined code. In such cases, when compiled with
gcc, the option
-fno-strict-aliasing
is invoked to prevent unwanted optimizations that could yield unexpected code.
Hardware aliasing
The term ''aliasing'' is also used to describe the situation where, due to either a hardware design choice or a hardware failure, one or more of the available address bits is not used in the memory selection process.
This may be a design decision if there are more address bits available than are necessary to support the installed memory device(s). In a failure, one or more address bits may be shorted together, or may be forced to
ground (logic 0) or the supply voltage (logic 1).
;Example
For this example, assuming a memory design with 8 locations, requiring only 3 address lines (or
bit
The bit is the most basic unit of information in computing and digital communication. The name is a portmanteau of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represented as ...
s, since 2
3 = 8). Address bits (named A2 through A0) are decoded to select unique memory locations as follows, in standard
binary counter fashion:
In the table above, each of the 8 unique combinations of address bits selects a different memory location. However, if one address bit (say A2) were to be shorted to ground, the table would be modified as follows:
In this case, with A2 always being zero, the first four memory locations are duplicated and appear again as the second four. Memory locations 4 through 7 have become inaccessible.
If this change occurred to a different address bit, the decoding results would be different, but in general the effect would be the same: the loss of a single address bit cuts the available memory space in half, with resulting duplication (aliasing) of the remaining space.
See also
*
Anti-aliasing Anti-aliasing may refer to any of a number of techniques to combat the problems of aliasing in a sampled signal such as a digital image or digital audio recording.
Specific topics in anti-aliasing include:
* Anti-aliasing filter, a filter used b ...
*
Aliasing
In signal processing and related disciplines, aliasing is a phenomenon that a reconstructed signal from samples of the original signal contains low frequency components that are not present in the original one. This is caused when, in the ori ...
for uses of the word when applied to signal processing, including computer graphics
References
{{reflist
External links
Aliasing, pointer casts and gcc 3.3– informational article on NetBSD mailing list
Type-based alias analysis in C++– Informational article on type-based alias analysis in C++
– article on strict aliasing originally from the boost developer's wiki
Compiler construction
Program analysis
Articles with example Perl code