OpenOCD
compiler.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /*
4  * This file contains compiler specific workarounds to handle different
5  * compilers and different compiler versions.
6  * Inspired by Linux's include/linux/compiler_attributes.h
7  * and file sys/cdefs.h in libc and newlib.
8  */
9 
10 #ifndef OPENOCD_HELPER_COMPILER_H
11 #define OPENOCD_HELPER_COMPILER_H
12 
13 /*
14  * __has_attribute is supported on gcc >= 5, clang >= 2.9 and icc >= 17.
15  */
16 #ifndef __has_attribute
17 # define __has_attribute(x) 0
18 #endif
19 
20 /*
21  * The __returns_nonnull function attribute marks the return type of the function
22  * as always being non-null.
23  */
24 #ifndef __returns_nonnull
25 # if __has_attribute(__returns_nonnull__)
26 # define __returns_nonnull __attribute__((__returns_nonnull__))
27 # else
28 # define __returns_nonnull
29 # endif
30 #endif
31 
32 /*
33  * The __nonnull function attribute marks pointer parameters that
34  * must not be NULL.
35  *
36  * clang for Apple defines
37  * #define __nonnull _Nonnull
38  * that is a per argument attribute, incompatible with the gcc per function attribute __nonnull__.
39  * gcc for Apple includes sys/cdefs.h from MacOSX.sdk that defines
40  * #define __nonnull
41  * In both cases, undefine __nonnull to keep compatibility among compilers and platforms.
42  */
43 #if defined(__APPLE__)
44 # undef __nonnull
45 #endif
46 #ifndef __nonnull
47 # if __has_attribute(__nonnull__)
48 # define __nonnull(params) __attribute__ ((__nonnull__ params))
49 # else
50 # define __nonnull(params)
51 # endif
52 #endif
53 
54 #endif /* OPENOCD_HELPER_COMPILER_H */