1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkAttributes_DEFINED 9 #define SkAttributes_DEFINED 10 11 #include "include/private/base/SkFeatures.h" // IWYU pragma: keep 12 #include "include/private/base/SkLoadUserConfig.h" // IWYU pragma: keep 13 14 #if defined(__clang__) || defined(__GNUC__) 15 # define SK_ATTRIBUTE(attr) __attribute__((attr)) 16 #else 17 # define SK_ATTRIBUTE(attr) 18 #endif 19 20 #if !defined(SK_UNUSED) 21 # if !defined(__clang__) && defined(_MSC_VER) 22 # define SK_UNUSED __pragma(warning(suppress:4189)) 23 # else 24 # define SK_UNUSED SK_ATTRIBUTE(unused) 25 # endif 26 #endif 27 28 #if !defined(SK_WARN_UNUSED_RESULT) 29 #define SK_WARN_UNUSED_RESULT SK_ATTRIBUTE(warn_unused_result) 30 #endif 31 32 /** 33 * If your judgment is better than the compiler's (i.e. you've profiled it), 34 * you can use SK_ALWAYS_INLINE to force inlining. E.g. 35 * inline void someMethod() { ... } // may not be inlined 36 * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined 37 */ 38 #if !defined(SK_ALWAYS_INLINE) 39 # if defined(SK_BUILD_FOR_WIN) 40 # define SK_ALWAYS_INLINE __forceinline 41 # else 42 # define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline 43 # endif 44 #endif 45 46 /** 47 * If your judgment is better than the compiler's (i.e. you've profiled it), 48 * you can use SK_NEVER_INLINE to prevent inlining. 49 */ 50 #if !defined(SK_NEVER_INLINE) 51 # if defined(SK_BUILD_FOR_WIN) 52 # define SK_NEVER_INLINE __declspec(noinline) 53 # else 54 # define SK_NEVER_INLINE SK_ATTRIBUTE(noinline) 55 # endif 56 #endif 57 58 /** 59 * Used to annotate a function as taking printf style arguments. 60 * `A` is the (1 based) index of the format string argument. 61 * `B` is the (1 based) index of the first argument used by the format string. 62 */ 63 #if !defined(SK_PRINTF_LIKE) 64 # define SK_PRINTF_LIKE(A, B) SK_ATTRIBUTE(format(printf, (A), (B))) 65 #endif 66 67 /** 68 * Used to ignore sanitizer warnings. 69 */ 70 #if !defined(SK_NO_SANITIZE) 71 # define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A)) 72 #endif 73 74 /** 75 * Annotates a class' non-trivial special functions as trivial for the purposes of calls. 76 * Allows a class with a non-trivial destructor to be __is_trivially_relocatable. 77 * Use of this attribute on a public API breaks platform ABI. 78 * Annotated classes may not hold pointers derived from `this`. 79 * Annotated classes must implement move+delete as equivalent to memcpy+free. 80 * Use may require more complete types, as callee destroys. 81 * 82 * https://clang.llvm.org/docs/AttributeReference.html#trivial-abi 83 * https://libcxx.llvm.org/DesignDocs/UniquePtrTrivialAbi.html 84 */ 85 #if !defined(SK_TRIVIAL_ABI) 86 # define SK_TRIVIAL_ABI 87 #endif 88 89 #endif 90