Been moving over an existing project to M2M Studio with OpenAt 2.20.
I’m getting a compiler warning that I haven’t seen before:
dereferencing type-punned pointer will break strict-aliasing rules
This warning is appearing for every instance of
adl_memRelease( pointer );
I have in my project.
A bit of searching around on the web has indicated that this is a common warning to have pop up when moving code to GCC 4 from earlier GGC versions, and it can be disabled by using the
-fno-strict-aliasing
compiler option.
My Questions:
Can anyone explain what this warning means with regards to the OpenAT environment?
In M2M Studio, how can I add the -fno-strict-aliasing option to the compiler command line?
Is there any way to cast the pointer variable in my code so that the -fno-strict-aliasing option is not required?
I know that it’s just a warning and can be ignored. However, there are so many of them in the log (I’m doing a lot of memory get/release operations) that other warnings are getting lost in the noise.
A friend of mine (a GCC guru) explained me that GCC embeds a “strict-aliasing” feature, which normally forbids two pointers of different types to point to the same memory address.
If you take a look to the adl_memRelease macro definition:
there is a cast to void** type which makes GCC losing type information it needs for the strict-aliasing.
I guess that such a macro is required since it is documented that adl_memRelease puts back the freed pointer to NULL: it obviously works with a pointer on the pointer…
Easy:
Right-click on your project in the Project Explorer, and go to Properties
Go to the C/C++ Build > Settings category
Select the ARM ELF GCC Compiler tool of the Tools Settings tab, and the Miscellaneous option category
In the Other flags list, append the -fno-strict-aliasing option
Rebuild… your warnings shall disappear…
I’ve tried but found no solution, because of the void** cast. Let’s hope that in future release the flag will be systematically added by M2M Studio.