diff options
Diffstat (limited to 'gl/attribute.h')
| -rw-r--r-- | gl/attribute.h | 132 |
1 files changed, 110 insertions, 22 deletions
diff --git a/gl/attribute.h b/gl/attribute.h index 710341ba..c85412d9 100644 --- a/gl/attribute.h +++ b/gl/attribute.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* ATTRIBUTE_* macros for using attributes in GCC and similar compilers | 1 | /* ATTRIBUTE_* macros for using attributes in GCC and similar compilers |
| 2 | 2 | ||
| 3 | Copyright 2020-2024 Free Software Foundation, Inc. | 3 | Copyright 2020-2025 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This file is free software: you can redistribute it and/or modify | 5 | This file is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU Lesser General Public License as | 6 | it under the terms of the GNU Lesser General Public License as |
| @@ -20,12 +20,50 @@ | |||
| 20 | /* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_* | 20 | /* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_* |
| 21 | macros used within Gnulib. */ | 21 | macros used within Gnulib. */ |
| 22 | 22 | ||
| 23 | /* These attributes can be placed in two ways: | 23 | /* The placement of these attributes depends on the kind of declaration |
| 24 | - At the start of a declaration (i.e. even before storage-class | 24 | and, in some cases, also on the programming language (C vs. C++). |
| 25 | specifiers!); then they apply to all entities that are declared | 25 | |
| 26 | by the declaration. | 26 | In function declarations and function definitions: |
| 27 | - Immediately after the name of an entity being declared by the | 27 | |
| 28 | declaration; then they apply to that entity only. */ | 28 | * ATTRIBUTE_NOTHROW must come after the parameter list. |
| 29 | |||
| 30 | * The macros | ||
| 31 | ATTRIBUTE_CONST | ||
| 32 | ATTRIBUTE_PURE | ||
| 33 | DEPRECATED | ||
| 34 | MAYBE_UNUSED | ||
| 35 | NODISCARD | ||
| 36 | REPRODUCIBLE | ||
| 37 | UNSEQUENCED | ||
| 38 | must come before the return type, and more precisely: | ||
| 39 | - In a function declaration/definition without a storage-class | ||
| 40 | specifier: at the beginning of the declaration/definition. | ||
| 41 | - In a function declaration/definition with a storage-class | ||
| 42 | specifier: | ||
| 43 | - In C: before the storage-class specifier. | ||
| 44 | - In C++: between the storage-class specifier and the return type. | ||
| 45 | |||
| 46 | * The other macros can be placed | ||
| 47 | - Either | ||
| 48 | - In a function declaration/definition without a storage-class | ||
| 49 | specifier: at the beginning of the declaration/definition. | ||
| 50 | - In a function declaration/definition with a storage-class | ||
| 51 | specifier: between the storage-class specifier and the return | ||
| 52 | type. | ||
| 53 | - Or, in a function declaration: | ||
| 54 | after the parameter list, | ||
| 55 | ∙ but after ATTRIBUTE_NOTHROW if present. | ||
| 56 | |||
| 57 | In other declarations, such as variable declarations: | ||
| 58 | |||
| 59 | * Either | ||
| 60 | - In C: before the storage-class specifier. | ||
| 61 | - In C++: between the storage-class specifier and the return type. | ||
| 62 | Then they apply to all entities that are declared by the declaration. | ||
| 63 | |||
| 64 | * Or immediately after the name of an entity being declared by the | ||
| 65 | declaration. Then they apply to that entity only. | ||
| 66 | */ | ||
| 29 | 67 | ||
| 30 | #ifndef _GL_ATTRIBUTE_H | 68 | #ifndef _GL_ATTRIBUTE_H |
| 31 | #define _GL_ATTRIBUTE_H | 69 | #define _GL_ATTRIBUTE_H |
| @@ -48,9 +86,10 @@ | |||
| 48 | _GL_ATTRIBUTE_FALLTHROUGH, _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_LEAF, | 86 | _GL_ATTRIBUTE_FALLTHROUGH, _GL_ATTRIBUTE_FORMAT, _GL_ATTRIBUTE_LEAF, |
| 49 | _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_MAY_ALIAS, _GL_ATTRIBUTE_MAYBE_UNUSED, | 87 | _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_MAY_ALIAS, _GL_ATTRIBUTE_MAYBE_UNUSED, |
| 50 | _GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOINLINE, _GL_ATTRIBUTE_NONNULL, | 88 | _GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOINLINE, _GL_ATTRIBUTE_NONNULL, |
| 51 | _GL_ATTRIBUTE_NONSTRING, _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED, | 89 | _GL_ATTRIBUTE_NONNULL_IF_NONZERO, _GL_ATTRIBUTE_NONSTRING, |
| 52 | _GL_ATTRIBUTE_PURE, _GL_ATTRIBUTE_RETURNS_NONNULL, | 90 | _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PACKED, _GL_ATTRIBUTE_PURE, |
| 53 | _GL_ATTRIBUTE_SENTINEL. */ | 91 | _GL_ATTRIBUTE_REPRODUCIBLE, _GL_ATTRIBUTE_RETURNS_NONNULL, |
| 92 | _GL_ATTRIBUTE_SENTINEL, _GL_ATTRIBUTE_UNSEQUENCED. */ | ||
| 54 | #if !_GL_CONFIG_H_INCLUDED | 93 | #if !_GL_CONFIG_H_INCLUDED |
| 55 | #error "Please include config.h first." | 94 | #error "Please include config.h first." |
| 56 | #endif | 95 | #endif |
| @@ -88,7 +127,7 @@ | |||
| 88 | is the size of the returned memory block. | 127 | is the size of the returned memory block. |
| 89 | ATTRIBUTE_ALLOC_SIZE ((M, N)) - Multiply the Mth and Nth arguments | 128 | ATTRIBUTE_ALLOC_SIZE ((M, N)) - Multiply the Mth and Nth arguments |
| 90 | to determine the size of the returned memory block. */ | 129 | to determine the size of the returned memory block. */ |
| 91 | /* Applies to: function, pointer to function, function types. */ | 130 | /* Applies to: functions, pointer to functions, function types. */ |
| 92 | #define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE (args) | 131 | #define ATTRIBUTE_ALLOC_SIZE(args) _GL_ATTRIBUTE_ALLOC_SIZE (args) |
| 93 | 132 | ||
| 94 | /* ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers | 133 | /* ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers |
| @@ -132,6 +171,12 @@ | |||
| 132 | /* Applies to: functions. */ | 171 | /* Applies to: functions. */ |
| 133 | #define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL (args) | 172 | #define ATTRIBUTE_NONNULL(args) _GL_ATTRIBUTE_NONNULL (args) |
| 134 | 173 | ||
| 174 | /* ATTRIBUTE_NONNULL_IF_NONZERO (NP, NI) - Argument NP (a pointer) | ||
| 175 | must not be NULL if the argument NI (an integer) is != 0. */ | ||
| 176 | /* Applies to: functions. */ | ||
| 177 | #define ATTRIBUTE_NONNULL_IF_NONZERO(np, ni) _GL_ATTRIBUTE_NONNULL_IF_NONZERO (np, ni) | ||
| 178 | |||
| 179 | |||
| 135 | /* The function's return value is a non-NULL pointer. */ | 180 | /* The function's return value is a non-NULL pointer. */ |
| 136 | /* Applies to: functions. */ | 181 | /* Applies to: functions. */ |
| 137 | #define ATTRIBUTE_RETURNS_NONNULL _GL_ATTRIBUTE_RETURNS_NONNULL | 182 | #define ATTRIBUTE_RETURNS_NONNULL _GL_ATTRIBUTE_RETURNS_NONNULL |
| @@ -170,7 +215,7 @@ | |||
| 170 | /* Attributes regarding debugging information emitted by the compiler. */ | 215 | /* Attributes regarding debugging information emitted by the compiler. */ |
| 171 | 216 | ||
| 172 | /* Omit the function from stack traces when debugging. */ | 217 | /* Omit the function from stack traces when debugging. */ |
| 173 | /* Applies to: function. */ | 218 | /* Applies to: functions. */ |
| 174 | #define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL | 219 | #define ATTRIBUTE_ARTIFICIAL _GL_ATTRIBUTE_ARTIFICIAL |
| 175 | 220 | ||
| 176 | /* Make the entity visible to debuggers etc., even with '-fwhole-program'. */ | 221 | /* Make the entity visible to debuggers etc., even with '-fwhole-program'. */ |
| @@ -192,25 +237,68 @@ | |||
| 192 | 237 | ||
| 193 | /* Always inline the function, and report an error if the compiler | 238 | /* Always inline the function, and report an error if the compiler |
| 194 | cannot inline. */ | 239 | cannot inline. */ |
| 195 | /* Applies to: function. */ | 240 | /* Applies to: functions. */ |
| 196 | #define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE | 241 | #define ATTRIBUTE_ALWAYS_INLINE _GL_ATTRIBUTE_ALWAYS_INLINE |
| 197 | 242 | ||
| 198 | /* It is OK for a compiler to omit duplicate calls with the same arguments. | 243 | /* It is OK for a compiler to move calls to the function and to omit |
| 244 | calls to the function if another call has the same arguments or the | ||
| 245 | result is not used. | ||
| 199 | This attribute is safe for a function that neither depends on | 246 | This attribute is safe for a function that neither depends on |
| 200 | nor affects observable state, and always returns exactly once - | 247 | nor affects state, and always returns exactly once - |
| 201 | e.g., does not loop forever, and does not call longjmp. | 248 | e.g., does not raise an exception, call longjmp, or loop forever. |
| 202 | (This attribute is stricter than ATTRIBUTE_PURE.) */ | 249 | (This attribute is stricter than ATTRIBUTE_PURE because the |
| 250 | function cannot observe state. It is stricter than UNSEQUENCED | ||
| 251 | because the function must return exactly once and cannot depend on | ||
| 252 | state addressed by its arguments.) */ | ||
| 203 | /* Applies to: functions. */ | 253 | /* Applies to: functions. */ |
| 204 | #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST | 254 | #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST |
| 205 | 255 | ||
| 206 | /* It is OK for a compiler to omit duplicate calls with the same | 256 | /* It is OK for a compiler to move calls to the function and to omit duplicate |
| 207 | arguments if observable state is not changed between calls. | 257 | calls to the function with the same arguments, so long as the state |
| 208 | This attribute is safe for a function that does not affect | 258 | addressed by its arguments is the same. |
| 209 | observable state, and always returns exactly once. | 259 | This attribute is safe for a function that is effectless, idempotent, |
| 210 | (This attribute is looser than ATTRIBUTE_CONST.) */ | 260 | stateless, and independent; see ISO C 23 § 6.7.12.7 for a definition of |
| 261 | these terms. | ||
| 262 | (This attribute is stricter than REPRODUCIBLE because the function | ||
| 263 | must be stateless and independent. It is looser than ATTRIBUTE_CONST | ||
| 264 | because the function need not return exactly once and can depend | ||
| 265 | on state addressed by its arguments.) | ||
| 266 | See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and | ||
| 267 | <https://stackoverflow.com/questions/76847905/>. | ||
| 268 | ATTENTION! Efforts are underway to change the meaning of this attribute. | ||
| 269 | See <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3424.htm>. */ | ||
| 270 | /* Applies to: functions, pointer to functions, function type. */ | ||
| 271 | #define UNSEQUENCED _GL_ATTRIBUTE_UNSEQUENCED | ||
| 272 | |||
| 273 | /* It is OK for a compiler to move calls to the function and to omit | ||
| 274 | calls to the function if another call has the same arguments or the | ||
| 275 | result is not used, and if observable state is the same. | ||
| 276 | This attribute is safe for a function that does not affect observable state | ||
| 277 | and always returns exactly once. | ||
| 278 | (This attribute is looser than ATTRIBUTE_CONST because the function | ||
| 279 | can depend on observable state. It is stricter than REPRODUCIBLE | ||
| 280 | because the function must return exactly once and cannot affect | ||
| 281 | state addressed by its arguments.) */ | ||
| 211 | /* Applies to: functions. */ | 282 | /* Applies to: functions. */ |
| 212 | #define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE | 283 | #define ATTRIBUTE_PURE _GL_ATTRIBUTE_PURE |
| 213 | 284 | ||
| 285 | /* It is OK for a compiler to move calls to the function and to omit duplicate | ||
| 286 | calls to the function with the same arguments, so long as the state | ||
| 287 | addressed by its arguments is the same and is updated in time for | ||
| 288 | the rest of the program. | ||
| 289 | This attribute is safe for a function that is effectless and idempotent; see | ||
| 290 | ISO C 23 § 6.7.12.7 for a definition of these terms. | ||
| 291 | (This attribute is looser than UNSEQUENCED because the function need | ||
| 292 | not be stateless and idempotent. It is looser than ATTRIBUTE_PURE | ||
| 293 | because the function need not return exactly once and can affect | ||
| 294 | state addressed by its arguments.) | ||
| 295 | See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and | ||
| 296 | <https://stackoverflow.com/questions/76847905/>. | ||
| 297 | ATTENTION! Efforts are underway to change the meaning of this attribute. | ||
| 298 | See <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3424.htm>. */ | ||
| 299 | /* Applies to: functions, pointer to functions, function type. */ | ||
| 300 | #define REPRODUCIBLE _GL_ATTRIBUTE_REPRODUCIBLE | ||
| 301 | |||
| 214 | /* The function is rarely executed. */ | 302 | /* The function is rarely executed. */ |
| 215 | /* Applies to: functions. */ | 303 | /* Applies to: functions. */ |
| 216 | #define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD | 304 | #define ATTRIBUTE_COLD _GL_ATTRIBUTE_COLD |
