summaryrefslogtreecommitdiff
path: root/tests
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 /tests
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 'tests')
-rw-r--r--tests/usr.bin/xlint/lint1/platform_ilp32_long.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tests/usr.bin/xlint/lint1/platform_ilp32_long.c b/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
index 5bb4efc78fa..5a1fb977719 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.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;
}