Since all compilers support __builtin_object_size(), and there is only one user of __compiletime_object_size, remove it to avoid the needless indirection. This lets Clang reason about check_copy_size() correctly.
Unified · Split
| @@ -41,8 +41,6 @@ · 40 unmodified lines | |||
| 41 | 41 | ||
| 42 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) | 42 | #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) |
| 43 | 43 | ||
| 44 | #define __compiletime_object_size(obj) __builtin_object_size(obj, 0) | ||
| 45 | |||
| 46 | #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) | 44 | #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__) |
| 47 | #define __latent_entropy __attribute__((latent_entropy)) | 45 | #define __latent_entropy __attribute__((latent_entropy)) |
| 48 | #endif | 46 | #endif |
| @@ -290,11 +290,6 @@ struct ftrace_likely_data { · 289 unmodified lines | |||
| 290 | (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ | 290 | (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ |
| 291 | sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) | 291 | sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) |
| 292 | 292 | ||
| 293 | /* Compile time object size, -1 for unknown */ | ||
| 294 | #ifndef __compiletime_object_size | ||
| 295 | # define __compiletime_object_size(obj) -1 | ||
| 296 | #endif | ||
| 297 | |||
| 298 | #ifdef __OPTIMIZE__ | 293 | #ifdef __OPTIMIZE__ |
| 299 | # define __compiletime_assert(condition, msg, prefix, suffix) \ | 294 | # define __compiletime_assert(condition, msg, prefix, suffix) \ |
| 300 | do { \ | 295 | do { \ |
| @@ -203,7 +203,7 @@ static inline void copy_overflow(int size, unsigned long count) · 202 unmodified lines | |||
| 203 | static __always_inline __must_check bool | 203 | static __always_inline __must_check bool |
| 204 | check_copy_size(const void *addr, size_t bytes, bool is_source) | 204 | check_copy_size(const void *addr, size_t bytes, bool is_source) |
| 205 | { | 205 | { |
| 206 | int sz = __compiletime_object_size(addr); | 206 | int sz = __builtin_object_size(addr, 0); |
| 207 | if (unlikely(sz >= 0 && sz < bytes)) { | 207 | if (unlikely(sz >= 0 && sz < bytes)) { |
| 208 | if (!__builtin_constant_p(bytes)) | 208 | if (!__builtin_constant_p(bytes)) |
| 209 | copy_overflow(sz, bytes); | 209 | copy_overflow(sz, bytes); |