• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #  define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A))
60 #endif
61 
62 /**
63  * Helper macro to define no_sanitize attributes only with clang.
64  */
65 #if defined(__clang__) && defined(__has_attribute)
66   #if __has_attribute(no_sanitize)
67     #define SK_CLANG_NO_SANITIZE(A) SK_NO_SANITIZE(A)
68   #endif
69 #endif
70 
71 #if !defined(SK_CLANG_NO_SANITIZE)
72   #define SK_CLANG_NO_SANITIZE(A)
73 #endif
74 
75 /**
76  * Annotates a class' non-trivial special functions as trivial for the purposes of calls.
77  * Allows a class with a non-trivial destructor to be __is_trivially_relocatable.
78  * Use of this attribute on a public API breaks platform ABI.
79  * Annotated classes may not hold pointers derived from `this`.
80  * Annotated classes must implement move+delete as equivalent to memcpy+free.
81  * Use may require more complete types, as callee destroys.
82  *
83  * https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
84  * https://libcxx.llvm.org/DesignDocs/UniquePtrTrivialAbi.html
85  */
86 #if !defined(SK_TRIVIAL_ABI)
87 #  define SK_TRIVIAL_ABI
88 #endif
89 
90 #endif
91