Module Name:    src
Committed By:   rillig
Date:           Wed Mar 27 19:28:21 UTC 2024

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_167.c msg_168.c msg_187.c msg_199.c
            msg_200.c platform_ilp32.c
        src/usr.bin/xlint/lint1: err.c func.c init.c tree.c

Log Message:
lint: don't use 'long' in diagnostics

The size of 'long' differs between 64-bit and 32-bit platforms.
Eliminate this possible platform-dependency.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_167.c \
    src/tests/usr.bin/xlint/lint1/msg_187.c \
    src/tests/usr.bin/xlint/lint1/msg_200.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_168.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_199.c \
    src/tests/usr.bin/xlint/lint1/platform_ilp32.c
cvs rdiff -u -r1.233 -r1.234 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.184 -r1.185 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.263 -r1.264 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.626 -r1.627 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_167.c
diff -u src/tests/usr.bin/xlint/lint1/msg_167.c:1.5 src/tests/usr.bin/xlint/lint1/msg_167.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_167.c:1.5	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_167.c	Wed Mar 27 19:28:20 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_167.c,v 1.5 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_167.c,v 1.6 2024/03/27 19:28:20 rillig Exp $	*/
 # 3 "msg_167.c"
 
-// Test for message: array subscript cannot be negative: %ld [167]
+// Test for message: array subscript cannot be negative: %jd [167]
 
 /* lint1-extra-flags: -X 351 */
 
Index: src/tests/usr.bin/xlint/lint1/msg_187.c
diff -u src/tests/usr.bin/xlint/lint1/msg_187.c:1.5 src/tests/usr.bin/xlint/lint1/msg_187.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_187.c:1.5	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_187.c	Wed Mar 27 19:28:20 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_187.c,v 1.5 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_187.c,v 1.6 2024/03/27 19:28:20 rillig Exp $	*/
 # 3 "msg_187.c"
 
-// Test for message: string literal too long (%lu) for target array (%lu) [187]
+// Test for message: string literal too long (%ju) for target array (%ju) [187]
 
 /* lint1-extra-flags: -X 351 */
 
Index: src/tests/usr.bin/xlint/lint1/msg_200.c
diff -u src/tests/usr.bin/xlint/lint1/msg_200.c:1.5 src/tests/usr.bin/xlint/lint1/msg_200.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_200.c:1.5	Sun Jul  9 11:01:27 2023
+++ src/tests/usr.bin/xlint/lint1/msg_200.c	Wed Mar 27 19:28:20 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_200.c,v 1.5 2023/07/09 11:01:27 rillig Exp $	*/
+/*	$NetBSD: msg_200.c,v 1.6 2024/03/27 19:28:20 rillig Exp $	*/
 # 3 "msg_200.c"
 
-// Test for message: duplicate case '%lu' in switch [200]
+// Test for message: duplicate case '%ju' in switch [200]
 
 /* lint1-extra-flags: -X 351 */
 

Index: src/tests/usr.bin/xlint/lint1/msg_168.c
diff -u src/tests/usr.bin/xlint/lint1/msg_168.c:1.10 src/tests/usr.bin/xlint/lint1/msg_168.c:1.11
--- src/tests/usr.bin/xlint/lint1/msg_168.c:1.10	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_168.c	Wed Mar 27 19:28:20 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_168.c,v 1.10 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_168.c,v 1.11 2024/03/27 19:28:20 rillig Exp $	*/
 # 3 "msg_168.c"
 
-// Test for message: array subscript cannot be > %d: %ld [168]
+// Test for message: array subscript cannot be > %d: %jd [168]
 
 /* lint1-extra-flags: -X 351 */
 

Index: src/tests/usr.bin/xlint/lint1/msg_199.c
diff -u src/tests/usr.bin/xlint/lint1/msg_199.c:1.4 src/tests/usr.bin/xlint/lint1/msg_199.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_199.c:1.4	Sun Jul  9 11:01:27 2023
+++ src/tests/usr.bin/xlint/lint1/msg_199.c	Wed Mar 27 19:28:20 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_199.c,v 1.4 2023/07/09 11:01:27 rillig Exp $	*/
+/*	$NetBSD: msg_199.c,v 1.5 2024/03/27 19:28:20 rillig Exp $	*/
 # 3 "msg_199.c"
 
-// Test for message: duplicate case '%ld' in switch [199]
+// Test for message: duplicate case '%jd' in switch [199]
 
 /* lint1-extra-flags: -X 351 */
 
Index: src/tests/usr.bin/xlint/lint1/platform_ilp32.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32.c:1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32.c:1.5
--- src/tests/usr.bin/xlint/lint1/platform_ilp32.c:1.4	Mon Feb 27 23:07:53 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32.c	Wed Mar 27 19:28:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32.c,v 1.4 2023/02/27 23:07:53 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32.c,v 1.5 2024/03/27 19:28:20 rillig Exp $	*/
 # 3 "platform_ilp32.c"
 
 /*
@@ -10,7 +10,37 @@
  *	platform_ilp32_long.c
  */
 
-/* lint1-extra-flags: -c -h -a -p -b -r -z */
+/* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */
 /* lint1-only-if: ilp32 */
 
-typedef int do_not_warn_about_empty_translation_unit;
+void
+switch_s64(long long x)
+{
+	switch (x) {
+	case 0x222200000001:
+	case 0x333300000001:
+	/* expect+1: error: duplicate case '37529424232449' in switch [199] */
+	case 0x222200000001:
+	case -0x7fffffffffffffff:
+	/* expect+1: error: duplicate case '-9223372036854775807' in switch [199] */
+	case -0x7fffffffffffffff:
+		break;
+	}
+}
+
+void
+switch_u64(unsigned long long x)
+{
+	switch (x) {
+	case 0x222200000001:
+	case 0x333300000001:
+	/* expect+1: error: duplicate case '37529424232449' in switch [200] */
+	case 0x222200000001:
+	/* expect+1: warning: conversion of negative constant to unsigned type [222] */
+	case -0x7fffffffffffffff:
+	/* expect+2: warning: conversion of negative constant to unsigned type [222] */
+	/* expect+1: error: duplicate case '9223372036854775809' in switch [200] */
+	case -0x7fffffffffffffff:
+		break;
+	}
+}

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.233 src/usr.bin/xlint/lint1/err.c:1.234
--- src/usr.bin/xlint/lint1/err.c:1.233	Mon Mar 25 22:37:43 2024
+++ src/usr.bin/xlint/lint1/err.c	Wed Mar 27 19:28:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.233 2024/03/25 22:37:43 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.234 2024/03/27 19:28:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.233 2024/03/25 22:37:43 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.234 2024/03/27 19:28:20 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -222,8 +222,8 @@ static const char *const msgs[] = {
 	"assignment of negative constant to unsigned type",		// 164
 	"constant truncated by assignment",				// 165
 	"precision lost in bit-field assignment",			// 166
-	"array subscript cannot be negative: %ld",			// 167
-	"array subscript cannot be > %d: %ld",				// 168
+	"array subscript cannot be negative: %jd",			// 167
+	"array subscript cannot be > %d: %jd",				// 168
 	"precedence confusion possible: parenthesize!",			// 169
 	"first operand of '?' must have scalar type",			// 170
 	"cannot assign to '%s' from '%s'",				// 171
@@ -242,7 +242,7 @@ static const char *const msgs[] = {
 	"illegal combination of '%s' and '%s'",				// 184
 	"cannot initialize '%s' from '%s'",				// 185
 	"bit-field initialization is illegal in traditional C",		// 186
-	"string literal too long (%lu) for target array (%lu)",		// 187
+	"string literal too long (%ju) for target array (%ju)",		// 187
 	"no automatic aggregate initialization in traditional C",	// 188
 	"",			/* no longer used */			// 189
 	"empty array declaration for '%s'",				// 190
@@ -254,8 +254,8 @@ static const char *const msgs[] = {
 	"case label affected by conversion",				// 196
 	"non-constant case expression",					// 197
 	"non-integral case expression",					// 198
-	"duplicate case '%ld' in switch",				// 199
-	"duplicate case '%lu' in switch",				// 200
+	"duplicate case '%jd' in switch",				// 199
+	"duplicate case '%ju' in switch",				// 200
 	"default outside switch",					// 201
 	"duplicate default in switch",					// 202
 	"case label must be of type 'int' in traditional C",		// 203

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.184 src/usr.bin/xlint/lint1/func.c:1.185
--- src/usr.bin/xlint/lint1/func.c:1.184	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/func.c	Wed Mar 27 19:28:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.184 2024/03/09 13:54:47 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.185 2024/03/27 19:28:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.184 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.185 2024/03/27 19:28:20 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -442,11 +442,11 @@ check_duplicate_case_label(control_state
 
 	if (i < n) {
 		if (is_uinteger(nv->v_tspec))
-			/* duplicate case '%lu' in switch */
-			error(200, (unsigned long)nv->u.integer);
+			/* duplicate case '%ju' in switch */
+			error(200, (uintmax_t)nv->u.integer);
 		else
-			/* duplicate case '%ld' in switch */
-			error(199, (long)nv->u.integer);
+			/* duplicate case '%jd' in switch */
+			error(199, (intmax_t)nv->u.integer);
 		return false;
 	}
 

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.263 src/usr.bin/xlint/lint1/init.c:1.264
--- src/usr.bin/xlint/lint1/init.c:1.263	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/init.c	Wed Mar 27 19:28:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.263 2024/03/09 13:54:47 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.264 2024/03/27 19:28:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.263 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.264 2024/03/27 19:28:20 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -835,8 +835,8 @@ initialization_add_designator_subscript(
 	}
 
 	if (!tp->t_incomplete_array && subscript >= (size_t)tp->u.dimension) {
-		/* array subscript cannot be > %d: %ld */
-		error(168, tp->u.dimension - 1, (long)subscript);
+		/* array subscript cannot be > %d: %jd */
+		error(168, tp->u.dimension - 1, (intmax_t)subscript);
 		subscript = 0;	/* suppress further errors */
 	}
 
@@ -893,9 +893,8 @@ initialization_init_array_from_string(in
 	}
 
 	if (!tp->t_incomplete_array && (size_t)tp->u.dimension < len)
-		/* string literal too long (%lu) for target array (%lu) */
-		warning(187, (unsigned long)len,
-		    (unsigned long)tp->u.dimension);
+		/* string literal too long (%ju) for target array (%ju) */
+		warning(187, (uintmax_t)len, (uintmax_t)tp->u.dimension);
 
 	brace_level *bl = in->in_brace_level;
 	if (bl != NULL && bl->bl_designation.dn_len == 0)

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.626 src/usr.bin/xlint/lint1/tree.c:1.627
--- src/usr.bin/xlint/lint1/tree.c:1.626	Mon Mar 25 23:39:13 2024
+++ src/usr.bin/xlint/lint1/tree.c	Wed Mar 27 19:28:20 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.626 2024/03/25 23:39:13 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.627 2024/03/27 19:28:20 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.626 2024/03/25 23:39:13 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.627 2024/03/27 19:28:20 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4436,11 +4436,11 @@ proceed:;
 	int dim = arr->tn_type->u.dimension + (taking_address ? 1 : 0);
 
 	if (!is_uinteger(idx->tn_type->t_tspec) && con < 0)
-		/* array subscript cannot be negative: %ld */
-		warning(167, (long)con);
+		/* array subscript cannot be negative: %jd */
+		warning(167, (intmax_t)con);
 	else if (dim > 0 && (uint64_t)con >= (uint64_t)dim)
-		/* array subscript cannot be > %d: %ld */
-		warning(168, dim - 1, (long)con);
+		/* array subscript cannot be > %d: %jd */
+		warning(168, dim - 1, (intmax_t)con);
 }
 
 static void

Reply via email to