1 /* 2 * Copyright (c) 2020 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_ 12 #define VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_ 13 14 #if !defined(__has_feature) 15 #define __has_feature(x) 0 16 #endif // !defined(__has_feature) 17 18 #if !defined(__has_attribute) 19 #define __has_attribute(x) 0 20 #endif // !defined(__has_attribute) 21 22 //------------------------------------------------------------------------------ 23 // Sanitizer attributes. 24 25 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) 26 #define VPX_WITH_ASAN 1 27 #else 28 #define VPX_WITH_ASAN 0 29 #endif // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) 30 31 #if defined(__clang__) && __has_attribute(no_sanitize) 32 // Both of these have defined behavior and are used in certain operations or 33 // optimizations thereof. There are cases where an overflow may be unintended, 34 // however, so use of these attributes should be done with care. 35 #define VPX_NO_UNSIGNED_OVERFLOW_CHECK \ 36 __attribute__((no_sanitize("unsigned-integer-overflow"))) 37 #if __clang_major__ >= 12 38 #define VPX_NO_UNSIGNED_SHIFT_CHECK \ 39 __attribute__((no_sanitize("unsigned-shift-base"))) 40 #endif // __clang__ >= 12 41 #endif // __clang__ 42 43 #ifndef VPX_NO_UNSIGNED_OVERFLOW_CHECK 44 #define VPX_NO_UNSIGNED_OVERFLOW_CHECK 45 #endif 46 #ifndef VPX_NO_UNSIGNED_SHIFT_CHECK 47 #define VPX_NO_UNSIGNED_SHIFT_CHECK 48 #endif 49 50 //------------------------------------------------------------------------------ 51 // Variable attributes. 52 53 #if __has_attribute(uninitialized) 54 // Attribute "uninitialized" disables -ftrivial-auto-var-init=pattern for 55 // the specified variable. 56 // 57 // -ftrivial-auto-var-init is security risk mitigation feature, so attribute 58 // should not be used "just in case", but only to fix real performance 59 // bottlenecks when other approaches do not work. In general the compiler is 60 // quite effective at eliminating unneeded initializations introduced by the 61 // flag, e.g. when they are followed by actual initialization by a program. 62 // However if compiler optimization fails and code refactoring is hard, the 63 // attribute can be used as a workaround. 64 #define VPX_UNINITIALIZED __attribute__((uninitialized)) 65 #else 66 #define VPX_UNINITIALIZED 67 #endif // __has_attribute(uninitialized) 68 69 #endif // VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_ 70