GCC and Clang's current RFCs name this attribute "counted_by", and have moved away from using a string for the member name. Update the kernel's macros to match. Additionally provide a UAPI no-op macro for UAPI structs that will gain annotations.
Unified · Split
| @@ -94,6 +94,19 @@ · 93 unmodified lines | |||
| 94 | # define __copy(symbol) | 94 | # define __copy(symbol) |
| 95 | #endif | 95 | #endif |
| 96 | 96 | ||
| 97 | /* | ||
| 98 | * Optional: only supported since gcc >= 14 | ||
| 99 | * Optional: only supported since clang >= 18 | ||
| 100 | * | ||
| 101 | * gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 | ||
| 102 | * clang: https://reviews.llvm.org/D148381 | ||
| 103 | */ | ||
| 104 | #if __has_attribute(__counted_by__) | ||
| 105 | # define __counted_by(member) __attribute__((__counted_by__(member))) | ||
| 106 | #else | ||
| 107 | # define __counted_by(member) | ||
| 108 | #endif | ||
| 109 | |||
| 97 | /* | 110 | /* |
| 98 | * Optional: not supported by gcc | 111 | * Optional: not supported by gcc |
| 99 | * Optional: only supported since clang >= 14.0 | 112 | * Optional: only supported since clang >= 14.0 |
| @@ -129,19 +142,6 @@ · 29 unmodified lines | |||
| 129 | # define __designated_init | 142 | # define __designated_init |
| 130 | #endif | 143 | #endif |
| 131 | 144 | ||
| 132 | /* | ||
| 133 | * Optional: only supported since gcc >= 14 | ||
| 134 | * Optional: only supported since clang >= 17 | ||
| 135 | * | ||
| 136 | * gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 | ||
| 137 | * clang: https://reviews.llvm.org/D148381 | ||
| 138 | */ | ||
| 139 | #if __has_attribute(__element_count__) | ||
| 140 | # define __counted_by(member) __attribute__((__element_count__(#member))) | ||
| 141 | #else | ||
| 142 | # define __counted_by(member) | ||
| 143 | #endif | ||
| 144 | |||
| 145 | /* | 145 | /* |
| 146 | * Optional: only supported since clang >= 14.0 | 146 | * Optional: only supported since clang >= 14.0 |
| 147 | * | 147 | * |
| @@ -45,3 +45,7 @@ · 44 unmodified lines | |||
| 45 | TYPE NAME[]; \ | 45 | TYPE NAME[]; \ |
| 46 | } | 46 | } |
| 47 | #endif | 47 | #endif |
| 48 | |||
| 49 | #ifndef __counted_by | ||
| 50 | #define __counted_by(m) | ||
| 51 | #endif | ||