tests/lint: add test for warning about zero-bits in '&'
This commit is contained in:
parent
60e7bdf08f
commit
fc2d694242
@ -1,7 +1,39 @@
|
||||
/* $NetBSD: msg_309.c,v 1.2 2021/02/21 09:07:58 rillig Exp $ */
|
||||
/* $NetBSD: msg_309.c,v 1.3 2021/05/16 10:08:01 rillig Exp $ */
|
||||
# 3 "msg_309.c"
|
||||
|
||||
// Test for message: extra bits set to 0 in conversion of '%s' to '%s', op %s [309]
|
||||
|
||||
TODO: "Add example code that triggers the above message." /* expect: 249 */
|
||||
TODO: "Add example code that almost triggers the above message."
|
||||
int
|
||||
scale(unsigned long long x) {
|
||||
|
||||
/*
|
||||
* Both operands of '&' have the same type, therefore no conversion
|
||||
* is necessary and no bits can get lost.
|
||||
*/
|
||||
if ((x & 0xffffffff00000000ULL) != 0)
|
||||
return 32;
|
||||
|
||||
/*
|
||||
* The constant has type 'unsigned 32-bit'. The usual arithmetic
|
||||
* conversions of '&' convert this constant to unsigned 64-bit.
|
||||
* The programmer may or may not have intended to sign-extend the
|
||||
* bit mask here. This situation may occur during migration from a
|
||||
* 32-bit to a 64-bit platform.
|
||||
*/
|
||||
if ((x & 0xffff0000) != 0) /* expect: 309 */
|
||||
return 16;
|
||||
|
||||
/*
|
||||
* In the remaining cases, the constant does not have its most
|
||||
* significant bit set, therefore there is no ambiguity.
|
||||
*/
|
||||
if ((x & 0xff00) != 0)
|
||||
return 8;
|
||||
if ((x & 0xf0) != 0)
|
||||
return 4;
|
||||
if ((x & 0xc) != 0)
|
||||
return 2;
|
||||
if ((x & 0x2) != 0)
|
||||
return 1;
|
||||
return (int)(x & 0x1);
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
msg_309.c(6): error: syntax error ':' [249]
|
||||
msg_309.c(23): warning: extra bits set to 0 in conversion of 'unsigned int' to 'unsigned long long', op & [309]
|
||||
|
Loading…
Reference in New Issue
Block a user