tests/lint: add more examples for 'extra bits set to 0'
Seen in sys/external/bsd/compiler_rt/dist/lib/builtins/fp_lib.h:88.
This commit is contained in:
parent
09afed1ac0
commit
ce87d2e53b
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msg_309.c,v 1.5 2022/06/17 06:59:16 rillig Exp $ */
|
||||
/* $NetBSD: msg_309.c,v 1.6 2022/10/15 21:19:15 rillig Exp $ */
|
||||
# 3 "msg_309.c"
|
||||
|
||||
// Test for message: extra bits set to 0 in conversion of '%s' to '%s', op '%s' [309]
|
||||
|
@ -24,6 +24,33 @@ scale(unsigned long long x) {
|
|||
if ((x & 0xffff0000) != 0)
|
||||
return 16;
|
||||
|
||||
/*
|
||||
* The integer constant is explicitly unsigned. Even in this case,
|
||||
* the code may have originated on a platform where 'x' had 32 bits
|
||||
* originally, and the intention may have been to clear the lower 16
|
||||
* bits.
|
||||
*/
|
||||
/* expect+1: warning: extra bits set to 0 in conversion of 'unsigned int' to 'unsigned long long', op '&' [309] */
|
||||
if ((x & 0xffff0000U) != 0)
|
||||
return 16;
|
||||
|
||||
/*
|
||||
* Even if the expression is written as '& ~', which makes the
|
||||
* intention of clearing the lower 16 bits clear, on a 32-bit
|
||||
* platform the integer constant stays at 32 bits, and when porting
|
||||
* the code to a 64-bit platform, the upper 32 bits are preserved.
|
||||
*/
|
||||
/* expect+1: warning: extra bits set to 0 in conversion of 'unsigned int' to 'unsigned long long', op '&' [309] */
|
||||
if ((x & ~0xffffU) != 0)
|
||||
return 16;
|
||||
|
||||
/*
|
||||
* Casting the integer constant to the proper type removes all
|
||||
* ambiguities about the programmer's intention.
|
||||
*/
|
||||
if ((x & (unsigned long long)~0xffffU) != 0)
|
||||
return 16;
|
||||
|
||||
/*
|
||||
* In the remaining cases, the constant does not have its most
|
||||
* significant bit set, therefore there is no ambiguity.
|
||||
|
|
Loading…
Reference in New Issue