From 369e264e2ee07cd30188e24e12673a24d1c52dcc Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 9 May 2016 22:55:21 -0700 Subject: [PATCH] dsp.h: add WEBP_UBSAN_IGNORE_UNDEF only defined when WEBP_FORCE_ALIGNED isn't. use it to quiet alignment warnings VP8LoadNewBytes(). Change-Id: I710a74bb9375285974e97022540551a3f4eda414 --- src/dsp/dsp.h | 13 +++++++++++++ src/utils/bit_reader_inl.h | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/dsp/dsp.h b/src/dsp/dsp.h index 10c16ee4..f09d7cdd 100644 --- a/src/dsp/dsp.h +++ b/src/dsp/dsp.h @@ -101,6 +101,19 @@ extern "C" { #endif #endif +// This macro prevents the undefined behavior sanitizer from reporting +// failures. This is only meant to silence unaligned loads on platforms that +// are known to support them. +#define WEBP_UBSAN_IGNORE_UNDEF +#if !defined(WEBP_FORCE_ALIGNED) && defined(__clang__) && \ + defined(__has_attribute) +#if __has_attribute(no_sanitize) +#undef WEBP_UBSAN_IGNORE_UNDEF +#define WEBP_UBSAN_IGNORE_UNDEF \ + __attribute__((no_sanitize("undefined"))) +#endif +#endif + typedef enum { kSSE2, kSSE3, diff --git a/src/utils/bit_reader_inl.h b/src/utils/bit_reader_inl.h index 37215702..99ed3137 100644 --- a/src/utils/bit_reader_inl.h +++ b/src/utils/bit_reader_inl.h @@ -55,7 +55,8 @@ void VP8LoadFinalBytes(VP8BitReader* const br); // Inlined critical functions // makes sure br->value_ has at least BITS bits worth of data -static WEBP_INLINE void VP8LoadNewBytes(VP8BitReader* const br) { +static WEBP_UBSAN_IGNORE_UNDEF WEBP_INLINE +void VP8LoadNewBytes(VP8BitReader* const br) { assert(br != NULL && br->buf_ != NULL); // Read 'BITS' bits at a time if possible. if (br->buf_ < br->buf_max_) {