diff options
author | dim <dim@FreeBSD.org> | 2012-03-24 10:07:21 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-03-24 10:07:21 +0000 |
commit | 8973cd587b6f51cb8ed2d9a9b324a557f3acae5d (patch) | |
tree | 4ae142fb1cbf8c28f38623a4bd3831d086faac73 | |
parent | 679009409c43d8fc17a58b44b8f4c001d5cce2c5 (diff) | |
download | FreeBSD-src-8973cd587b6f51cb8ed2d9a9b324a557f3acae5d.zip FreeBSD-src-8973cd587b6f51cb8ed2d9a9b324a557f3acae5d.tar.gz |
Fix the following clang warning in sys/dev/dcons/dcons.c, caused by the
recent changes in sys/x86/include/endian.h:
sys/dev/dcons/dcons.c:190:15: error: implicit conversion from '__uint32_t' (aka 'unsigned int') to '__uint16_t' (aka 'unsigned short') changes value from 1684238190 to 28526 [-Werror,-Wconstant-conversion]
buf->magic = ntohl(DCONS_MAGIC);
^~~~~~~~~~~~~~~~~~
sys/sys/param.h:306:18: note: expanded from:
#define ntohl(x) __ntohl(x)
^
./x86/endian.h:128:20: note: expanded from:
#define __ntohl(x) __bswap32(x)
^
./x86/endian.h:78:20: note: expanded from:
__bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
^
./x86/endian.h:68:26: note: expanded from:
(((__uint32_t)__bswap16(x) << 16) | __bswap16((x) >> 16))
^
./x86/endian.h:75:53: note: expanded from:
__bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
~~~~~~~~~~~~~ ^
This is because the __bswapXX_gen() macros (for x86) call the regular
__bswapXX() macros. Since the __bswapXX_gen() variants are only called
when their arguments are constant, there is no need to do that constancy
check recursively. Also, it causes the above error with clang.
Fix it by calling __bswap16_gen() from __bswap32_gen(), and similarly,
__bswap32_gen() from __bswap64_gen().
While here, add extra parentheses around the __bswap16_gen() macro
expansion, to prevent unexpected side effects.
-rw-r--r-- | sys/x86/include/endian.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/x86/include/endian.h b/sys/x86/include/endian.h index 2f95320..9059587 100644 --- a/sys/x86/include/endian.h +++ b/sys/x86/include/endian.h @@ -63,11 +63,11 @@ #define BYTE_ORDER _BYTE_ORDER #endif -#define __bswap16_gen(x) (__uint16_t)((x) << 8 | (x) >> 8) +#define __bswap16_gen(x) ((__uint16_t)((x) << 8 | (x) >> 8)) #define __bswap32_gen(x) \ - (((__uint32_t)__bswap16(x) << 16) | __bswap16((x) >> 16)) + (((__uint32_t)__bswap16_gen(x) << 16) | __bswap16_gen((x) >> 16)) #define __bswap64_gen(x) \ - (((__uint64_t)__bswap32(x) << 32) | __bswap32((x) >> 32)) + (((__uint64_t)__bswap32_gen(x) << 32) | __bswap32_gen((x) >> 32)) #ifdef __GNUCLIKE_BUILTIN_CONSTANT_P #define __bswap16(x) \ |