![]() |
|
Message-ID: <20250624155451.GO1827@brightrain.aerifal.cx> Date: Tue, 24 Jun 2025 11:54:51 -0400 From: Rich Felker <dalias@...c.org> To: Jacob Abrams <satur9nine@...il.com> Cc: musl@...ts.openwall.com Subject: Re: [PATCH] endian.h: use parentheses to silence warnings On Tue, Jun 24, 2025 at 05:02:05PM +0800, Jacob Abrams wrote: > It would be nice to silence some warnings that arise from endian.h, for example: > > musl/include/endian.h:29:25: warning: '&' within '|' [-Wbitwise-op-parentheses] > 29 | return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; > | ~ ~~~~~~^~~~~~~ > musl/include/endian.h:29:25: note: place parentheses around the '&' > expression to silence this warning > 29 | return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; > | ^ > | ( ) > musl/include/endian.h:29:41: warning: '&' within '|' [-Wbitwise-op-parentheses] > 29 | return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; > | ~ ~~~~~~^~~~~~~~~ > musl/include/endian.h:29:41: note: place parentheses around the '&' > expression to silence this warning > 29 | return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; > | ^ > | ( ) > musl/include/endian.h:34:23: warning: operator '<<' has lower > precedence than '+'; '+' will be evaluated first > [-Wshift-op-parentheses] > 34 | return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32); > | ~~~~~~~~~~~~~~^~~~~~~ > musl/include/endian.h:34:23: note: place parentheses around the '+' > expression to silence this warning > 34 | return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32); > | ^ > | ( ) > > Note: I'm not subscribed to the mailing-list, so CCs are appreciated > --- > include/endian.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/endian.h b/include/endian.h > index 172c4320..2819c926 100644 > --- a/include/endian.h > +++ b/include/endian.h > @@ -18,17 +18,17 @@ > > static __inline uint16_t __bswap16(uint16_t __x) > { > - return __x<<8 | __x>>8; > + return (__x<<8) | (__x>>8); > } > > static __inline uint32_t __bswap32(uint32_t __x) > { > - return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; > + return (__x>>24) | ((__x>>8)&0xff00) | ((__x<<8)&0xff0000) | (__x<<24); > } > > static __inline uint64_t __bswap64(uint64_t __x) > { > - return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32); > + return ((__bswap32(__x)+0ULL)<<32) | __bswap32(__x>>32); > } > > #if __BYTE_ORDER == __LITTLE_ENDIAN > -- > 2.50.0 While there has been some discussion lately of trying to silence warnings from headers where GCC and clang are generating them even after properly processing them as "system headers", often because of how they treat argument to macro vs macro contents, the above seem to be generated purely from misuse of the headers, passing the location they're in with -I to a non-musl-targeting toolchain rather than using a properly configured toolchain where the libc headers are in the "-isystem" path. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.