Debian Codegraph @

include/private/base/SkAttributes.h

raw
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 /**
21 * If your judgment is better than the compiler's (i.e. you've profiled it),
22 * you can use SK_ALWAYS_INLINE to force inlining. E.g.
23 * inline void someMethod() { ... } // may not be inlined
24 * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined
25 */
26 #if !defined(SK_ALWAYS_INLINE)
27 # if defined(SK_BUILD_FOR_WIN)
28 # define SK_ALWAYS_INLINE __forceinline
29 # else
30 # define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
31 # endif
32 #endif
33
34 /**
35 * If your judgment is better than the compiler's (i.e. you've profiled it),
36 * you can use SK_NEVER_INLINE to prevent inlining.
37 */
38 #if !defined(SK_NEVER_INLINE)
39 # if defined(SK_BUILD_FOR_WIN)
40 # define SK_NEVER_INLINE __declspec(noinline)
41 # else
42 # define SK_NEVER_INLINE SK_ATTRIBUTE(noinline)
43 # endif
44 #endif
45
46 /**
47 * Used to annotate a function as taking printf style arguments.
48 * `A` is the (1 based) index of the format string argument.
49 * `B` is the (1 based) index of the first argument used by the format string.
50 */
51 #if !defined(SK_PRINTF_LIKE)
52 # define SK_PRINTF_LIKE(A, B) SK_ATTRIBUTE(format(printf, (A), (B)))
53 #endif
54
55 /**
56 * Used to ignore sanitizer warnings.
57 */
58 #if !defined(SK_NO_SANITIZE)
59 #if defined(__has_attribute)
60 #if __has_attribute(no_sanitize)
61 // This should be for clang and versions of gcc >= 8.0
62 #define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A))
63 #else
64 // For compilers that don't support sanitization, just do nothing.
65 #define SK_NO_SANITIZE(A)
66 #endif
67 #else // no __has_attribute, e.g. MSVC
68 #define SK_NO_SANITIZE(A)
69 #endif
70 #endif
71
72 /**
73 * Used to ignore CFI sanitizer warnings, supported only by Clang at the moment.
74 */
75 #if defined(__clang__)
76 #define SK_NO_SANITIZE_CFI SK_NO_SANITIZE("cfi")
77 #else
78 #define SK_NO_SANITIZE_CFI
79 #endif
80
81 /**
82 * Annotates a class' non-trivial special functions as trivial for the purposes of calls.
83 * Allows a class with a non-trivial destructor to be __is_trivially_relocatable.
84 * Use of this attribute on a public API breaks platform ABI.
85 * Annotated classes may not hold pointers derived from `this`.
86 * Annotated classes must implement move+delete as equivalent to memcpy+free.
87 * Use may require more complete types, as callee destroys.
88 *
89 * https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
90 * https://libcxx.llvm.org/DesignDocs/UniquePtrTrivialAbi.html
91 */
92 #if !defined(SK_TRIVIAL_ABI)
93 # define SK_TRIVIAL_ABI
94 #endif
95
96 #endif