Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: do not use portable type sizes in ...
details: https://anonhg.NetBSD.org/src/rev/0b53dad82bb2
branches: trunk
changeset: 377355:0b53dad82bb2
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jul 08 15:26:25 2023 +0000
description:
lint: do not use portable type sizes in integer constraints
This reverts the change from tree.c 1.547 from 2023-07-03. Back then, I
didn't know that the actual value from a type's 'portable size in bits'
was not supposed to be used.
diffstat:
tests/usr.bin/xlint/lint1/msg_247_portable.c | 3 ++-
tests/usr.bin/xlint/lint1/platform_ilp32_long.c | 16 +++++++++-------
usr.bin/xlint/lint1/tree.c | 13 ++++++-------
3 files changed, 17 insertions(+), 15 deletions(-)
diffs (91 lines):
diff -r c54c3ea935a5 -r 0b53dad82bb2 tests/usr.bin/xlint/lint1/msg_247_portable.c
--- a/tests/usr.bin/xlint/lint1/msg_247_portable.c Sat Jul 08 14:05:51 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247_portable.c Sat Jul 08 15:26:25 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_247_portable.c,v 1.2 2023/07/05 11:42:14 rillig Exp $ */
+/* $NetBSD: msg_247_portable.c,v 1.3 2023/07/08 15:26:25 rillig Exp $ */
# 3 "msg_247_portable.c"
// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
@@ -11,6 +11,7 @@
// msg_247_ilp32_ldbl64.c
// msg_247_lp64_ldbl128.c
+/* lint1-only-if: long */
/* lint1-extra-flags: -c -p -X 351 */
typedef double double_array[5];
diff -r c54c3ea935a5 -r 0b53dad82bb2 tests/usr.bin/xlint/lint1/platform_ilp32_long.c
--- a/tests/usr.bin/xlint/lint1/platform_ilp32_long.c Sat Jul 08 14:05:51 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/platform_ilp32_long.c Sat Jul 08 15:26:25 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: platform_ilp32_long.c,v 1.3 2023/07/03 21:36:16 rillig Exp $ */
+/* $NetBSD: platform_ilp32_long.c,v 1.4 2023/07/08 15:26:25 rillig Exp $ */
# 3 "platform_ilp32_long.c"
/*
@@ -22,15 +22,17 @@ void
convert_between_int_and_long(void)
{
/*
- * Even though 'long' and 'int' have the same size on this platform,
- * the option '-p' enables additional portability checks that assume
- * a 24-bit int and a 32-bit long type, to proactively detect loss of
- * accuracy on potential other platforms.
+ * The '-p' option enables checks that apply independently of the
+ * current platform, assuming that 'long' is always wider than 'int'.
+ * This assumption, when applied on its own, leads to wrong warnings
+ * that a 32-bit 'long' may lose accuracy when converted to a 32-bit
+ * 'int'.
+ *
+ * To avoid these, take a look at the actually possible values of the
+ * right-hand side, and if they fit in the left-hand side, don't warn.
*/
- /* expect+1: warning: conversion from 'long' to 'int' may lose accuracy [132] */
s32 = sl32;
sl32 = s32;
- /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
u32 = ul32;
ul32 = u32;
}
diff -r c54c3ea935a5 -r 0b53dad82bb2 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sat Jul 08 14:05:51 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sat Jul 08 15:26:25 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.552 2023/07/08 12:45:43 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.553 2023/07/08 15:26:25 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.552 2023/07/08 12:45:43 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.553 2023/07/08 15:26:25 rillig Exp $");
#endif
#include <float.h>
@@ -95,9 +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
- // FIXME: The rank of a type is only intended as a relative size,
- // its value is not to be taken literally.
- : type_properties(tp->t_tspec)->tt_rank;
+ : size_in_bits(tp->t_tspec);
}
static int
@@ -3450,8 +3448,9 @@ convert_integer_from_integer(op_t op, in
(portable_rank_cmp(ot, LONG) >= 0 || aflag > 1) &&
// XXX: The portable_rank_cmp above aims at portable mode,
// independent of the current platform, while can_represent acts
- // on the actual types from the current platform. This mix is
- // inconsistent.
+ // on the actual type sizes from the current platform. This mix
+ // is inconsistent, but anything else would make the exact
+ // conditions too complicated to grasp.
!can_represent(tp, tn)) {
if (op == FARG) {
/* conversion from '%s' to '%s' may lose ... */
Home |
Main Index |
Thread Index |
Old Index