Enabling strict alias warnings in g ++

What is the correct way to enable strong anti-aliasing warnings in g ++? Does VC ++ 10 use these rules?

+6
source share
3 answers

Use -fstrict-aliasing for g++ . I also use -Wstrict-aliasing=2 to see warnings related to possible violations of strict alias rules.

+4
source

They are automatically turned on with -O2 because they need to use them to perform some of the optimizations. Definitely combine it with a warning ( -Wall does the trick) to make sure that you are not creating potentially buggy code. Otherwise, you can use -fstrict-aliasing as shown in another answer to enable them.

However, I'm not sure about VC ++ 10.

+3
source

VC ++ 10 allows a strict smoothing rule with / O 1 and higher. I use the test program (with a score of 6) in the chapter "ADVANTAGES TO THE BUILDING RULE OF STATEMENT" here . And get the following asm code. You can see that b is loaded only once.

 00A910AE movzx edx,word ptr [edx+2] //Load of b 00A910B2 xor eax,eax 00A910B4 xor ecx,ecx 00A910B6 add dword ptr [esp+eax*4+34h],edx //Loop start 00A910BA add eax,1 00A910BD adc ecx,edi 00A910BF jne main+76h (0A910C6h) 00A910C1 cmp eax,6 00A910C4 jb main+66h (0A910B6h) //Loop end 

But there seems to be no way to turn on a warning of a violation of this rule.

+1
source

Source: https://habr.com/ru/post/904029/


All Articles