1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_COMPILER_TYPES_H
3 #error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
6 /* Compiler specific definitions for Clang compiler */
8 /* same as gcc, this was present in clang-2.6 so we can assume it works
9 * with any version that can compile the kernel
11 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
13 /* all clang versions usable with the kernel support KASAN ABI version 5 */
14 #define KASAN_ABI_VERSION 5
17 * Note: Checking __has_feature(*_sanitizer) is only true if the feature is
18 * enabled. Therefore it is not required to additionally check defined(CONFIG_*)
19 * to avoid adding redundant attributes in other configurations.
22 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
23 /* Emulate GCC's __SANITIZE_ADDRESS__ flag */
24 #define __SANITIZE_ADDRESS__
25 #define __no_sanitize_address \
26 __attribute__((no_sanitize("address", "hwaddress")))
28 #define __no_sanitize_address
31 #if __has_feature(thread_sanitizer)
32 /* emulate gcc's __SANITIZE_THREAD__ flag */
33 #define __SANITIZE_THREAD__
34 #define __no_sanitize_thread \
35 __attribute__((no_sanitize("thread")))
37 #define __no_sanitize_thread
40 #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP)
41 #define __HAVE_BUILTIN_BSWAP32__
42 #define __HAVE_BUILTIN_BSWAP64__
43 #define __HAVE_BUILTIN_BSWAP16__
44 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
46 #if __has_feature(undefined_behavior_sanitizer)
47 /* GCC does not have __SANITIZE_UNDEFINED__ */
48 #define __no_sanitize_undefined \
49 __attribute__((no_sanitize("undefined")))
51 #define __no_sanitize_undefined
54 #if __has_feature(memory_sanitizer)
55 #define __SANITIZE_MEMORY__
57 * Unlike other sanitizers, KMSAN still inserts code into functions marked with
58 * no_sanitize("kernel-memory"). Using disable_sanitizer_instrumentation
59 * provides the behavior consistent with other __no_sanitize_ attributes,
60 * guaranteeing that __no_sanitize_memory functions remain uninstrumented.
62 #define __no_sanitize_memory __disable_sanitizer_instrumentation
65 * The __no_kmsan_checks attribute ensures that a function does not produce
66 * false positive reports by:
67 * - initializing all local variables and memory stores in this function;
68 * - skipping all shadow checks;
69 * - passing initialized arguments to this function's callees.
71 #define __no_kmsan_checks __attribute__((no_sanitize("kernel-memory")))
73 #define __no_sanitize_memory
74 #define __no_kmsan_checks
78 * Support for __has_feature(coverage_sanitizer) was added in Clang 13 together
79 * with no_sanitize("coverage"). Prior versions of Clang support coverage
80 * instrumentation, but cannot be queried for support by the preprocessor.
82 #if __has_feature(coverage_sanitizer)
83 #define __no_sanitize_coverage __attribute__((no_sanitize("coverage")))
85 #define __no_sanitize_coverage
88 #if __has_feature(shadow_call_stack)
89 # define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
92 #if __has_feature(kcfi)
93 /* Disable CFI checking inside a function. */
94 #define __nocfi __attribute__((__no_sanitize__("kcfi")))
98 * Turn individual warnings and errors on and off locally, depending
101 #define __diag_clang(version, severity, s) \
102 __diag_clang_ ## version(__diag_clang_ ## severity s)
104 /* Severity used in pragma directives */
105 #define __diag_clang_ignore ignored
106 #define __diag_clang_warn warning
107 #define __diag_clang_error error
109 #define __diag_str1(s) #s
110 #define __diag_str(s) __diag_str1(s)
111 #define __diag(s) _Pragma(__diag_str(clang diagnostic s))
113 #if CONFIG_CLANG_VERSION >= 110000
114 #define __diag_clang_11(s) __diag(s)
116 #define __diag_clang_11(s)
119 #define __diag_ignore_all(option, comment) \
120 __diag_clang(11, ignore, option)