![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 #ifndef __LINUX_COMPILER_ATTRIBUTES_H 0003 #define __LINUX_COMPILER_ATTRIBUTES_H 0004 0005 /* 0006 * The attributes in this file are unconditionally defined and they directly 0007 * map to compiler attribute(s), unless one of the compilers does not support 0008 * the attribute. In that case, __has_attribute is used to check for support 0009 * and the reason is stated in its comment ("Optional: ..."). 0010 * 0011 * Any other "attributes" (i.e. those that depend on a configuration option, 0012 * on a compiler, on an architecture, on plugins, on other attributes...) 0013 * should be defined elsewhere (e.g. compiler_types.h or compiler-*.h). 0014 * The intention is to keep this file as simple as possible, as well as 0015 * compiler- and version-agnostic (e.g. avoiding GCC_VERSION checks). 0016 * 0017 * This file is meant to be sorted (by actual attribute name, 0018 * not by #define identifier). Use the __attribute__((__name__)) syntax 0019 * (i.e. with underscores) to avoid future collisions with other macros. 0020 * Provide links to the documentation of each supported compiler, if it exists. 0021 */ 0022 0023 /* 0024 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alias-function-attribute 0025 */ 0026 #define __alias(symbol) __attribute__((__alias__(#symbol))) 0027 0028 /* 0029 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-aligned-function-attribute 0030 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-aligned-type-attribute 0031 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-aligned-variable-attribute 0032 */ 0033 #define __aligned(x) __attribute__((__aligned__(x))) 0034 #define __aligned_largest __attribute__((__aligned__)) 0035 0036 /* 0037 * Note: do not use this directly. Instead, use __alloc_size() since it is conditionally 0038 * available and includes other attributes. 0039 * 0040 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute 0041 * clang: https://clang.llvm.org/docs/AttributeReference.html#alloc-size 0042 */ 0043 #define __alloc_size__(x, ...) __attribute__((__alloc_size__(x, ## __VA_ARGS__))) 0044 0045 /* 0046 * Note: users of __always_inline currently do not write "inline" themselves, 0047 * which seems to be required by gcc to apply the attribute according 0048 * to its docs (and also "warning: always_inline function might not be 0049 * inlinable [-Wattributes]" is emitted). 0050 * 0051 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute 0052 * clang: mentioned 0053 */ 0054 #define __always_inline inline __attribute__((__always_inline__)) 0055 0056 /* 0057 * The second argument is optional (default 0), so we use a variadic macro 0058 * to make the shorthand. 0059 * 0060 * Beware: Do not apply this to functions which may return 0061 * ERR_PTRs. Also, it is probably unwise to apply it to functions 0062 * returning extra information in the low bits (but in that case the 0063 * compiler should see some alignment anyway, when the return value is 0064 * massaged by 'flags = ptr & 3; ptr &= ~3;'). 0065 * 0066 * Optional: not supported by icc 0067 * 0068 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-assume_005faligned-function-attribute 0069 * clang: https://clang.llvm.org/docs/AttributeReference.html#assume-aligned 0070 */ 0071 #if __has_attribute(__assume_aligned__) 0072 # define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) 0073 #else 0074 # define __assume_aligned(a, ...) 0075 #endif 0076 0077 /* 0078 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-cold-function-attribute 0079 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-cold-label-attribute 0080 */ 0081 #define __cold __attribute__((__cold__)) 0082 0083 /* 0084 * Note the long name. 0085 * 0086 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute 0087 */ 0088 #define __attribute_const__ __attribute__((__const__)) 0089 0090 /* 0091 * Optional: only supported since gcc >= 9 0092 * Optional: not supported by clang 0093 * Optional: not supported by icc 0094 * 0095 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-copy-function-attribute 0096 */ 0097 #if __has_attribute(__copy__) 0098 # define __copy(symbol) __attribute__((__copy__(symbol))) 0099 #else 0100 # define __copy(symbol) 0101 #endif 0102 0103 /* 0104 * Optional: not supported by gcc 0105 * Optional: only supported since clang >= 14.0 0106 * Optional: not supported by icc 0107 * 0108 * clang: https://clang.llvm.org/docs/AttributeReference.html#diagnose_as_builtin 0109 */ 0110 #if __has_attribute(__diagnose_as_builtin__) 0111 # define __diagnose_as(builtin...) __attribute__((__diagnose_as_builtin__(builtin))) 0112 #else 0113 # define __diagnose_as(builtin...) 0114 #endif 0115 0116 /* 0117 * Don't. Just don't. See commit 771c035372a0 ("deprecate the '__deprecated' 0118 * attribute warnings entirely and for good") for more information. 0119 * 0120 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute 0121 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-deprecated-type-attribute 0122 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-deprecated-variable-attribute 0123 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html#index-deprecated-enumerator-attribute 0124 * clang: https://clang.llvm.org/docs/AttributeReference.html#deprecated 0125 */ 0126 #define __deprecated 0127 0128 /* 0129 * Optional: not supported by clang 0130 * Optional: not supported by icc 0131 * 0132 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-designated_005finit-type-attribute 0133 */ 0134 #if __has_attribute(__designated_init__) 0135 # define __designated_init __attribute__((__designated_init__)) 0136 #else 0137 # define __designated_init 0138 #endif 0139 0140 /* 0141 * Optional: only supported since clang >= 14.0 0142 * 0143 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-error-function-attribute 0144 */ 0145 #if __has_attribute(__error__) 0146 # define __compiletime_error(msg) __attribute__((__error__(msg))) 0147 #else 0148 # define __compiletime_error(msg) 0149 #endif 0150 0151 /* 0152 * Optional: not supported by clang 0153 * 0154 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-externally_005fvisible-function-attribute 0155 */ 0156 #if __has_attribute(__externally_visible__) 0157 # define __visible __attribute__((__externally_visible__)) 0158 #else 0159 # define __visible 0160 #endif 0161 0162 /* 0163 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute 0164 * clang: https://clang.llvm.org/docs/AttributeReference.html#format 0165 */ 0166 #define __printf(a, b) __attribute__((__format__(printf, a, b))) 0167 #define __scanf(a, b) __attribute__((__format__(scanf, a, b))) 0168 0169 /* 0170 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-gnu_005finline-function-attribute 0171 * clang: https://clang.llvm.org/docs/AttributeReference.html#gnu-inline 0172 */ 0173 #define __gnu_inline __attribute__((__gnu_inline__)) 0174 0175 /* 0176 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute 0177 * clang: https://clang.llvm.org/docs/AttributeReference.html#malloc 0178 */ 0179 #define __malloc __attribute__((__malloc__)) 0180 0181 /* 0182 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-mode-type-attribute 0183 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-mode-variable-attribute 0184 */ 0185 #define __mode(x) __attribute__((__mode__(x))) 0186 0187 /* 0188 * Optional: only supported since gcc >= 7 0189 * 0190 * gcc: https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-no_005fcaller_005fsaved_005fregisters-function-attribute_002c-x86 0191 * clang: https://clang.llvm.org/docs/AttributeReference.html#no-caller-saved-registers 0192 */ 0193 #if __has_attribute(__no_caller_saved_registers__) 0194 # define __no_caller_saved_registers __attribute__((__no_caller_saved_registers__)) 0195 #else 0196 # define __no_caller_saved_registers 0197 #endif 0198 0199 /* 0200 * Optional: not supported by clang 0201 * 0202 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noclone-function-attribute 0203 */ 0204 #if __has_attribute(__noclone__) 0205 # define __noclone __attribute__((__noclone__)) 0206 #else 0207 # define __noclone 0208 #endif 0209 0210 /* 0211 * Add the pseudo keyword 'fallthrough' so case statement blocks 0212 * must end with any of these keywords: 0213 * break; 0214 * fallthrough; 0215 * continue; 0216 * goto <label>; 0217 * return [expression]; 0218 * 0219 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes 0220 */ 0221 #if __has_attribute(__fallthrough__) 0222 # define fallthrough __attribute__((__fallthrough__)) 0223 #else 0224 # define fallthrough do {} while (0) /* fallthrough */ 0225 #endif 0226 0227 /* 0228 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes 0229 * clang: https://clang.llvm.org/docs/AttributeReference.html#flatten 0230 */ 0231 # define __flatten __attribute__((flatten)) 0232 0233 /* 0234 * Note the missing underscores. 0235 * 0236 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute 0237 * clang: mentioned 0238 */ 0239 #define noinline __attribute__((__noinline__)) 0240 0241 /* 0242 * Optional: only supported since gcc >= 8 0243 * Optional: not supported by clang 0244 * Optional: not supported by icc 0245 * 0246 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-nonstring-variable-attribute 0247 */ 0248 #if __has_attribute(__nonstring__) 0249 # define __nonstring __attribute__((__nonstring__)) 0250 #else 0251 # define __nonstring 0252 #endif 0253 0254 /* 0255 * Optional: only supported since GCC >= 7.1, clang >= 13.0. 0256 * 0257 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute 0258 * clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function 0259 */ 0260 #if __has_attribute(__no_profile_instrument_function__) 0261 # define __no_profile __attribute__((__no_profile_instrument_function__)) 0262 #else 0263 # define __no_profile 0264 #endif 0265 0266 /* 0267 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute 0268 * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn 0269 * clang: https://clang.llvm.org/docs/AttributeReference.html#id1 0270 */ 0271 #define __noreturn __attribute__((__noreturn__)) 0272 0273 /* 0274 * Optional: not supported by gcc. 0275 * Optional: not supported by icc. 0276 * 0277 * clang: https://clang.llvm.org/docs/AttributeReference.html#overloadable 0278 */ 0279 #if __has_attribute(__overloadable__) 0280 # define __overloadable __attribute__((__overloadable__)) 0281 #else 0282 # define __overloadable 0283 #endif 0284 0285 /* 0286 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute 0287 * clang: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-packed-variable-attribute 0288 */ 0289 #define __packed __attribute__((__packed__)) 0290 0291 /* 0292 * Note: the "type" argument should match any __builtin_object_size(p, type) usage. 0293 * 0294 * Optional: not supported by gcc. 0295 * Optional: not supported by icc. 0296 * 0297 * clang: https://clang.llvm.org/docs/AttributeReference.html#pass-object-size-pass-dynamic-object-size 0298 */ 0299 #if __has_attribute(__pass_object_size__) 0300 # define __pass_object_size(type) __attribute__((__pass_object_size__(type))) 0301 #else 0302 # define __pass_object_size(type) 0303 #endif 0304 0305 /* 0306 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute 0307 */ 0308 #define __pure __attribute__((__pure__)) 0309 0310 /* 0311 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute 0312 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute 0313 * clang: https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate 0314 */ 0315 #define __section(section) __attribute__((__section__(section))) 0316 0317 /* 0318 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-unused-function-attribute 0319 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-unused-type-attribute 0320 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-unused-variable-attribute 0321 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-unused-label-attribute 0322 * clang: https://clang.llvm.org/docs/AttributeReference.html#maybe-unused-unused 0323 */ 0324 #define __always_unused __attribute__((__unused__)) 0325 #define __maybe_unused __attribute__((__unused__)) 0326 0327 /* 0328 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-used-function-attribute 0329 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-used-variable-attribute 0330 */ 0331 #define __used __attribute__((__used__)) 0332 0333 /* 0334 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warn_005funused_005fresult-function-attribute 0335 * clang: https://clang.llvm.org/docs/AttributeReference.html#nodiscard-warn-unused-result 0336 */ 0337 #define __must_check __attribute__((__warn_unused_result__)) 0338 0339 /* 0340 * Optional: only supported since clang >= 14.0 0341 * 0342 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warning-function-attribute 0343 */ 0344 #if __has_attribute(__warning__) 0345 # define __compiletime_warning(msg) __attribute__((__warning__(msg))) 0346 #else 0347 # define __compiletime_warning(msg) 0348 #endif 0349 0350 /* 0351 * Optional: only supported since clang >= 14.0 0352 * 0353 * clang: https://clang.llvm.org/docs/AttributeReference.html#disable-sanitizer-instrumentation 0354 * 0355 * disable_sanitizer_instrumentation is not always similar to 0356 * no_sanitize((<sanitizer-name>)): the latter may still let specific sanitizers 0357 * insert code into functions to prevent false positives. Unlike that, 0358 * disable_sanitizer_instrumentation prevents all kinds of instrumentation to 0359 * functions with the attribute. 0360 */ 0361 #if __has_attribute(disable_sanitizer_instrumentation) 0362 # define __disable_sanitizer_instrumentation \ 0363 __attribute__((disable_sanitizer_instrumentation)) 0364 #else 0365 # define __disable_sanitizer_instrumentation 0366 #endif 0367 0368 /* 0369 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-weak-function-attribute 0370 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-weak-variable-attribute 0371 */ 0372 #define __weak __attribute__((__weak__)) 0373 0374 #endif /* __LINUX_COMPILER_ATTRIBUTES_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |