From 7e5e12757b93167d993d8e34031f500216f09c5f Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Fri, 13 Apr 2018 11:19:28 -0700 Subject: [PATCH] use attribute to alias for punning float to int Bug: libyuv:791 Test: g++ -Iinclude -I../libvpx/third_party/libwebm -I../libvpx/vp8 -I../libvpx/vp8 -I../libvpx/vp9 -I../libvpx/vp9 -Iinclude -m64 -DNDEBUG -O3 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wdisabled-optimization -Wfloat-conversion -Wpointer-arith -Wtype-limits -Wcast-qual -Wvla -Wuninitialized -Wunused -Wextra -I. -I"../libvpx" -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -Wno-unused-parameter -c -o third_party/libyuv/source/row_common.cc.o source/row_common.cc Change-Id: Ia006cb9212b671ae668cab5ec0b29759024a2c8a Reviewed-on: https://chromium-review.googlesource.com/1012462 Reviewed-by: Johann Koenig Commit-Queue: Frank Barchard --- README.chromium | 2 +- include/libyuv/version.h | 2 +- source/row_common.cc | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.chromium b/README.chromium index 23c10d795..090967573 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1708 +Version: 1709 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index fc5654115..82db1d6f4 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1708 +#define LIBYUV_VERSION 1709 #endif // INCLUDE_LIBYUV_VERSION_H_ diff --git a/source/row_common.cc b/source/row_common.cc index a598ee592..2bbc5adbf 100644 --- a/source/row_common.cc +++ b/source/row_common.cc @@ -2762,6 +2762,13 @@ void ARGBPolynomialRow_C(const uint8_t* src_argb, // simply extract the low bits of the exponent and the high // bits of the mantissa from our float and we're done. +// Work around GCC 7 punning warning -Wstrict-aliasing +#if defined(__GNUC__) +typedef uint32_t __attribute__((__may_alias__)) uint32_alias_t; +#else +typedef uint32_t uint32_alias_t; +#endif + void HalfFloatRow_C(const uint16_t* src, uint16_t* dst, float scale, @@ -2770,7 +2777,7 @@ void HalfFloatRow_C(const uint16_t* src, float mult = 1.9259299444e-34f * scale; for (i = 0; i < width; ++i) { float value = src[i] * mult; - dst[i] = (uint16_t)((*(uint32_t*)&value) >> 13); + dst[i] = (uint16_t)((*(const uint32_alias_t*)&value) >> 13); } }