Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add more examples for ...
details: https://anonhg.NetBSD.org/src/rev/8e5bdec32401
branches: trunk
changeset: 371894:8e5bdec32401
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Oct 15 21:19:15 2022 +0000
description:
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.
diffstat:
tests/usr.bin/xlint/lint1/msg_309.c | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diffs (43 lines):
diff -r 8a44c7ad39dd -r 8e5bdec32401 tests/usr.bin/xlint/lint1/msg_309.c
--- a/tests/usr.bin/xlint/lint1/msg_309.c Sat Oct 15 20:11:44 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_309.c Sat Oct 15 21:19:15 2022 +0000
@@ -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]
@@ -25,6 +25,33 @@
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.
*/
Home |
Main Index |
Thread Index |
Old Index