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 #define CLANG_VERSION (__clang_major__ * 10000 \
7 + __clang_minor__ * 100 \
8 + __clang_patchlevel__)
10 #if CLANG_VERSION < 100001
11 # error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
14 /* Compiler specific definitions for Clang compiler */
16 /* same as gcc, this was present in clang-2.6 so we can assume it works
17 * with any version that can compile the kernel
19 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
21 /* all clang versions usable with the kernel support KASAN ABI version 5 */
22 #define KASAN_ABI_VERSION 5
24 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
25 /* Emulate GCC's __SANITIZE_ADDRESS__ flag */
26 #define __SANITIZE_ADDRESS__
27 #define __no_sanitize_address \
28 __attribute__((no_sanitize("address", "hwaddress")))
30 #define __no_sanitize_address
33 #if __has_feature(thread_sanitizer)
34 /* emulate gcc's __SANITIZE_THREAD__ flag */
35 #define __SANITIZE_THREAD__
36 #define __no_sanitize_thread \
37 __attribute__((no_sanitize("thread")))
39 #define __no_sanitize_thread
42 #if __has_feature(undefined_behavior_sanitizer)
43 /* GCC does not have __SANITIZE_UNDEFINED__ */
44 #define __no_sanitize_undefined \
45 __attribute__((no_sanitize("undefined")))
47 #define __no_sanitize_undefined
51 * Not all versions of clang implement the type-generic versions
52 * of the builtin overflow checkers. Fortunately, clang implements
53 * __has_builtin allowing us to avoid awkward version
54 * checks. Unfortunately, we don't know which version of gcc clang
55 * pretends to be, so the macro may or may not be defined.
57 #if __has_builtin(__builtin_mul_overflow) && \
58 __has_builtin(__builtin_add_overflow) && \
59 __has_builtin(__builtin_sub_overflow)
60 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
63 /* The following are for compatibility with GCC, from compiler-gcc.h,
64 * and may be redefined here because they should not be shared with other
65 * compilers, like ICC.
67 #define barrier() __asm__ __volatile__("" : : : "memory")
69 #if __has_feature(shadow_call_stack)
70 # define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))