diff options
| author | rillig <rillig@NetBSD.org> | 2023-07-08 15:26:25 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-07-08 15:26:25 +0000 |
| commit | 65989024f874330227db7d9793fa78cab7c0ee2f (patch) | |
| tree | 74bc338956dbc13d05596e6fdabb684576902ce9 | |
| parent | 06c86f587bc97ca18607602ed3345db07a0dacd8 (diff) | |
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.
| -rw-r--r-- | tests/usr.bin/xlint/lint1/msg_247_portable.c | 3 | ||||
| -rw-r--r-- | tests/usr.bin/xlint/lint1/platform_ilp32_long.c | 16 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/tree.c | 13 |
3 files changed, 17 insertions, 15 deletions
diff --git a/tests/usr.bin/xlint/lint1/msg_247_portable.c b/tests/usr.bin/xlint/lint1/msg_247_portable.c index 29025f56fc3..028a41b5131 100644 --- a/tests/usr.bin/xlint/lint1/msg_247_portable.c +++ b/tests/usr.bin/xlint/lint1/msg_247_portable.c @@ -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 --git a/tests/usr.bin/xlint/lint1/platform_ilp32_long.c b/tests/usr.bin/xlint/lint1/platform_ilp32_long.c index 5a1fb977719..c2c46d9f5fe 100644 --- a/tests/usr.bin/xlint/lint1/platform_ilp32_long.c +++ b/tests/usr.bin/xlint/lint1/platform_ilp32_long.c @@ -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 --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 5bda4bf4e62..9da4e6c1e9f 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -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, int arg, tspec_t nt, tspec_t ot, (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 ... */ |
