<s>
In	O
computing	O
,	O
aliasing	B-Error_Name
describes	O
a	O
situation	O
in	O
which	O
a	O
data	O
location	O
in	O
memory	B-General_Concept
can	O
be	O
accessed	O
through	O
different	O
symbolic	O
names	O
in	O
the	O
program	O
.	O
</s>
<s>
As	O
a	O
result	O
,	O
aliasing	B-Error_Name
makes	O
it	O
particularly	O
difficult	O
to	O
understand	O
,	O
analyze	O
and	O
optimize	O
programs	O
.	O
</s>
<s>
Aliasing	B-Error_Name
analysers	O
intend	O
to	O
make	O
and	O
compute	O
useful	O
information	O
for	O
understanding	O
aliasing	B-Error_Name
in	O
programs	O
.	O
</s>
<s>
For	O
example	O
,	O
most	O
implementations	O
of	O
the	O
C	B-Language
programming	I-Language
language	I-Language
do	O
not	O
perform	O
array	B-Data_Structure
bounds	I-Data_Structure
checking	I-Data_Structure
.	O
</s>
<s>
One	O
can	O
then	O
exploit	O
the	O
implementation	O
of	O
the	O
programming	O
language	O
by	O
the	O
compiler	O
and	O
the	O
computer	O
architecture	O
's	O
assembly	B-Language
language	I-Language
conventions	O
,	O
to	O
achieve	O
aliasing	B-Error_Name
effects	O
by	O
writing	O
outside	O
of	O
the	O
array	B-Data_Structure
(	O
a	O
type	O
of	O
buffer	B-General_Concept
overflow	I-General_Concept
)	O
.	O
</s>
<s>
This	O
invokes	O
undefined	B-Language
behaviour	I-Language
according	O
to	O
the	O
C	B-Language
language	I-Language
specification	O
;	O
however	O
many	O
implementations	O
of	O
C	B-Language
will	O
show	O
the	O
aliasing	B-Error_Name
effects	O
described	O
here	O
.	O
</s>
<s>
If	O
an	O
array	B-Data_Structure
is	O
created	O
on	O
the	O
stack	B-General_Concept
,	O
with	O
a	O
variable	O
laid	O
out	O
in	O
memory	B-General_Concept
directly	O
beside	O
that	O
array	B-Data_Structure
,	O
one	O
could	O
index	O
outside	O
the	O
array	B-Data_Structure
and	O
directly	O
change	O
the	O
variable	O
by	O
changing	O
the	O
relevant	O
array	B-Data_Structure
element	I-Data_Structure
.	O
</s>
<s>
For	O
example	O
,	O
if	O
there	O
is	O
an	O
array	B-Data_Structure
of	O
size	O
2	O
(	O
for	O
this	O
example	O
's	O
sake	O
,	O
calling	O
it	O
)	O
,	O
next	O
to	O
another	O
variable	O
(	O
call	O
it	O
)	O
,	O
(	O
i.e.	O
,	O
the	O
3rd	O
element	O
)	O
would	O
be	O
aliased	O
to	O
if	O
they	O
are	O
adjacent	O
in	O
memory	B-General_Concept
.	O
</s>
<s>
This	O
is	O
possible	O
in	O
some	O
implementations	O
of	O
C	B-Language
because	O
an	O
array	B-Data_Structure
is	O
a	O
block	O
of	O
contiguous	O
memory	B-General_Concept
,	O
and	O
array	B-Data_Structure
elements	I-Data_Structure
are	O
merely	O
referenced	O
by	O
offsets	O
off	O
the	O
address	O
of	O
the	O
beginning	O
of	O
that	O
block	O
multiplied	O
by	O
the	O
size	O
of	O
a	O
single	O
element	O
.	O
</s>
<s>
Since	O
C	B-Language
has	O
no	O
bounds	B-Data_Structure
checking	I-Data_Structure
,	O
indexing	O
and	O
addressing	O
outside	O
of	O
the	O
array	B-Data_Structure
is	O
possible	O
.	O
</s>
<s>
Note	O
that	O
the	O
aforementioned	O
aliasing	B-Error_Name
behaviour	O
is	O
undefined	B-Language
behaviour	I-Language
.	O
</s>
<s>
Some	O
implementations	O
may	O
leave	O
space	O
between	O
arrays	O
and	O
variables	O
on	O
the	O
stack	B-General_Concept
,	O
for	O
instance	O
,	O
to	O
align	O
variables	O
to	O
memory	B-General_Concept
locations	O
that	O
are	O
a	O
multiple	O
of	O
the	O
architecture	O
's	O
native	O
word	O
size	O
.	O
</s>
<s>
The	O
C	B-Language
standard	O
does	O
not	O
generally	O
specify	O
how	O
data	O
is	O
to	O
be	O
laid	O
out	O
in	O
memory	B-General_Concept
.	O
</s>
<s>
It	O
is	O
not	O
erroneous	O
for	O
a	O
compiler	O
to	O
omit	O
aliasing	B-Error_Name
effects	O
for	O
accesses	O
that	O
fall	O
outside	O
the	O
bounds	O
of	O
an	O
array	B-Data_Structure
.	O
</s>
<s>
Another	O
variety	O
of	O
aliasing	B-Error_Name
can	O
occur	O
in	O
any	O
language	O
that	O
can	O
refer	O
to	O
one	O
location	O
in	O
memory	B-General_Concept
with	O
more	O
than	O
one	O
name	O
(	O
for	O
example	O
,	O
with	O
pointers	O
)	O
.	O
</s>
<s>
See	O
the	O
C	B-Language
example	O
of	O
the	O
XOR	O
swap	O
algorithm	O
that	O
is	O
a	O
function	O
;	O
it	O
assumes	O
the	O
two	O
pointers	O
passed	O
to	O
it	O
are	O
distinct	O
,	O
but	O
if	O
they	O
are	O
in	O
fact	O
equal	O
(	O
or	O
aliases	O
of	O
each	O
other	O
)	O
,	O
the	O
function	O
fails	O
.	O
</s>
<s>
This	O
is	O
a	O
common	O
problem	O
with	O
functions	O
that	O
accept	O
pointer	O
arguments	O
,	O
and	O
their	O
tolerance	O
(	O
or	O
the	O
lack	O
thereof	O
)	O
for	O
aliasing	B-Error_Name
must	O
be	O
carefully	O
documented	O
,	O
particularly	O
for	O
functions	O
that	O
perform	O
complex	O
manipulations	O
on	O
memory	B-General_Concept
areas	O
passed	O
to	O
them	O
.	O
</s>
<s>
Controlled	O
aliasing	B-Error_Name
behaviour	O
may	O
be	O
desirable	O
in	O
some	O
cases	O
(	O
that	O
is	O
,	O
aliasing	B-Error_Name
behaviour	O
that	O
is	O
specified	O
,	O
unlike	O
that	O
enabled	O
by	O
memory	B-General_Concept
layout	O
in	O
C	B-Language
)	O
.	O
</s>
<s>
It	O
is	O
common	O
practice	O
in	O
Fortran	B-Application
.	O
</s>
<s>
The	O
Perl	B-Language
programming	I-Language
language	I-Language
specifies	O
,	O
in	O
some	O
constructs	O
,	O
aliasing	B-Error_Name
behaviour	O
,	O
such	O
as	O
in	O
loops	O
.	O
</s>
<s>
If	O
one	O
wanted	O
to	O
bypass	O
aliasing	B-Error_Name
effects	O
,	O
one	O
could	O
copy	O
the	O
contents	O
of	O
the	O
index	O
variable	O
into	O
another	O
and	O
change	O
the	O
copy	O
.	O
</s>
<s>
Optimizers	B-Application
often	O
have	O
to	O
make	O
conservative	O
assumptions	O
about	O
variables	O
when	O
aliasing	B-Error_Name
is	O
possible	O
.	O
</s>
<s>
However	O
,	O
the	O
compiler	O
cannot	O
use	O
this	O
information	O
after	O
an	O
assignment	O
to	O
another	O
variable	O
(	O
for	O
example	O
,	O
in	O
C	B-Language
,	O
*	O
y	O
=	O
10	O
)	O
because	O
it	O
could	O
be	O
that	O
*	O
y	O
is	O
an	O
alias	O
of	O
x	O
.	O
</s>
<s>
Another	O
optimization	O
impacted	O
by	O
aliasing	B-Error_Name
is	O
code	O
reordering	O
.	O
</s>
<s>
To	O
enable	O
such	O
optimizations	O
in	O
a	O
predictable	O
manner	O
,	O
the	O
ISO	O
standard	O
for	O
the	O
C	B-Language
programming	I-Language
language	I-Language
(	O
including	O
its	O
newer	O
C99	O
edition	O
,	O
see	O
section	O
6.5	O
,	O
paragraph	O
7	O
)	O
specifies	O
that	O
it	O
is	O
illegal	O
(	O
with	O
some	O
exceptions	O
)	O
to	O
access	O
the	O
same	O
memory	B-General_Concept
location	O
using	O
pointers	O
of	O
different	O
types	O
.	O
</s>
<s>
This	O
rule	O
,	O
known	O
as	O
the	O
strict	O
aliasing	B-Error_Name
rule	O
,	O
sometimes	O
allows	O
for	O
impressive	O
increases	O
in	O
performance	O
,	O
but	O
has	O
been	O
known	O
to	O
break	O
some	O
otherwise	O
valid	O
code	O
.	O
</s>
<s>
For	O
example	O
,	O
Python	B-Language
2.x	I-Language
did	O
so	O
to	O
implement	O
reference	B-General_Concept
counting	I-General_Concept
,	O
and	O
required	O
changes	O
to	O
the	O
basic	O
object	O
structs	O
in	O
Python	O
3	O
to	O
enable	O
this	O
optimization	O
.	O
</s>
<s>
The	O
Linux	B-Operating_System
kernel	I-Operating_System
does	O
this	O
because	O
strict	O
aliasing	B-Error_Name
causes	O
problems	O
with	O
optimization	O
of	O
inlined	O
code	O
.	O
</s>
<s>
In	O
such	O
cases	O
,	O
when	O
compiled	O
with	O
gcc	B-Application
,	O
the	O
option	O
-fno-strict-aliasing	O
is	O
invoked	O
to	O
prevent	O
unwanted	O
optimizations	O
that	O
could	O
yield	O
unexpected	O
code	O
.	O
</s>
<s>
The	O
term	O
aliasing	B-Error_Name
is	O
also	O
used	O
to	O
describe	O
the	O
situation	O
where	O
,	O
due	O
to	O
either	O
a	O
hardware	O
design	O
choice	O
or	O
a	O
hardware	O
failure	O
,	O
one	O
or	O
more	O
of	O
the	O
available	O
address	O
bits	O
is	O
not	O
used	O
in	O
the	O
memory	B-General_Concept
selection	O
process	O
.	O
</s>
<s>
For	O
this	O
example	O
,	O
assuming	O
a	O
memory	B-General_Concept
design	O
with	O
8	O
locations	O
,	O
requiring	O
only	O
3	O
address	O
lines	O
(	O
or	O
bits	O
)	O
since	O
23	O
=	O
8	O
)	O
.	O
</s>
<s>
Address	O
bits	O
(	O
named	O
A2	O
through	O
A0	O
)	O
are	O
decoded	O
to	O
select	O
unique	O
memory	B-General_Concept
locations	O
as	O
follows	O
,	O
in	O
standard	O
binary	O
counter	O
fashion	O
:	O
</s>
<s>
In	O
the	O
table	O
above	O
,	O
each	O
of	O
the	O
8	O
unique	O
combinations	O
of	O
address	O
bits	O
selects	O
a	O
different	O
memory	B-General_Concept
location	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
with	O
A2	O
always	O
being	O
zero	O
,	O
the	O
first	O
four	O
memory	B-General_Concept
locations	O
are	O
duplicated	O
and	O
appear	O
again	O
as	O
the	O
second	O
four	O
.	O
</s>
<s>
Memory	B-General_Concept
locations	O
4	O
through	O
7	O
have	O
become	O
inaccessible	O
.	O
</s>
<s>
If	O
this	O
change	O
occurred	O
to	O
a	O
different	O
address	O
bit	O
,	O
the	O
decoding	O
results	O
would	O
be	O
different	O
,	O
but	O
in	O
general	O
the	O
effect	O
would	O
be	O
the	O
same	O
:	O
the	O
loss	O
of	O
a	O
single	O
address	O
bit	O
cuts	O
the	O
available	O
memory	B-General_Concept
space	O
in	O
half	O
,	O
with	O
resulting	O
duplication	O
(	O
aliasing	B-Error_Name
)	O
of	O
the	O
remaining	O
space	O
.	O
</s>
