[x264-devel] commit: Use __attribute__((may_alias)) for type-punning (Alexander Strange )
git version control
git at videolan.org
Mon Nov 16 01:32:17 CET 2009
x264 | branch: master | Alexander Strange <astrange at ithinksw.com> | Sat Nov 14 22:13:28 2009 -0800| [1d54b2c7f9110cb7c7af1059cf595db17ed96273] | committer: Jason Garrett-Glaser
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.
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=1d54b2c7f9110cb7c7af1059cf595db17ed96273
---
common/common.h | 8 ++++----
common/osdep.h | 2 ++
configure | 2 +-
input/y4m.c | 2 +-
4 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/common/common.h b/common/common.h
index 3ea5155..1da3c02 100644
--- a/common/common.h
+++ b/common/common.h
@@ -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)
diff --git a/common/osdep.h b/common/osdep.h
index eb48dcc..14f06a8 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 d08c548..5502021 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 5dba38a..d5d85c8 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;
}
More information about the x264-devel
mailing list