Module Name:    src
Committed By:   rillig
Date:           Sat Jul  8 15:26:25 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_247_portable.c platform_ilp32_long.c
        src/usr.bin/xlint/lint1: tree.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_247_portable.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.552 -r1.553 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_247_portable.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247_portable.c:1.2 src/tests/usr.bin/xlint/lint1/msg_247_portable.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_247_portable.c:1.2	Wed Jul  5 11:42:14 2023
+++ src/tests/usr.bin/xlint/lint1/msg_247_portable.c	Sat Jul  8 15:26:25 2023
@@ -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];

Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.3	Mon Jul  3 21:36:16 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c	Sat Jul  8 15:26:25 2023
@@ -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;
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.552 src/usr.bin/xlint/lint1/tree.c:1.553
--- src/usr.bin/xlint/lint1/tree.c:1.552	Sat Jul  8 12:45:43 2023
+++ src/usr.bin/xlint/lint1/tree.c	Sat Jul  8 15:26:25 2023
@@ -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 ... */

Reply via email to