summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-07-03 21:36:16 +0000
committerrillig <rillig@NetBSD.org>2023-07-03 21:36:16 +0000
commit70bab06713c1a381554b075e4b94a5eaefa1608b (patch)
tree0097d583b87d60332fc0b048f97bd265f4d2c2f4 /usr.bin
parentb16761f898d61c9a55b63f495693c1df8f8542e0 (diff)
lint: consistently use portable type size in integer constraints
Since tree.c 1.546 from 2023-07-03, lint no longer warned about possible loss of accuracy when converting from 'long' to 'int' on an ILP32 platform that uses 'unsigned long' for size_t, when run in portable mode (-p), which is enabled by default in the NetBSD build. The integer constraints avoid false-positive warnings by looking at the actual values an expression can take. The function can_represent is guarded by a condition that uses the portable_size_in_bits, but then internally used the opposite size_in_bits, which led to inconsistent results. The warning looks confusing though, as on an ILP32 platform, 'int' and 'long' have the same size and representation, therefore there cannot be an actual loss of accuracy. The warning may need to be reworded to explicitly mention the portability mode, in which sizeof(int) is assumed to be 3 instead of 4, to catch possible loss of accuracy on other platforms.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xlint/lint1/tree.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c
index 17c69fbfe35..c86812ec726 100644
--- a/usr.bin/xlint/lint1/tree.c
+++ b/usr.bin/xlint/lint1/tree.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.546 2023/07/03 07:19:57 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.547 2023/07/03 21:36:16 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.546 2023/07/03 07:19:57 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.547 2023/07/03 21:36:16 rillig Exp $");
#endif
#include <float.h>
@@ -95,7 +95,7 @@ width_in_bits(const type_t *tp)
lint_assert(is_integer(tp->t_tspec));
return tp->t_bitfield
? tp->t_bit_field_width
- : size_in_bits(tp->t_tspec);
+ : portable_size_in_bits(tp->t_tspec);
}
static bool