Re: Clarification on Gcc's strict aliasing rules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patrick Horgan <phorgan1@xxxxxxxxx> writes:

[...]

> If you look on the boost wiki you find a discussion of strict-aliasing
> and how gcc generates awesome code if you do things right.  (If you
> like it I wrote that section, if you don't it was probably random
> cosmic rays).
>
> https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines
>

I have 2 remarks:

>From the -fstrict-alisiang part, one can read:

  In particular you're promising by using this flag that an object of
  one type won't reside at the same address as an object of an
  incompatible type

I don't think this is exact since the standard allows one special case
of this: please see the C's standard 6.5.2.3p5

The other thing is about the swaphalves() example. The main point is
that -fno-strict-aliasing (without the use of union) produces incorrect
code, the code size is pretty much the same for both cases. Reading this
section, I feel like '-fno-strict-aliasing' without the union produces
incorrect _and_ slow code for that particular example which is not true:

   $ gcc -O2 -fno-strict-aliasing swaphalves-with-union.c && objdump -D a.out
   [...]
   0000000000400480 <swaphalves>:
     400480:	89 f8                	mov    %edi,%eax
     400482:	c1 c0 10             	rol    $0x10,%eax
     400485:	c3                   	retq   
   [...]

   $ gcc -O2 -fno-strict-aliasing swaphalves.c && objdump -D a.out
   [...]
   0000000000400480 <swaphalves>:
     400480:	89 f8                	mov    %edi,%eax
     400482:	66 89 7c 24 fe       	mov    %di,-0x2(%rsp)
     400487:	c1 e8 10             	shr    $0x10,%eax
     40048a:	66 89 44 24 fc       	mov    %ax,-0x4(%rsp)
     40048f:	8b 44 24 fc          	mov    -0x4(%rsp),%eax
     400493:	c3                   	retq   
   [...]

-- 
Francis


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux