[ipxe-devel] [PATCH] Avoid strict-aliasing warning for gcc 4.3.

Bo Yang boyang at suse.com
Thu Mar 21 03:32:51 UTC 2013



>>> On 3/21/2013 at 12:20 AM, in message <5149E1D2.6090301 at fensystems.co.uk>,
Michael Brown <mbrown at fensystems.co.uk> wrote: 
> On 20/03/13 08:34, Bo Yang wrote: 
> > Signed-off-by: Bo Yang<boyang at suse.com> 
> > --- 
> >   src/arch/i386/include/bits/byteswap.h |    4 ++-- 
> >   1 files changed, 2 insertions(+), 2 deletions(-) 
> > 
> > diff --git a/src/arch/i386/include/bits/byteswap.h  
> b/src/arch/i386/include/bits/byteswap.h 
> > index f3d30a2..0d9cb96 100644 
> > --- a/src/arch/i386/include/bits/byteswap.h 
> > +++ b/src/arch/i386/include/bits/byteswap.h 
> > @@ -53,8 +53,8 @@ __bswap_variable_64 ( uint64_t x ) { 
> >   static inline __attribute__ (( always_inline )) void 
> >   __bswap_64s ( uint64_t *x ) { 
> >   	struct { 
> > -		uint32_t low; 
> > -		uint32_t high; 
> > +		uint32_t __attribute__ (( may_alias )) low; 
> > +		uint32_t __attribute__ (( may_alias )) high; 
> >   	} __attribute__ (( may_alias )) *dwords = ( ( void * ) x ); 
> >   	uint32_t discard; 
>  
> I'm puzzled by this; as far as I know, the may_alias which is already  
> present on the structure type should be sufficient.  I have tested gcc  
> versions 4.3.0, 4.3.1, 4.3.2, 4.3.3, 4.3.4 and 4.3.5 (using the GCC  
> compile farm) and have not been able to reproduce any problem with the  
> original, unmodified code. 
>  
> Could you let me know precisely which gcc version is causing problems,  
> and what the error message is? 

I am sorry that I missed the architecture. gcc 4.3 on x86. My testing
uses gcc 4.3.4 on x86 system(SLES11SP2).

I don't understand this either. :( It looks like that the 32-bit gcc 4.3 does 
some optimization and checks into the structure. Here is the message:


arch/i386/include/bits/byteswap.h:61: error: likely type-punning may break strict-aliasing rules: object ‘*{unknown}’ of main type ‘unsigned int’ is referenced at or around arch/i386/include/bits/byteswap.h:61 and may be aliased to object ‘test64’ of main type ‘long long unsigned int’ which is referenced at or around tests/byteswap_test.c:83.
arch/i386/include/bits/byteswap.h:61: error: likely type-punning may break strict-aliasing rules: object ‘*{unknown}’ of main type ‘unsigned int’ is referenced at or around arch/i386/include/bits/byteswap.h:61 and may be aliased to object ‘test64’ of main type ‘long long unsigned int’ which is referenced at or around tests/byteswap_test.c:83.

Thanks!

>  
> Thanks, 
>  
> Michael 
>  
>  




More information about the ipxe-devel mailing list