Merge tag 'for-linus-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw...
[linux-2.6-microblaze.git] / include / linux / compiler-clang.h
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."
4 #endif
5
6 /* Compiler specific definitions for Clang compiler */
7
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
10  */
11 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
12
13 /* all clang versions usable with the kernel support KASAN ABI version 5 */
14 #define KASAN_ABI_VERSION 5
15
16 #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer)
17 /* Emulate GCC's __SANITIZE_ADDRESS__ flag */
18 #define __SANITIZE_ADDRESS__
19 #define __no_sanitize_address \
20                 __attribute__((no_sanitize("address", "hwaddress")))
21 #else
22 #define __no_sanitize_address
23 #endif
24
25 #if __has_feature(thread_sanitizer)
26 /* emulate gcc's __SANITIZE_THREAD__ flag */
27 #define __SANITIZE_THREAD__
28 #define __no_sanitize_thread \
29                 __attribute__((no_sanitize("thread")))
30 #else
31 #define __no_sanitize_thread
32 #endif
33
34 #if __has_feature(undefined_behavior_sanitizer)
35 /* GCC does not have __SANITIZE_UNDEFINED__ */
36 #define __no_sanitize_undefined \
37                 __attribute__((no_sanitize("undefined")))
38 #else
39 #define __no_sanitize_undefined
40 #endif
41
42 /*
43  * Not all versions of clang implement the the type-generic versions
44  * of the builtin overflow checkers. Fortunately, clang implements
45  * __has_builtin allowing us to avoid awkward version
46  * checks. Unfortunately, we don't know which version of gcc clang
47  * pretends to be, so the macro may or may not be defined.
48  */
49 #if __has_builtin(__builtin_mul_overflow) && \
50     __has_builtin(__builtin_add_overflow) && \
51     __has_builtin(__builtin_sub_overflow)
52 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
53 #endif
54
55 /* The following are for compatibility with GCC, from compiler-gcc.h,
56  * and may be redefined here because they should not be shared with other
57  * compilers, like ICC.
58  */
59 #define barrier() __asm__ __volatile__("" : : : "memory")
60
61 #if __has_feature(shadow_call_stack)
62 # define __noscs        __attribute__((__no_sanitize__("shadow-call-stack")))
63 #endif