|
46 | 46 | * comparison, and these expressions only need to be careful to not cause
|
47 | 47 | * warnings for pointer use.
|
48 | 48 | */
|
49 |
| -#define __signed_type_use(ux) (2 + __is_nonneg(ux)) |
50 |
| -#define __unsigned_type_use(ux) (1 + 2 * (sizeof(ux) < 4)) |
51 | 49 | #define __sign_use(ux) (is_signed_type(typeof(ux)) ? \
|
52 |
| - __signed_type_use(ux) : __unsigned_type_use(ux)) |
| 50 | + (2 + __is_nonneg(ux)) : (1 + 2 * (sizeof(ux) < 4))) |
53 | 51 |
|
54 | 52 | /*
|
55 | 53 | * Check whether a signed value is always non-negative.
|
56 | 54 | *
|
57 | 55 | * A cast is needed to avoid any warnings from values that aren't signed
|
58 | 56 | * integer types (in which case the result doesn't matter).
|
59 | 57 | *
|
60 |
| - * On 64-bit any integer or pointer type can safely be cast to 'long'. |
| 58 | + * On 64-bit any integer or pointer type can safely be cast to 'long long'. |
61 | 59 | * But on 32-bit we need to avoid warnings about casting pointers to integers
|
62 | 60 | * of different sizes without truncating 64-bit values so 'long' or 'long long'
|
63 | 61 | * must be used depending on the size of the value.
|
|
66 | 64 | * them, but we do not use s128 types in the kernel (we do use 'u128',
|
67 | 65 | * but they are handled by the !is_signed_type() case).
|
68 | 66 | */
|
69 |
| -#ifdef CONFIG_64BIT |
70 |
| - #define __signed_type(ux) long |
| 67 | +#if __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__ |
| 68 | +#define __is_nonneg(ux) statically_true((long long)(ux) >= 0) |
71 | 69 | #else
|
72 |
| - #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)) |
| 70 | +#define __is_nonneg(ux) statically_true( \ |
| 71 | + (typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)))(ux) >= 0) |
73 | 72 | #endif
|
74 |
| -#define __is_nonneg(ux) statically_true((__signed_type(ux))(ux) >= 0) |
75 | 73 |
|
76 | 74 | #define __types_ok(ux, uy) \
|
77 | 75 | (__sign_use(ux) & __sign_use(uy))
|
|
0 commit comments