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: consistently use portable type siz...
details: https://anonhg.NetBSD.org/src/rev/fcb663bebc16
branches: trunk
changeset: 377255:fcb663bebc16
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Jul 03 21:36:16 2023 +0000
description:
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:
tests/usr.bin/xlint/lint1/platform_ilp32_long.c | 3 ++-
usr.bin/xlint/lint1/tree.c | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diffs (44 lines):
diff -r 0e0303ced590 -r fcb663bebc16 tests/usr.bin/xlint/lint1/platform_ilp32_long.c
--- a/tests/usr.bin/xlint/lint1/platform_ilp32_long.c Mon Jul 03 18:50:42 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/platform_ilp32_long.c Mon Jul 03 21:36:16 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: platform_ilp32_long.c,v 1.2 2023/03/28 14:44:35 rillig Exp $ */
+/* $NetBSD: platform_ilp32_long.c,v 1.3 2023/07/03 21:36:16 rillig Exp $ */
# 3 "platform_ilp32_long.c"
/*
@@ -30,6 +30,7 @@ convert_between_int_and_long(void)
/* 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 0e0303ced590 -r fcb663bebc16 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Mon Jul 03 18:50:42 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c Mon Jul 03 21:36:16 2023 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index