]> git.sesse.net Git - x264/commitdiff
Use __attribute__((may_alias)) for type-punning
authorAlexander Strange <astrange@ithinksw.com>
Sun, 15 Nov 2009 06:13:28 +0000 (22:13 -0800)
committerFiona Glaser <fiona@x264.com>
Sun, 15 Nov 2009 21:15:07 +0000 (13:15 -0800)
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.

common/common.h
common/osdep.h
configure
input/y4m.c

index 3ea5155311cc3677172e11b40670fb432efce2ec..1da3c02c0380abaaf136b0cfee7ea4eade4d5c0e 100644 (file)
@@ -79,13 +79,13 @@ do {\
 #include <assert.h>
 #include <limits.h>
 
-/* 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)
index eb48dcc8d93c111ad346a9f7f597d9f989a43daf..14f06a85bc56ad748795e2d986fec7de35c0f65b 100644 (file)
 #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
 
index d08c548b8e4bab3e00dd23753ab640345f8aa22b..5502021d24f966e50d369a4ca78825dc9292bb24 100755 (executable)
--- 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
index 5dba38a5d48c52c0155222eb7c83ef41b42de854..d5d85c846c0fd7b13bc195f45b1e6c08a8aadfa1 100644 (file)
@@ -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;
     }