Purpose
Indicates whether a program contains certain
categories of aliasing or does not conform to C/C++ standard aliasing
rules. The compiler limits the scope of some optimizations when there
is a possibility that different names are aliases for the same storage
location.
Syntax
.-:---------------.
| .-notypeptr---. |
| +-restrict----+ |
| +-global------+ |
| +-noallptrs---+ |
| +-ansi--------+ |
V +-noaddrtaken-+ |
>>- -q--alias--=----+-addrtaken---+-+--------------------------><
+-noansi------+
+-allptrs-----+
+-noglobal----+
+-norestrict--+
'-typeptr-----'
Defaults
- -qalias=noaddrtaken:noallptrs:ansi:global:restrict:notypeptr
- -qalias=noaddrtaken:noallptrs:ansi:global:restrict:notypeptr for
all invocation commands except cc. -qalias=noaddrtaken:noallptrs:noansi:global:restrict:notypeptr for
the cc invocation command.
Parameters
- addrtaken | noaddrtaken
- When addrtaken is in effect, variables are disjoint from
pointers unless their address is taken. Any class of variable for
which an address has not been recorded in the compilation unit
will be considered disjoint from indirect access through pointers.
When noaddrtaken is
specified, the compiler generates aliasing based on the aliasing rules
that are in effect.
- allptrs | noallptrs
- When allptrs is in effect, pointers are never aliased (this
also implies -qalias=typeptr). Specifying allptrs is
an assertion to the compiler that no two pointers point to the same
storage location. These suboptions are only valid if ansi is
also specified.
- ansi | noansi
- When ansi is in effect, type-based aliasing is used during
optimization, which restricts the lvalues that can be safely used
to access a data object. The optimizer assumes that pointers can only point
to an object of the same type. This suboption has no effect unless
you also specify an optimization option.
When noansi is
in effect, the optimizer makes worst case aliasing assumptions. It
assumes that a pointer of a given type can point to an external object
or any object whose address is already taken, regardless of type.
- global | noglobal
- When global is in effect, type-based aliasing rules are
enabled during IPA link-time optimization across compilation units.
Both -qipa and -qalias=ansi must be enabled for -qalias=global to
have an effect. Specifying noglobal disables type-based aliasing
rules.
-qalias=global produces
better performance at higher optimization levels and also better link-time
performance. If you use -qalias=global, it is recommended that
you compile as much as possible of the application with the same version
of the compiler to maximize the effect of the suboption on performance.
- restrict | norestrict
- When restrict is in effect, optimizations for pointers
qualified with the restrict keyword are enabled.
Specifying norestrict disables optimizations for restrict-qualified
pointers.
-qalias=restrict is independent from other -qalias suboptions.
Using the -qalias=restrict option will usually result in performance
improvements for code that uses restrict-qualified
pointers. Note, however, that using -qalias=restrict requires
that restricted pointers be used correctly; if they are not, compile-time
and runtime failures may result. You can use norestrict to
preserve compatibility with code compiled with versions of the compiler
previous to V9.0.
- typeptr | notypeptr
- When typeptr is in effect, pointers to different types
are never aliased. Specifying typeptr is an assertion to
the compiler that no two pointers of different types point to the
same storage location. These suboptions are only valid if ansi is
also specified.
Usage
-qalias makes assertions to
the compiler about the code that is being compiled. If the assertions
about the code are false, then the code generated by the compiler
may result in unpredictable behaviour when the application is run.
The
following are not subject to type-based aliasing:
- Signed and unsigned types. For example, a pointer to a signed
int can point to an unsigned int.
- Character pointer types can point to any type.
- Types qualified as volatile or const.
For example, a pointer to a const int can point to
an int.
The -qalias=[no]ansi option replaces
the deprecated -q[no]ansialias option. Use -qalias=[no]ansi in
your new applications.
Examples
To specify worst-case aliasing
assumptions when compiling
myprogram.c, enter:
xlc myprogram.c -O -qalias=noansi