1*f412fd2aSLoGin #pragma once 2*f412fd2aSLoGin /* SPDX-License-Identifier: GPL-2.0 */ 3*f412fd2aSLoGin #ifndef __LINUX_COMPILER_ATTRIBUTES_H 4*f412fd2aSLoGin #define __LINUX_COMPILER_ATTRIBUTES_H 5*f412fd2aSLoGin 6*f412fd2aSLoGin /* 7*f412fd2aSLoGin * The attributes in this file are unconditionally defined and they directly 8*f412fd2aSLoGin * map to compiler attribute(s), unless one of the compilers does not support 9*f412fd2aSLoGin * the attribute. In that case, __has_attribute is used to check for support 10*f412fd2aSLoGin * and the reason is stated in its comment ("Optional: ..."). 11*f412fd2aSLoGin * 12*f412fd2aSLoGin * Any other "attributes" (i.e. those that depend on a configuration option, 13*f412fd2aSLoGin * on a compiler, on an architecture, on plugins, on other attributes...) 14*f412fd2aSLoGin * should be defined elsewhere (e.g. compiler_types.h or compiler-*.h). 15*f412fd2aSLoGin * The intention is to keep this file as simple as possible, as well as 16*f412fd2aSLoGin * compiler- and version-agnostic (e.g. avoiding GCC_VERSION checks). 17*f412fd2aSLoGin * 18*f412fd2aSLoGin * This file is meant to be sorted (by actual attribute name, 19*f412fd2aSLoGin * not by #define identifier). Use the __attribute__((__name__)) syntax 20*f412fd2aSLoGin * (i.e. with underscores) to avoid future collisions with other macros. 21*f412fd2aSLoGin * Provide links to the documentation of each supported compiler, if it exists. 22*f412fd2aSLoGin */ 23*f412fd2aSLoGin 24*f412fd2aSLoGin /* 25*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alias-function-attribute 26*f412fd2aSLoGin */ 27*f412fd2aSLoGin #define __alias(symbol) __attribute__((__alias__(#symbol))) 28*f412fd2aSLoGin 29*f412fd2aSLoGin /* 30*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-aligned-function-attribute 31*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-aligned-type-attribute 32*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-aligned-variable-attribute 33*f412fd2aSLoGin */ 34*f412fd2aSLoGin #define __aligned(x) __attribute__((__aligned__(x))) 35*f412fd2aSLoGin #define __aligned_largest __attribute__((__aligned__)) 36*f412fd2aSLoGin 37*f412fd2aSLoGin /* 38*f412fd2aSLoGin * Note: do not use this directly. Instead, use __alloc_size() since it is conditionally 39*f412fd2aSLoGin * available and includes other attributes. For GCC < 9.1, __alloc_size__ gets undefined 40*f412fd2aSLoGin * in compiler-gcc.h, due to misbehaviors. 41*f412fd2aSLoGin * 42*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute 43*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#alloc-size 44*f412fd2aSLoGin */ 45*f412fd2aSLoGin #define __alloc_size__(x, ...) __attribute__((__alloc_size__(x, ##__VA_ARGS__))) 46*f412fd2aSLoGin 47*f412fd2aSLoGin /* 48*f412fd2aSLoGin * Note: users of __always_inline currently do not write "inline" themselves, 49*f412fd2aSLoGin * which seems to be required by gcc to apply the attribute according 50*f412fd2aSLoGin * to its docs (and also "warning: always_inline function might not be 51*f412fd2aSLoGin * inlinable [-Wattributes]" is emitted). 52*f412fd2aSLoGin * 53*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute 54*f412fd2aSLoGin * clang: mentioned 55*f412fd2aSLoGin */ 56*f412fd2aSLoGin #define __always_inline inline __attribute__((__always_inline__)) 57*f412fd2aSLoGin 58*f412fd2aSLoGin /* 59*f412fd2aSLoGin * The second argument is optional (default 0), so we use a variadic macro 60*f412fd2aSLoGin * to make the shorthand. 61*f412fd2aSLoGin * 62*f412fd2aSLoGin * Beware: Do not apply this to functions which may return 63*f412fd2aSLoGin * ERR_PTRs. Also, it is probably unwise to apply it to functions 64*f412fd2aSLoGin * returning extra information in the low bits (but in that case the 65*f412fd2aSLoGin * compiler should see some alignment anyway, when the return value is 66*f412fd2aSLoGin * massaged by 'flags = ptr & 3; ptr &= ~3;'). 67*f412fd2aSLoGin * 68*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-assume_005faligned-function-attribute 69*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#assume-aligned 70*f412fd2aSLoGin */ 71*f412fd2aSLoGin #define __assume_aligned(a, ...) \ 72*f412fd2aSLoGin __attribute__((__assume_aligned__(a, ##__VA_ARGS__))) 73*f412fd2aSLoGin 74*f412fd2aSLoGin /* 75*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-cleanup-variable-attribute 76*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#cleanup 77*f412fd2aSLoGin */ 78*f412fd2aSLoGin #define __cleanup(func) __attribute__((__cleanup__(func))) 79*f412fd2aSLoGin 80*f412fd2aSLoGin /* 81*f412fd2aSLoGin * Note the long name. 82*f412fd2aSLoGin * 83*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute 84*f412fd2aSLoGin */ 85*f412fd2aSLoGin #define __attribute_const__ __attribute__((__const__)) 86*f412fd2aSLoGin 87*f412fd2aSLoGin /* 88*f412fd2aSLoGin * Optional: only supported since gcc >= 9 89*f412fd2aSLoGin * Optional: not supported by clang 90*f412fd2aSLoGin * 91*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-copy-function-attribute 92*f412fd2aSLoGin */ 93*f412fd2aSLoGin #if __has_attribute(__copy__) 94*f412fd2aSLoGin #define __copy(symbol) __attribute__((__copy__(symbol))) 95*f412fd2aSLoGin #else 96*f412fd2aSLoGin #define __copy(symbol) 97*f412fd2aSLoGin #endif 98*f412fd2aSLoGin 99*f412fd2aSLoGin /* 100*f412fd2aSLoGin * Optional: only supported since gcc >= 14 101*f412fd2aSLoGin * Optional: only supported since clang >= 18 102*f412fd2aSLoGin * 103*f412fd2aSLoGin * gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 104*f412fd2aSLoGin * clang: https://reviews.llvm.org/D148381 105*f412fd2aSLoGin */ 106*f412fd2aSLoGin #if __has_attribute(__counted_by__) 107*f412fd2aSLoGin #define __counted_by(member) __attribute__((__counted_by__(member))) 108*f412fd2aSLoGin #else 109*f412fd2aSLoGin #define __counted_by(member) 110*f412fd2aSLoGin #endif 111*f412fd2aSLoGin 112*f412fd2aSLoGin /* 113*f412fd2aSLoGin * Optional: not supported by gcc 114*f412fd2aSLoGin * Optional: only supported since clang >= 14.0 115*f412fd2aSLoGin * 116*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#diagnose_as_builtin 117*f412fd2aSLoGin */ 118*f412fd2aSLoGin #if __has_attribute(__diagnose_as_builtin__) 119*f412fd2aSLoGin #define __diagnose_as(builtin...) \ 120*f412fd2aSLoGin __attribute__((__diagnose_as_builtin__(builtin))) 121*f412fd2aSLoGin #else 122*f412fd2aSLoGin #define __diagnose_as(builtin...) 123*f412fd2aSLoGin #endif 124*f412fd2aSLoGin 125*f412fd2aSLoGin /* 126*f412fd2aSLoGin * Don't. Just don't. See commit 771c035372a0 ("deprecate the '__deprecated' 127*f412fd2aSLoGin * attribute warnings entirely and for good") for more information. 128*f412fd2aSLoGin * 129*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute 130*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-deprecated-type-attribute 131*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-deprecated-variable-attribute 132*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html#index-deprecated-enumerator-attribute 133*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#deprecated 134*f412fd2aSLoGin */ 135*f412fd2aSLoGin #define __deprecated 136*f412fd2aSLoGin 137*f412fd2aSLoGin /* 138*f412fd2aSLoGin * Optional: not supported by clang 139*f412fd2aSLoGin * 140*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-designated_005finit-type-attribute 141*f412fd2aSLoGin */ 142*f412fd2aSLoGin #if __has_attribute(__designated_init__) 143*f412fd2aSLoGin #define __designated_init __attribute__((__designated_init__)) 144*f412fd2aSLoGin #else 145*f412fd2aSLoGin #define __designated_init 146*f412fd2aSLoGin #endif 147*f412fd2aSLoGin 148*f412fd2aSLoGin /* 149*f412fd2aSLoGin * Optional: only supported since clang >= 14.0 150*f412fd2aSLoGin * 151*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-error-function-attribute 152*f412fd2aSLoGin */ 153*f412fd2aSLoGin #if __has_attribute(__error__) 154*f412fd2aSLoGin #define __compiletime_error(msg) __attribute__((__error__(msg))) 155*f412fd2aSLoGin #else 156*f412fd2aSLoGin #define __compiletime_error(msg) 157*f412fd2aSLoGin #endif 158*f412fd2aSLoGin 159*f412fd2aSLoGin /* 160*f412fd2aSLoGin * Optional: not supported by clang 161*f412fd2aSLoGin * 162*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-externally_005fvisible-function-attribute 163*f412fd2aSLoGin */ 164*f412fd2aSLoGin #if __has_attribute(__externally_visible__) 165*f412fd2aSLoGin #define __visible __attribute__((__externally_visible__)) 166*f412fd2aSLoGin #else 167*f412fd2aSLoGin #define __visible 168*f412fd2aSLoGin #endif 169*f412fd2aSLoGin 170*f412fd2aSLoGin /* 171*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-format-function-attribute 172*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#format 173*f412fd2aSLoGin */ 174*f412fd2aSLoGin #define __printf(a, b) __attribute__((__format__(printf, a, b))) 175*f412fd2aSLoGin #define __scanf(a, b) __attribute__((__format__(scanf, a, b))) 176*f412fd2aSLoGin 177*f412fd2aSLoGin /* 178*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-gnu_005finline-function-attribute 179*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#gnu-inline 180*f412fd2aSLoGin */ 181*f412fd2aSLoGin #define __gnu_inline __attribute__((__gnu_inline__)) 182*f412fd2aSLoGin 183*f412fd2aSLoGin /* 184*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute 185*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#malloc 186*f412fd2aSLoGin */ 187*f412fd2aSLoGin #define __malloc __attribute__((__malloc__)) 188*f412fd2aSLoGin 189*f412fd2aSLoGin /* 190*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-mode-type-attribute 191*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-mode-variable-attribute 192*f412fd2aSLoGin */ 193*f412fd2aSLoGin #define __mode(x) __attribute__((__mode__(x))) 194*f412fd2aSLoGin 195*f412fd2aSLoGin /* 196*f412fd2aSLoGin * Optional: only supported since gcc >= 7 197*f412fd2aSLoGin * 198*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#index-no_005fcaller_005fsaved_005fregisters-function-attribute_002c-x86 199*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#no-caller-saved-registers 200*f412fd2aSLoGin */ 201*f412fd2aSLoGin #if __has_attribute(__no_caller_saved_registers__) 202*f412fd2aSLoGin #define __no_caller_saved_registers \ 203*f412fd2aSLoGin __attribute__((__no_caller_saved_registers__)) 204*f412fd2aSLoGin #else 205*f412fd2aSLoGin #define __no_caller_saved_registers 206*f412fd2aSLoGin #endif 207*f412fd2aSLoGin 208*f412fd2aSLoGin /* 209*f412fd2aSLoGin * Optional: not supported by clang 210*f412fd2aSLoGin * 211*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noclone-function-attribute 212*f412fd2aSLoGin */ 213*f412fd2aSLoGin #if __has_attribute(__noclone__) 214*f412fd2aSLoGin #define __noclone __attribute__((__noclone__)) 215*f412fd2aSLoGin #else 216*f412fd2aSLoGin #define __noclone 217*f412fd2aSLoGin #endif 218*f412fd2aSLoGin 219*f412fd2aSLoGin /* 220*f412fd2aSLoGin * Add the pseudo keyword 'fallthrough' so case statement blocks 221*f412fd2aSLoGin * must end with any of these keywords: 222*f412fd2aSLoGin * break; 223*f412fd2aSLoGin * fallthrough; 224*f412fd2aSLoGin * continue; 225*f412fd2aSLoGin * goto <label>; 226*f412fd2aSLoGin * return [expression]; 227*f412fd2aSLoGin * 228*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes 229*f412fd2aSLoGin */ 230*f412fd2aSLoGin #if __has_attribute(__fallthrough__) 231*f412fd2aSLoGin #define fallthrough __attribute__((__fallthrough__)) 232*f412fd2aSLoGin #else 233*f412fd2aSLoGin #define fallthrough \ 234*f412fd2aSLoGin do { \ 235*f412fd2aSLoGin } while (0) /* fallthrough */ 236*f412fd2aSLoGin #endif 237*f412fd2aSLoGin 238*f412fd2aSLoGin /* 239*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes 240*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#flatten 241*f412fd2aSLoGin */ 242*f412fd2aSLoGin #define __flatten __attribute__((flatten)) 243*f412fd2aSLoGin 244*f412fd2aSLoGin /* 245*f412fd2aSLoGin * Note the missing underscores. 246*f412fd2aSLoGin * 247*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute 248*f412fd2aSLoGin * clang: mentioned 249*f412fd2aSLoGin */ 250*f412fd2aSLoGin #define noinline __attribute__((__noinline__)) 251*f412fd2aSLoGin 252*f412fd2aSLoGin /* 253*f412fd2aSLoGin * Optional: only supported since gcc >= 8 254*f412fd2aSLoGin * Optional: not supported by clang 255*f412fd2aSLoGin * 256*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-nonstring-variable-attribute 257*f412fd2aSLoGin */ 258*f412fd2aSLoGin #if __has_attribute(__nonstring__) 259*f412fd2aSLoGin #define __nonstring __attribute__((__nonstring__)) 260*f412fd2aSLoGin #else 261*f412fd2aSLoGin #define __nonstring 262*f412fd2aSLoGin #endif 263*f412fd2aSLoGin 264*f412fd2aSLoGin /* 265*f412fd2aSLoGin * Optional: only supported since GCC >= 7.1, clang >= 13.0. 266*f412fd2aSLoGin * 267*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute 268*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function 269*f412fd2aSLoGin */ 270*f412fd2aSLoGin #if __has_attribute(__no_profile_instrument_function__) 271*f412fd2aSLoGin #define __no_profile __attribute__((__no_profile_instrument_function__)) 272*f412fd2aSLoGin #else 273*f412fd2aSLoGin #define __no_profile 274*f412fd2aSLoGin #endif 275*f412fd2aSLoGin 276*f412fd2aSLoGin /* 277*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute 278*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn 279*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#id1 280*f412fd2aSLoGin */ 281*f412fd2aSLoGin #define __noreturn __attribute__((__noreturn__)) 282*f412fd2aSLoGin 283*f412fd2aSLoGin /* 284*f412fd2aSLoGin * Optional: only supported since GCC >= 11.1, clang >= 7.0. 285*f412fd2aSLoGin * 286*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fstack_005fprotector-function-attribute 287*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#no-stack-protector-safebuffers 288*f412fd2aSLoGin */ 289*f412fd2aSLoGin #if __has_attribute(__no_stack_protector__) 290*f412fd2aSLoGin #define __no_stack_protector __attribute__((__no_stack_protector__)) 291*f412fd2aSLoGin #else 292*f412fd2aSLoGin #define __no_stack_protector 293*f412fd2aSLoGin #endif 294*f412fd2aSLoGin 295*f412fd2aSLoGin /* 296*f412fd2aSLoGin * Optional: not supported by gcc. 297*f412fd2aSLoGin * 298*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#overloadable 299*f412fd2aSLoGin */ 300*f412fd2aSLoGin #if __has_attribute(__overloadable__) 301*f412fd2aSLoGin #define __overloadable __attribute__((__overloadable__)) 302*f412fd2aSLoGin #else 303*f412fd2aSLoGin #define __overloadable 304*f412fd2aSLoGin #endif 305*f412fd2aSLoGin 306*f412fd2aSLoGin /* 307*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute 308*f412fd2aSLoGin * clang: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-packed-variable-attribute 309*f412fd2aSLoGin */ 310*f412fd2aSLoGin #define __packed __attribute__((__packed__)) 311*f412fd2aSLoGin 312*f412fd2aSLoGin /* 313*f412fd2aSLoGin * Note: the "type" argument should match any __builtin_object_size(p, type) usage. 314*f412fd2aSLoGin * 315*f412fd2aSLoGin * Optional: not supported by gcc. 316*f412fd2aSLoGin * 317*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#pass-object-size-pass-dynamic-object-size 318*f412fd2aSLoGin */ 319*f412fd2aSLoGin #if __has_attribute(__pass_dynamic_object_size__) 320*f412fd2aSLoGin #define __pass_dynamic_object_size(type) \ 321*f412fd2aSLoGin __attribute__((__pass_dynamic_object_size__(type))) 322*f412fd2aSLoGin #else 323*f412fd2aSLoGin #define __pass_dynamic_object_size(type) 324*f412fd2aSLoGin #endif 325*f412fd2aSLoGin #if __has_attribute(__pass_object_size__) 326*f412fd2aSLoGin #define __pass_object_size(type) __attribute__((__pass_object_size__(type))) 327*f412fd2aSLoGin #else 328*f412fd2aSLoGin #define __pass_object_size(type) 329*f412fd2aSLoGin #endif 330*f412fd2aSLoGin 331*f412fd2aSLoGin /* 332*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute 333*f412fd2aSLoGin */ 334*f412fd2aSLoGin #define __pure __attribute__((__pure__)) 335*f412fd2aSLoGin 336*f412fd2aSLoGin /* 337*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute 338*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute 339*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate 340*f412fd2aSLoGin */ 341*f412fd2aSLoGin #define __section(section) __attribute__((__section__(section))) 342*f412fd2aSLoGin 343*f412fd2aSLoGin /* 344*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-unused-function-attribute 345*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-unused-type-attribute 346*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-unused-variable-attribute 347*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html#index-unused-label-attribute 348*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#maybe-unused-unused 349*f412fd2aSLoGin */ 350*f412fd2aSLoGin #define __always_unused __attribute__((__unused__)) 351*f412fd2aSLoGin #define __maybe_unused __attribute__((__unused__)) 352*f412fd2aSLoGin 353*f412fd2aSLoGin /* 354*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-used-function-attribute 355*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-used-variable-attribute 356*f412fd2aSLoGin */ 357*f412fd2aSLoGin #define __used __attribute__((__used__)) 358*f412fd2aSLoGin 359*f412fd2aSLoGin /* 360*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warn_005funused_005fresult-function-attribute 361*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#nodiscard-warn-unused-result 362*f412fd2aSLoGin */ 363*f412fd2aSLoGin #define __must_check __attribute__((__warn_unused_result__)) 364*f412fd2aSLoGin 365*f412fd2aSLoGin /* 366*f412fd2aSLoGin * Optional: only supported since clang >= 14.0 367*f412fd2aSLoGin * 368*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warning-function-attribute 369*f412fd2aSLoGin */ 370*f412fd2aSLoGin #if __has_attribute(__warning__) 371*f412fd2aSLoGin #define __compiletime_warning(msg) __attribute__((__warning__(msg))) 372*f412fd2aSLoGin #else 373*f412fd2aSLoGin #define __compiletime_warning(msg) 374*f412fd2aSLoGin #endif 375*f412fd2aSLoGin 376*f412fd2aSLoGin /* 377*f412fd2aSLoGin * Optional: only supported since clang >= 14.0 378*f412fd2aSLoGin * 379*f412fd2aSLoGin * clang: https://clang.llvm.org/docs/AttributeReference.html#disable-sanitizer-instrumentation 380*f412fd2aSLoGin * 381*f412fd2aSLoGin * disable_sanitizer_instrumentation is not always similar to 382*f412fd2aSLoGin * no_sanitize((<sanitizer-name>)): the latter may still let specific sanitizers 383*f412fd2aSLoGin * insert code into functions to prevent false positives. Unlike that, 384*f412fd2aSLoGin * disable_sanitizer_instrumentation prevents all kinds of instrumentation to 385*f412fd2aSLoGin * functions with the attribute. 386*f412fd2aSLoGin */ 387*f412fd2aSLoGin #if __has_attribute(disable_sanitizer_instrumentation) 388*f412fd2aSLoGin #define __disable_sanitizer_instrumentation \ 389*f412fd2aSLoGin __attribute__((disable_sanitizer_instrumentation)) 390*f412fd2aSLoGin #else 391*f412fd2aSLoGin #define __disable_sanitizer_instrumentation 392*f412fd2aSLoGin #endif 393*f412fd2aSLoGin 394*f412fd2aSLoGin /* 395*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-weak-function-attribute 396*f412fd2aSLoGin * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-weak-variable-attribute 397*f412fd2aSLoGin */ 398*f412fd2aSLoGin #define __weak __attribute__((__weak__)) 399*f412fd2aSLoGin 400*f412fd2aSLoGin /* 401*f412fd2aSLoGin * Used by functions that use '__builtin_return_address'. These function 402*f412fd2aSLoGin * don't want to be splited or made inline, which can make 403*f412fd2aSLoGin * the '__builtin_return_address' get unexpected address. 404*f412fd2aSLoGin */ 405*f412fd2aSLoGin #define __fix_address noinline __noclone 406*f412fd2aSLoGin 407*f412fd2aSLoGin #endif /* __LINUX_COMPILER_ATTRIBUTES_H */ 408