[PATCH] Silence misguided GCC warning about alignment issues

Ralf Friedl Ralf.Friedl at online.de
Tue Aug 8 12:58:25 UTC 2017


Johannes Schindelin wrote:
> When compiling xz_dec_stream.c with GCC 7.1.0, it complains thusly:
>
> 	In function 'dec_stream_footer':
> 	error: dereferencing type-punned pointer will break strict-aliasing
> 	      rules [-Werror=strict-aliasing]
> 	   if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf))
> 	       ^~
>
> The thing is, the `buf` field was put just after two fields of type
> size_t for the express purpose of avoiding alignment issues, as per the
> comment above the `temp` struct.
>   
> +#if defined(__GNUC__)
> +	/*
> +	 * The temp.buf field is put just after two fields of type size_t for
> +	 * the express purpose of avoiding alignment issues. But GCC complains
> +	 * about it nevertheless... so: shut GCC up for a few lines.
> +	 */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wstrict-aliasing"
> +#endif
In this discussion, you write repeatedly about the alignment of the 
variable, you even propose a comment to that effect.
Note, this is not about the alignment, it is about aliasing, which means 
two different pointers may access the same memory location.


More information about the busybox mailing list