You must indicate whether your source code conforms to the ANSI aliasing rules when you use the IPA or the OPT(2) (or above) z/OS® XL C/C++ compiler options. If the code does not conform to the rules, it must be compiled with NOANSIALIAS. Incorrect use of these options might generate bad code.
Type | Reason for acceptance |
---|---|
int | This is the declared type of the object. |
const int or volatile int | These types are the qualified version of the declared type of the object. |
unsigned int | This is a signed or unsigned type corresponding to the declared type of the object. |
const unsigned int or volatile unsigned int | These types are the signed or unsigned types corresponding to a qualified version of the declared type of the object. |
|
This is an aggregate or union type that includes one of the aforementioned types among its members. This can include, recursively, a member of a subaggregator-contained union. |
char or unsigned char | The char pointers are an exception to the rules, as any pointer can be used to point to a char variable. |
Conversely, your code breaks the aliasing rules if it casts a float to an int and then assigns it to the int pointer.
For more information, see type-based aliasing in z/OS XL C/C++ Language Reference and ANSIALIAS in z/OS XL C/C++ User's Guide.
When you use the NOANSIALIAS option, the compiler generates code to accommodate worst-case assumptions (for example, that any variable could have been updated by the store through a pointer). This means that every variable (local and global) must be stored in memory to ensure that any value can be read through a pointer. This severely limits the potential for optimization.
int ei1;
float ef1;
int *eip1;
float *efp1;
float exmp1 ()
{
ef1 = 3.0;
ei1=5;
*efp1 = ef1;
*eip1 = ei1;
return *efp1;
}
Table 2 shows the difference between code generated with, and without, ANSI aliasing.
ANSIALIAS RENT and OPT(2) | NOANSIALIAS RENT and OPT(2) |
---|---|
|
|
|
|
|
|
|
|
|
|
|