From: Alexander Strange Date: Sun, 15 Nov 2009 06:13:28 +0000 (-0800) Subject: Use __attribute__((may_alias)) for type-punning X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddbac0c6f6b320eb8b1731c744d7803140b0a5a3;p=libx264 Use __attribute__((may_alias)) for type-punning GCC thinks pointer casts to unions aren't valid with strict aliasing. See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Optimize-Options.html#Type_002dpunning. Also use M32() in y4m.c. Enable -Wstrict-aliasing again since all such warnings are fixed. --- diff --git a/common/common.h b/common/common.h index 3ea51553..1da3c02c 100644 --- a/common/common.h +++ b/common/common.h @@ -79,13 +79,13 @@ do {\ #include #include -/* Unions for type-punning without aliasing violations. +/* Unions for type-punning. * Mn: load or store n bits, aligned, native-endian * CPn: copy n bits, aligned, native-endian * we don't use memcpy for CPn because memcpy's args aren't assumed to be aligned */ -typedef union { uint16_t i; uint8_t c[2]; } x264_union16_t; -typedef union { uint32_t i; uint16_t b[2]; uint8_t c[4]; } x264_union32_t; -typedef union { uint64_t i; uint32_t a[2]; uint16_t b[4]; uint8_t c[8]; } x264_union64_t; +typedef union { uint16_t i; uint8_t c[2]; } MAY_ALIAS x264_union16_t; +typedef union { uint32_t i; uint16_t b[2]; uint8_t c[4]; } MAY_ALIAS x264_union32_t; +typedef union { uint64_t i; uint32_t a[2]; uint16_t b[4]; uint8_t c[8]; } MAY_ALIAS x264_union64_t; #define M16(src) (((x264_union16_t*)(src))->i) #define M32(src) (((x264_union32_t*)(src))->i) #define M64(src) (((x264_union64_t*)(src))->i) diff --git a/common/osdep.h b/common/osdep.h index eb48dcc8..14f06a85 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -69,11 +69,13 @@ #define UNUSED __attribute__((unused)) #define ALWAYS_INLINE __attribute__((always_inline)) inline #define NOINLINE __attribute__((noinline)) +#define MAY_ALIAS __attribute__((may_alias)) #define x264_constant_p(x) __builtin_constant_p(x) #else #define UNUSED #define ALWAYS_INLINE inline #define NOINLINE +#define MAY_ALIAS #define x264_constant_p(x) 0 #endif diff --git a/configure b/configure index d08c548b..5502021d 100755 --- a/configure +++ b/configure @@ -61,7 +61,7 @@ pic="no" vis="no" shared="no" -CFLAGS="$CFLAGS -Wall -I. -Wno-strict-aliasing" +CFLAGS="$CFLAGS -Wall -I." LDFLAGS="$LDFLAGS" ASFLAGS="$ASFLAGS" HAVE_GETOPT_LONG=1 diff --git a/input/y4m.c b/input/y4m.c index 5dba38a5..d5d85c84 100644 --- a/input/y4m.c +++ b/input/y4m.c @@ -188,7 +188,7 @@ static int read_frame_internal( x264_picture_t *p_pic, y4m_hnd_t *h ) if( strncmp( header, Y4M_FRAME_MAGIC, slen ) ) { fprintf( stderr, "Bad header magic (%"PRIx32" <=> %s)\n", - *((uint32_t*)header), header ); + M32(header), header ); return -1; }