-fstrict-aliasing (-qalias=ansi), -qalias

Pragma equivalent

None

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

Read syntax diagramSkip visual syntax diagram
                  .-:---------------.   
                  | .-restrict----. |   
                  | +-ansi--------+ |   
                  V +-noaddrtaken-+ |   
>>- -q--alias--=----+-addrtaken---+-+--------------------------><
                    +-noansi------+     
                    '-norestrict--'     

For details about the -fstrict-aliasing option, see the GCC information, available at http://gcc.gnu.org/onlinedocs/.

Defaults

  • C++ only -qalias=noaddrtaken:ansi:restrict
  • C only -qalias=noaddrtaken:ansi:restrict for all invocation commands except cc. -qalias=noaddrtaken:noansi:restrict for the cc invocation command.

Parameters

addrtaken | noaddrtaken
When addrtaken is in effect, the reference of any variable whose address is taken may alias to any pointer type. Any class of variable for which an address has not been recorded in the compilation unit is considered disjoint from indirect access through pointers.

When noaddrtaken is specified, the compiler generates aliasing based on the aliasing rules that are in effect.

ansi | noansi
This suboption has no effect unless you also specify an optimization option. You can specify the may_alias attribute for a type that is not subject to type-based aliasing rules.

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.

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 usually results 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.

Usage

-qalias makes assertions to the compiler about the code that is being compiled. If the assertions about the code are false, the code that is generated by the compiler might result in unpredictable behavior 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 that are qualified as volatile or const. For example, a pointer to a const int can point to an int.
  • C++ only beginsBase type pointers can point to the derived types of that type.C++ only ends

Predefined macros

None.

Examples

To specify worst-case aliasing assumptions when you compile myprogram.c, enter:
xlc myprogram.c -O -qalias=noansi


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us