ref: c713f846168f4d6fd6a5e2150a115eaa661e5c77
parent: 6ca77eb7ca4d3ef580f8e2df584b28322ef23ce1
author: James Zern <jzern@google.com>
date: Fri Feb 14 12:31:42 EST 2020
move common attribute defs to compiler_attributes.h BUG=b/148271109 Change-Id: I620e26ff1233fcd34ebe0723cb913e82eb58271c
--- a/examples.mk
+++ b/examples.mk
@@ -65,6 +65,7 @@
# while EXAMPLES demonstrate specific portions of the API.
UTILS-$(CONFIG_DECODERS) += vpxdec.c
vpxdec.SRCS += md5_utils.c md5_utils.h
+vpxdec.SRCS += vpx_ports/compiler_attributes.h
vpxdec.SRCS += vpx_ports/mem_ops.h
vpxdec.SRCS += vpx_ports/mem_ops_aligned.h
vpxdec.SRCS += vpx_ports/msvc.h
@@ -167,6 +168,7 @@
decode_to_md5.SRCS += tools_common.h tools_common.c
decode_to_md5.SRCS += video_common.h
decode_to_md5.SRCS += video_reader.h video_reader.c
+decode_to_md5.SRCS += vpx_ports/compiler_attributes.h
decode_to_md5.SRCS += vpx_ports/mem_ops.h
decode_to_md5.SRCS += vpx_ports/mem_ops_aligned.h
decode_to_md5.SRCS += vpx_ports/msvc.h
--- a/md5_utils.c
+++ b/md5_utils.c
@@ -23,6 +23,7 @@
#include <string.h> /* for memcpy() */
#include "md5_utils.h"
+#include "vpx_ports/compiler_attributes.h"
static void byteSwap(UWORD32 *buf, unsigned words) {
md5byte *p;
@@ -145,17 +146,6 @@
#define MD5STEP(f, w, x, y, z, in, s) \
(w += f(x, y, z) + in, w = (w << s | w >> (32 - s)) + x)
-#if defined(__clang__) && defined(__has_attribute)
-#if __has_attribute(no_sanitize)
-#define VPX_NO_UNSIGNED_OVERFLOW_CHECK \
- __attribute__((no_sanitize("unsigned-integer-overflow")))
-#endif
-#endif
-
-#ifndef VPX_NO_UNSIGNED_OVERFLOW_CHECK
-#define VPX_NO_UNSIGNED_OVERFLOW_CHECK
-#endif
-
/*
* The core of the MD5 algorithm, this alters an existing MD5 hash to
* reflect the addition of 16 longwords of new data. MD5Update blocks
@@ -243,7 +233,5 @@
buf[2] += c;
buf[3] += d;
}
-
-#undef VPX_NO_UNSIGNED_OVERFLOW_CHECK
#endif
--- a/vp8/common/reconintra4x4.c
+++ b/vp8/common/reconintra4x4.c
@@ -16,7 +16,7 @@
#include "blockd.h"
#include "reconintra4x4.h"
#include "vp8/common/common.h"
-#include "vpx_ports/mem.h"
+#include "vpx_ports/compiler_attributes.h"
typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride,
const uint8_t *above, const uint8_t *left);
--- a/vp9/encoder/vp9_pickmode.c
+++ b/vp9/encoder/vp9_pickmode.c
@@ -19,7 +19,7 @@
#include "vpx/vpx_codec.h"
#include "vpx_dsp/vpx_dsp_common.h"
#include "vpx_mem/vpx_mem.h"
-#include "vpx_ports/mem.h"
+#include "vpx_ports/compiler_attributes.h"
#include "vp9/common/vp9_blockd.h"
#include "vp9/common/vp9_common.h"
--- a/vpx_dsp/x86/convolve.h
+++ b/vpx_dsp/x86/convolve.h
@@ -14,7 +14,7 @@
#include "./vpx_config.h"
#include "vpx/vpx_integer.h"
-#include "vpx_ports/mem.h"
+#include "vpx_ports/compiler_attributes.h"
// TODO(chiyotsai@google.com): Refactor the code here. Currently this is pretty
// hacky and awful to read. Note that there is a filter_x[3] == 128 check in
--- /dev/null
+++ b/vpx_ports/compiler_attributes.h
@@ -1,0 +1,59 @@
+/*
+ * Copyright (c) 2020 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_
+#define VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_
+
+#if !defined(__has_feature)
+#define __has_feature(x) 0
+#endif // !defined(__has_feature)
+
+#if !defined(__has_attribute)
+#define __has_attribute(x) 0
+#endif // !defined(__has_attribute)
+
+//------------------------------------------------------------------------------
+// Sanitizer attributes.
+
+#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
+#define VPX_WITH_ASAN 1
+#else
+#define VPX_WITH_ASAN 0
+#endif // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
+
+#if defined(__clang__) && __has_attribute(no_sanitize)
+#define VPX_NO_UNSIGNED_OVERFLOW_CHECK \
+ __attribute__((no_sanitize("unsigned-integer-overflow")))
+#endif
+
+#ifndef VPX_NO_UNSIGNED_OVERFLOW_CHECK
+#define VPX_NO_UNSIGNED_OVERFLOW_CHECK
+#endif
+
+//------------------------------------------------------------------------------
+// Variable attributes.
+
+#if __has_attribute(uninitialized)
+// Attribute "uninitialized" disables -ftrivial-auto-var-init=pattern for
+// the specified variable.
+//
+// -ftrivial-auto-var-init is security risk mitigation feature, so attribute
+// should not be used "just in case", but only to fix real performance
+// bottlenecks when other approaches do not work. In general the compiler is
+// quite effective at eliminating unneeded initializations introduced by the
+// flag, e.g. when they are followed by actual initialization by a program.
+// However if compiler optimization fails and code refactoring is hard, the
+// attribute can be used as a workaround.
+#define VPX_UNINITIALIZED __attribute__((uninitialized))
+#else
+#define VPX_UNINITIALIZED
+#endif // __has_attribute(uninitialized)
+
+#endif // VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_
--- a/vpx_ports/mem.h
+++ b/vpx_ports/mem.h
@@ -41,34 +41,4 @@
#define CAST_TO_BYTEPTR(x) ((uint8_t *)((uintptr_t)(x)))
#endif // CONFIG_VP9_HIGHBITDEPTH
-#if !defined(__has_feature)
-#define __has_feature(x) 0
-#endif // !defined(__has_feature)
-
-#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
-#define VPX_WITH_ASAN 1
-#else
-#define VPX_WITH_ASAN 0
-#endif // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
-
-#if !defined(__has_attribute)
-#define __has_attribute(x) 0
-#endif // !defined(__has_attribute)
-
-#if __has_attribute(uninitialized)
-// Attribute "uninitialized" disables -ftrivial-auto-var-init=pattern for
-// the specified variable.
-//
-// -ftrivial-auto-var-init is security risk mitigation feature, so attribute
-// should not be used "just in case", but only to fix real performance
-// bottlenecks when other approaches do not work. In general the compiler is
-// quite effective at eliminating unneeded initializations introduced by the
-// flag, e.g. when they are followed by actual initialization by a program.
-// However if compiler optimization fails and code refactoring is hard, the
-// attribute can be used as a workaround.
-#define VPX_UNINITIALIZED __attribute__((uninitialized))
-#else
-#define VPX_UNINITIALIZED
-#endif // __has_attribute(uninitialized)
-
#endif // VPX_VPX_PORTS_MEM_H_
--- a/vpx_ports/vpx_ports.mk
+++ b/vpx_ports/vpx_ports.mk
@@ -12,6 +12,7 @@
PORTS_SRCS-yes += vpx_ports.mk
PORTS_SRCS-yes += bitops.h
+PORTS_SRCS-yes += compiler_attributes.h
PORTS_SRCS-yes += mem.h
PORTS_SRCS-yes += msvc.h
PORTS_SRCS-yes += static_assert.h