CVS commit: src/tests/usr.bin/xlint/lint1

2024-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 19 20:59:18 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_207.c

Log Message:
tests/lint: show how to trigger message 207


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_207.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_207.c
diff -u src/tests/usr.bin/xlint/lint1/msg_207.c:1.3 src/tests/usr.bin/xlint/lint1/msg_207.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_207.c:1.3	Thu Jun 16 21:24:41 2022
+++ src/tests/usr.bin/xlint/lint1/msg_207.c	Fri Apr 19 20:59:18 2024
@@ -1,8 +1,51 @@
-/*	$NetBSD: msg_207.c,v 1.3 2022/06/16 21:24:41 rillig Exp $	*/
+/*	$NetBSD: msg_207.c,v 1.4 2024/04/19 20:59:18 rillig Exp $	*/
 # 3 "msg_207.c"
 
 // Test for message: loop not entered at top [207]
 
-/* expect+1: error: syntax error ':' [249] */
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+static void
+/* expect+1: warning: static function 'for_loop' unused [236] */
+for_loop(void)
+{
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			for (i = 0;
+			i < 5;
+/* expect+2: warning: loop not entered at top [207] */
+/* expect+1: warning: end-of-loop code not reached [223] */
+			i += 4)
+return;
+
+	// XXX: Why is this different from the snippet above?
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			/* expect+1: warning: statement not reached [193] */
+			for (int j = 0;
+			j < 5;
+			/* expect+1: warning: end-of-loop code not reached [223] */
+			j += 4)
+return;
+}
+
+static void
+/* expect+1: warning: static function 'while_loop' unused [236] */
+while_loop(void)
+{
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			/* expect+1: warning: loop not entered at top [207] */
+			while (i < 5)
+i += 4;
+}
+
+static void
+/* expect+1: warning: static function 'do_loop' unused [236] */
+do_loop(void)
+{
+	for (int i = 0; i < 10; i++)
+		if (0 == 1)
+			/* expect+1: warning: loop not entered at top [207] */
+			do {
+i += 4;
+			} while (i < 5);
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2024-04-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 19 20:59:18 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_207.c

Log Message:
tests/lint: show how to trigger message 207


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_207.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Mar 25 22:46:23 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c

Log Message:
tests/lint: demonstrate wrong warnings about lossy bit field operations


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/tests/usr.bin/xlint/lint1/msg_132.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_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.36 src/tests/usr.bin/xlint/lint1/msg_132.c:1.37
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.36	Tue Mar 12 20:35:29 2024
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Mon Mar 25 22:46:23 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.36 2024/03/12 20:35:29 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.37 2024/03/25 22:46:23 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -427,3 +427,20 @@ compare_bit_field_to_integer_constant(vo
 	b = s.u64 == 0;
 	b = !b;
 }
+
+_Bool
+binary_operators_on_bit_fields(void)
+{
+	struct {
+		unsigned long long u15:15;
+		unsigned long long u48:48;
+		unsigned long long u64;
+	} s = { 0, 0, 0 };
+
+	u64 = s.u15 | s.u48;
+	/* expect+1: warning: conversion from 'unsigned long long:16' to 'int:17' may lose accuracy [132] */
+	u64 = s.u15 | s.u48 | s.u64;
+	/* expect+2: warning: conversion from 'unsigned long long:16' to 'int:17' may lose accuracy [132] */
+	/* expect+1: warning: conversion from 'unsigned long long:17' to 'int:18' may lose accuracy [132] */
+	return (s.u15 | s.u48 | s.u64) != 0;
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Mar 25 22:46:23 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c

Log Message:
tests/lint: demonstrate wrong warnings about lossy bit field operations


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/tests/usr.bin/xlint/lint1/msg_132.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Mar 13 06:56:24 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_sizeof.c

Log Message:
tests/lint: ensure that lint correctly decays array parameter types


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/expr_sizeof.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/expr_sizeof.c
diff -u src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.14 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.15
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.14	Sat Aug  5 10:13:39 2023
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c	Wed Mar 13 06:56:24 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_sizeof.c,v 1.14 2023/08/05 10:13:39 rillig Exp $	*/
+/*	$NetBSD: expr_sizeof.c,v 1.15 2024/03/13 06:56:24 rillig Exp $	*/
 # 3 "expr_sizeof.c"
 
 /*
@@ -199,3 +199,17 @@ struct s24 {
 };
 /* expect+1: error: negative array dimension (-24) [20] */
 typedef int sizeof_s24[-(int)sizeof(struct s24)];
+
+void
+sizeof_array_parameter(short arr[12345])
+{
+	// The size of an array parameter is the size of the decayed pointer.
+	// Subtracting 'sizeof(void *)' makes the test platform-independent.
+	typedef int sizeof_arr[-(int)(sizeof arr - sizeof(void *))];
+
+	// The 2 comes from 'sizeof(short)', as the type 'array[size] of elem'
+	// decays into the type 'pointer to elem', not 'pointer to array[size]
+	// of elem'.
+	/* expect+1: error: negative array dimension (-2) [20] */
+	typedef int sizeof_arr_elem[-(int)(sizeof *arr)];
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Mar 13 06:56:24 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_sizeof.c

Log Message:
tests/lint: ensure that lint correctly decays array parameter types


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/expr_sizeof.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 12 20:35:29 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c

Log Message:
tests/lint: extend test for previously wrong warning about bit-fields


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/tests/usr.bin/xlint/lint1/msg_132.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 12 20:35:29 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c

Log Message:
tests/lint: extend test for previously wrong warning about bit-fields


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/tests/usr.bin/xlint/lint1/msg_132.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_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.35 src/tests/usr.bin/xlint/lint1/msg_132.c:1.36
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.35	Tue Mar 12 07:56:08 2024
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Tue Mar 12 20:35:29 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.35 2024/03/12 07:56:08 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.36 2024/03/12 20:35:29 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -404,16 +404,26 @@ test_ic_conditional(char c1, char c2)
 }
 
 void
-fp_classify(void)
+compare_bit_field_to_integer_constant(void)
 {
-	static struct ieee_ext {
-		unsigned long long ext_exp:15;
-	} x;
+	static _Bool b;
+	static struct {
+		short s16:15;
+		unsigned short u16:15;
+		int s32:15;
+		unsigned u32:15;
+		long long s64:15;
+		unsigned long long u64:15;
+	} s;
 
 	// Since decl.c 1.180 from 2021-05-02 and before tree.c 1.624 from
 	// 2024-03-12, lint warned about a possible loss of accuracy [132]
-	// when promoting a small unsigned bit-field to 'int'.
-	if (x.ext_exp == 0) {
-	} else if (x.ext_exp == 0x7fff) {
-	}
+	// when promoting an 'unsigned long long' bit-field to 'int'.
+	b = s.s16 == 0;
+	b = s.u16 == 0;
+	b = s.s32 == 0;
+	b = s.u32 == 0;
+	b = s.s64 == 0;
+	b = s.u64 == 0;
+	b = !b;
 }



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 12 07:29:40 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c

Log Message:
tests/lint: demonstrate wrong warning when comparing a bit-field

Since decl.c 1.180 from 2021-05-02, which allowed arbitrary integer
types to be used as the underlying type for bit-fields in GCC mode.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/tests/usr.bin/xlint/lint1/msg_132.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_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.33 src/tests/usr.bin/xlint/lint1/msg_132.c:1.34
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.33	Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Tue Mar 12 07:29:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.33 2024/01/28 08:17:27 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.34 2024/03/12 07:29:39 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -402,3 +402,19 @@ test_ic_conditional(char c1, char c2)
 	/* expect+1: warning: conversion from 'int' to 'unsigned char' may lose accuracy [132] */
 	u8 = cond ? s8 : u8;
 }
+
+void
+fp_classify(void)
+{
+	static struct ieee_ext {
+		unsigned long long ext_exp:15;
+	} x;
+
+	/* FIXME: There is no loss of accuracy here. */
+	/* expect+1: warning: conversion from 'unsigned long long:15' to 'int:15' may lose accuracy [132] */
+	if (x.ext_exp == 0) {
+	/* FIXME: There is no loss of accuracy here. */
+	/* expect+1: warning: conversion from 'unsigned long long:15' to 'int:15' may lose accuracy [132] */
+	} else if (x.ext_exp == 0x7fff) {
+	}
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 12 07:29:40 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132.c

Log Message:
tests/lint: demonstrate wrong warning when comparing a bit-field

Since decl.c 1.180 from 2021-05-02, which allowed arbitrary integer
types to be used as the underlying type for bit-fields in GCC mode.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/tests/usr.bin/xlint/lint1/msg_132.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 10:39:19 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_lp64.c

Log Message:
tests/lint: enable test for integer overflow in array index


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/platform_lp64.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 10:39:19 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_lp64.c

Log Message:
tests/lint: enable test for integer overflow in array index


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/platform_lp64.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/platform_lp64.c
diff -u src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.9 src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.10
--- src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.9	Sat Mar  9 17:34:01 2024
+++ src/tests/usr.bin/xlint/lint1/platform_lp64.c	Sun Mar 10 10:39:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_lp64.c,v 1.9 2024/03/09 17:34:01 rillig Exp $	*/
+/*	$NetBSD: platform_lp64.c,v 1.10 2024/03/10 10:39:19 rillig Exp $	*/
 # 3 "platform_lp64.c"
 
 /*
@@ -91,12 +91,15 @@ array_index(void)
 	u64 += u64_buf[0x00ff];
 	/* expect+1: warning: array subscript cannot be > 19: 1152921504606846975 [168] */
 	u64 += u64_buf[0x0fff];
-	// FIXME: integer overflow
-	//u64 += u64_buf[0x1fff];
-	// FIXME: integer overflow
-	//u64 += u64_buf[0x3fff];
-	// FIXME: integer overflow
-	//u64 += u64_buf[0x7fff];
+	/* expect+2: warning: operator '*' produces integer overflow [141] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x1fff];
+	/* expect+2: warning: operator '*' produces integer overflow [141] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x3fff];
+	/* expect+2: warning: operator '*' produces integer overflow [141] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x7fff];
 	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
 	u64 += u64_buf[0x];
 }



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 09:58:30 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c

Log Message:
tests/lint: test integer overflow when folding constants

The test is still incomplete, yet it has discovered several bugs that
are worth fixing.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_141.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_141.c
diff -u src/tests/usr.bin/xlint/lint1/msg_141.c:1.10 src/tests/usr.bin/xlint/lint1/msg_141.c:1.11
--- src/tests/usr.bin/xlint/lint1/msg_141.c:1.10	Thu Jan 11 20:25:04 2024
+++ src/tests/usr.bin/xlint/lint1/msg_141.c	Sun Mar 10 09:58:30 2024
@@ -1,213 +1,583 @@
-/*	$NetBSD: msg_141.c,v 1.10 2024/01/11 20:25:04 rillig Exp $	*/
+/*	$NetBSD: msg_141.c,v 1.11 2024/03/10 09:58:30 rillig Exp $	*/
 # 3 "msg_141.c"
 
 // Test for message: operator '%s' produces integer overflow [141]
 
 /* lint1-extra-flags: -h -X 351 */
 
-/*
- * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
- * overflow in '-'.
- */
-int signed_int_max = (1U << 31) - 1;
+// Integer overflow occurs when the arbitrary-precision result of an
+// arithmetic operation cannot be represented by the type of the expression.
 
-/*
- * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
- * overflow in '-'.
- */
-unsigned int unsigned_int_max = (1U << 31) - 1;
-
-/* expect+1: warning: operator '+' produces integer overflow [141] */
-int int_overflow = (1 << 30) + (1 << 30);
-
-/* expect+2: warning: operator '+' produces integer overflow [141] */
-/* expect+1: warning: initialization of unsigned with negative constant [221] */
-unsigned int intermediate_overflow = (1 << 30) + (1 << 30);
-
-unsigned int no_overflow = (1U << 30) + (1 << 30);
-
-/* expect+1: warning: operator '-' produces integer overflow [141] */
-unsigned int unsigned_int_min = 0U - (1U << 31);
-
-/* expect+1: warning: operator '-' produces integer overflow [141] */
-unsigned int unsigned_int_min_unary = -(1U << 31);
-
-enum {
-	INT_MAX = 2147483647,
-	INT_MIN = -INT_MAX - 1,
-};
-
-unsigned long long overflow_unsigned[] = {
-
-	// unary '+'
-
-	+0U,
-	+~0U,
-	+~0ULL,
-
-	// unary '-'
-
-	-0U,
-	-~0U,
+signed int s32;
+unsigned int u32;
+signed long long s64;
+unsigned long long u64;
+
+void
+compl_s32(void)
+{
+	s32 = ~(-0x7fff - 1);
+	s32 = ~-1;
+	s32 = ~0;
+	s32 = ~1;
+	s32 = ~0x7fff;
+}
+
+void
+compl_u32(void)
+{
+	u32 = ~0xU;
+	u32 = ~0x7fffU;
+	u32 = ~0x8000U;
+	u32 = ~0xU;
+}
+
+void
+compl_s64(void)
+{
+	s64 = ~(-0x7fffLL - 1LL);
+	s64 = ~-1LL;
+	s64 = ~0LL;
+	s64 = ~0x7fffLL;
+}
+
+void
+compl_u64(void)
+{
+	u64 = ~0ULL;
+	u64 = ~0x7fffULL;
+	u64 = ~0x8000ULL;
+	u64 = ~0xULL;
+}
+
+void
+uplus_s32(void)
+{
+	s32 = +(-0x7fff - 1);
+	s32 = +-1;
+	s32 = +0;
+	s32 = +0x7fff;
+}
+
+void
+uplus_u32(void)
+{
+	u32 = +0xU;
+	u32 = +0x7fffU;
+	u32 = +0x8000U;
+	u32 = +0xU;
+}
+
+void
+uplus_s64(void)
+{
+	s64 = +(-0x7fffLL - 1LL);
+	s64 = +-1LL;
+	s64 = +0LL;
+	s64 = +0x7fffLL;
+}
+
+void
+uplus_u64(void)
+{
+	u64 = +0xULL;
+	u64 = +0x7fffULL;
+	u64 = +0x8000ULL;
+	u64 = +0xULL;
+}
+
+void
+uminus_s32(void)
+{
 	/* expect+1: warning: operator '-' produces integer overflow [141] */
-	-(1ULL << 63),
+	s32 = -(-0x7fff - 1);
+	s32 = - -1;
+	s32 = -0;
+	s32 = -0x7fff;
+}
+
+void
+uminus_u32(void)
+{
+	u32 = -0xU;
+	u32 = -0x7fffU;
 	/* expect+1: warning: operator '-' produces integer overflow [141] */
-	-(1U << 31),
-
-	// '~'
+	u32 = -0x8000U;
+	u32 = -0xU;
+}
+
+void
+uminus_s64(void)
+{
+	/* expect+1: warning: operator '-' produces integer overflow [141] */
+	s64 = -(-0x7fffLL - 1LL);
+	s64 = - -1LL;
+	s64 = -0LL;
+	s64 = -0x7fffLL;
+}
+
+void
+uminus_u64(void)
+{
+	u64 = -0xULL;
+	u64 = -0x7fffULL;
+	/* expect+1: warning: operator '-' produces integer overflow [141] */
+	u64 = -0x8000ULL;
+	u64 = -0xULL;
+}
+
+void
+mult_s32(void)
+{
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s32 = -0x0001 * +0x0001;	// -0x01
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s32 = -0x0003 * +0x2aab;	// -0x8001
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	s32 = +0x2aab * -0x0003;	// -0x8001
+	s32 = -0x0008 * +0x1000;	// -0x8000
+	s32 = +0x1000 * -0x0008;	// -0x8000
+	s32 = +0x0002 * +0x3fff;	// +0x7ffe
+	s32 = +0x3fff * +0x0002;	// +0x7ffe
+	s32 = +0x7fff * +0x0001;	// +0x7fff
+	s32 = 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 09:58:30 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c

Log Message:
tests/lint: test integer overflow when folding constants

The test is still incomplete, yet it has discovered several bugs that
are worth fixing.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_141.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 17:34:01 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: demonstrate integer overflow on lp64 platforms


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/platform_lp64.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/platform_ilp32_int.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3	Sat Mar  9 16:47:09 2024
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c	Sat Mar  9 17:34:01 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_int.c,v 1.3 2024/03/09 16:47:09 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_int.c,v 1.4 2024/03/09 17:34:01 rillig Exp $	*/
 # 3 "platform_ilp32_int.c"
 
 /*
@@ -28,24 +28,75 @@ convert_between_int_and_long(void)
 	ul32 = u32;
 }
 
-char ch;
+unsigned char u8;
+unsigned long long u64;
+unsigned char u8_buf[20];
+unsigned long long u64_buf[20];
 
 void
 array_index(void)
 {
-	static char buf[20];
 
+	/* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */
+	u8 += u8_buf[0x00ff];
 	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
-	ch += buf[2147483647];
+	u8 += u8_buf[0x7fff];
 	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
 	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
-	ch += buf[2147483648];
+	u8 += u8_buf[2147483648];
 	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
 	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
-	ch += buf[0x8000];
+	u8 += u8_buf[0x8000];
 	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
 	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
-	ch += buf[0x];
+	u8 += u8_buf[0x];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	u8 += u8_buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u8 += u8_buf[0x];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u8 += u8_buf[0x00ff];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u8 += u8_buf[0x];
+
+	/* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */
+	u64 += u64_buf[0x00ff];
+	/* expect+2: warning: operator '*' produces integer overflow [141] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x7fff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	u64 += u64_buf[2147483648];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	u64 += u64_buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	u64 += u64_buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x00ff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x0fff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += u64_buf[0x1fff];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	u64 += 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 17:34:01 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: demonstrate integer overflow on lp64 platforms


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/platform_lp64.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 16:47:10 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: test check for out-of-bounds array index


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/platform_lp64.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/platform_ilp32_int.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.2 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.3
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c:1.2	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c	Sat Mar  9 16:47:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_int.c,v 1.2 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_int.c,v 1.3 2024/03/09 16:47:09 rillig Exp $	*/
 # 3 "platform_ilp32_int.c"
 
 /*
@@ -27,3 +27,25 @@ convert_between_int_and_long(void)
 	u32 = ul32;
 	ul32 = u32;
 }
+
+char ch;
+
+void
+array_index(void)
+{
+	static char buf[20];
+
+	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
+	ch += buf[2147483647];
+	/* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[2147483648];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+}

Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.5
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c:1.4	Sat Jul  8 15:26:25 2023
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c	Sat Mar  9 16:47:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_long.c,v 1.4 2023/07/08 15:26:25 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_long.c,v 1.5 2024/03/09 16:47:09 rillig Exp $	*/
 # 3 "platform_ilp32_long.c"
 
 /*
@@ -36,3 +36,25 @@ convert_between_int_and_long(void)
 	u32 = ul32;
 	ul32 = u32;
 }
+
+char ch;
+
+void
+array_index(void)
+{
+	static char buf[20];
+
+	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
+	ch += buf[2147483647];
+	/* expect+2: warning: conversion of 'long long' to 'long' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[2147483648];
+	/* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
+	ch += buf[0x8000];
+	/* expect+2: warning: conversion of 'unsigned int' to 'long' is out of range [119] */
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+}

Index: src/tests/usr.bin/xlint/lint1/platform_lp64.c
diff -u src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.7 src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.8
--- src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.7	Sat Jul  8 12:45:43 2023
+++ src/tests/usr.bin/xlint/lint1/platform_lp64.c	Sat Mar  9 16:47:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_lp64.c,v 1.7 2023/07/08 12:45:43 rillig Exp $	*/
+/*	$NetBSD: platform_lp64.c,v 1.8 2024/03/09 16:47:09 rillig Exp $	*/
 # 3 "platform_lp64.c"
 
 /*
@@ -44,3 +44,22 @@ convert_128(void)
 	/* expect+1: warning: conversion from '__uint128_t' to 'unsigned int' may lose accuracy [132] */
 	u32 = u128;
 }
+
+char ch;
+
+void
+array_index(void)
+{
+	static char buf[20];
+
+	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
+	ch += buf[2147483647];
+	/* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */
+	ch += buf[2147483648];
+	/* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */
+	ch += buf[0x8000];
+	/* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */
+	ch += buf[0x];
+	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
+	ch += buf[0x];
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 16:47:10 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_int.c
platform_ilp32_long.c platform_lp64.c

Log Message:
tests/lint: test check for out-of-bounds array index


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_int.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_ilp32_long.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/platform_lp64.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 22:59:28 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_trad.c

Log Message:
tests/lint: sync test for integer constant type on ILP32 platforms

The test was broken since lex.c 1.214 from today.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.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/platform_ilp32_trad.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.c:1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.c:1.3	Sun Jan 28 08:26:07 2024
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.c	Wed Feb  7 22:59:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_trad.c,v 1.3 2024/01/28 08:26:07 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_trad.c,v 1.4 2024/02/07 22:59:28 rillig Exp $	*/
 # 3 "platform_ilp32_trad.c"
 
 /*
@@ -13,10 +13,12 @@ void *lex_integer[] = {
 	2147483647,
 	/* expect+1: ... integer 'int' ... */
 	0x7fff,
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: ... integer 'long' ... */
 	2147483648,
 	/* expect+1: ... integer 'long' ... */
 	0x8000,
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: ... integer 'long' ... */
 	4294967295,
 	/* expect+1: ... integer 'long' ... */



CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 22:59:28 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_ilp32_trad.c

Log Message:
tests/lint: sync test for integer constant type on ILP32 platforms

The test was broken since lex.c 1.214 from today.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 19:18:36 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_074.c msg_075.c

Log Message:
tests/lint: extend tests for hexadecimal character escapes


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_074.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_075.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_074.c
diff -u src/tests/usr.bin/xlint/lint1/msg_074.c:1.7 src/tests/usr.bin/xlint/lint1/msg_074.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_074.c:1.7	Fri Feb  2 19:07:58 2024
+++ src/tests/usr.bin/xlint/lint1/msg_074.c	Sat Feb  3 19:18:36 2024
@@ -1,7 +1,10 @@
-/*	$NetBSD: msg_074.c,v 1.7 2024/02/02 19:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_074.c,v 1.8 2024/02/03 19:18:36 rillig Exp $	*/
 # 3 "msg_074.c"
 
 // Test for message: no hex digits follow \x [74]
+//
+// See also:
+//	msg_075.c		overflow in hex escape
 
 /* lint1-extra-flags: -X 351 */
 
@@ -10,27 +13,19 @@ char char_invalid_hex = '\x';
 /* expect+2: error: no hex digits follow \x [74] */
 /* expect+1: warning: multi-character character constant [294] */
 char char_invalid_hex_letter = '\xg';
-char char_hex1 = '\xf';
-char char_hex2 = '\xff';
 
 /* expect+1: error: no hex digits follow \x [74] */
 int wide_invalid_hex = L'\x';
 /* expect+2: error: no hex digits follow \x [74] */
 /* expect+1: error: too many characters in character constant [71] */
 int wide_invalid_hex_letter = L'\xg';
-int wide_hex1 = L'\xf';
-int wide_hex2 = L'\xff';
 
 /* expect+1: error: no hex digits follow \x [74] */
 char char_string_invalid_hex[] = "\x";
 /* expect+1: error: no hex digits follow \x [74] */
 char char_string_invalid_hex_letter[] = "\xg";
-char char_string_hex1[] = "\xf";
-char char_string_hex2[] = "\xff";
 
 /* expect+1: error: no hex digits follow \x [74] */
 int wide_string_invalid_hex[] = L"\x";
 /* expect+1: error: no hex digits follow \x [74] */
 int wide_string_invalid_hex_letter[] = L"\xg";
-int wide_string_hex1[] = L"\xf";
-int wide_string_hex2[] = L"\xff";

Index: src/tests/usr.bin/xlint/lint1/msg_075.c
diff -u src/tests/usr.bin/xlint/lint1/msg_075.c:1.9 src/tests/usr.bin/xlint/lint1/msg_075.c:1.10
--- src/tests/usr.bin/xlint/lint1/msg_075.c:1.9	Sat Feb  3 18:58:05 2024
+++ src/tests/usr.bin/xlint/lint1/msg_075.c	Sat Feb  3 19:18:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_075.c,v 1.9 2024/02/03 18:58:05 rillig Exp $	*/
+/*	$NetBSD: msg_075.c,v 1.10 2024/02/03 19:18:36 rillig Exp $	*/
 # 3 "msg_075.c"
 
 // Test for message: overflow in hex escape [75]
@@ -20,40 +20,64 @@ char str[] = "\x123456781234567812345678
 /* C11 6.4.4.4p7 */
 char leading_zeroes = '\x020';
 
-char char_hex1 = '\xf';
-char char_hex2 = '\xff';
+char char_hex4bit = '\xf';
+char char_hex7bit = '\x7f';
+char char_hex8bit = '\xff';
 /* expect+1: warning: overflow in hex escape [75] */
-char char_hex3 = '\x100';
+char char_hex9bit = '\x100';
 /* expect+1: warning: overflow in hex escape [75] */
-char char_hex4 = '\x';
+char char_hex16bit = '\x';
 /* expect+1: warning: overflow in hex escape [75] */
-char char_hex5 = '\xf';
+char char_hex20bit = '\xf';
 /* expect+1: warning: overflow in hex escape [75] */
-char char_hex9 = '\xf';
+char char_hex31bit = '\x7fff';
+/* expect+1: warning: overflow in hex escape [75] */
+char char_hex32bit = '\x';
+/* expect+1: warning: overflow in hex escape [75] */
+char char_hex33bit = '\x100ff';
+/* expect+1: warning: overflow in hex escape [75] */
+char char_hex36bit = '\xf';
 
-int wide_hex1 = L'\xf';
-int wide_hex2 = L'\xff';
-int wide_hex3 = L'\x100';
-int wide_hex4 = L'\x';
-int wide_hex5 = L'\xf';
+int wide_hex4bit = L'\xf';
+int wide_hex7bit = L'\x7f';
+int wide_hex8bit = L'\xff';
+int wide_hex9bit = L'\x100';
+int wide_hex16bit = L'\x';
+int wide_hex20bit = L'\xf';
+int wide_hex31bit = L'\x7fff';
+int wide_hex32bit = L'\x';
+/* expect+1: warning: overflow in hex escape [75] */
+int wide_hex33bit = L'\x100ff';
 /* expect+1: warning: overflow in hex escape [75] */
-int wide_hex9 = L'\xf';
+int wide_hex36bit = L'\xf';
 
-char char_string_hex1[] = "\xf";
-char char_string_hex2[] = "\xff";
+char char_string_hex4bit[] = "\xf";
+char char_string_hex7bit[] = "\x7f";
+char char_string_hex8bit[] = "\xff";
 /* expect+1: warning: overflow in hex escape [75] */
-char char_string_hex3[] = "\x100";
+char char_string_hex9bit[] = "\x100";
 /* expect+1: warning: overflow in hex escape [75] */
-char char_string_hex4[] = "\x";
+char char_string_hex16bit[] = "\x";
 /* expect+1: warning: overflow in hex escape [75] */
-char char_string_hex5[] = "\xf";
+char char_string_hex20bit[] = "\xf";
 /* expect+1: warning: overflow in hex escape [75] */
-char 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 19:18:36 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_074.c msg_075.c

Log Message:
tests/lint: extend tests for hexadecimal character escapes


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_074.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_075.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 09:36:14 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_076.c

Log Message:
tests/lint: test octal escapes in character and wide strings


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_076.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 09:36:14 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_076.c

Log Message:
tests/lint: test octal escapes in character and wide strings


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_076.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_076.c
diff -u src/tests/usr.bin/xlint/lint1/msg_076.c:1.6 src/tests/usr.bin/xlint/lint1/msg_076.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_076.c:1.6	Fri Feb  2 19:07:58 2024
+++ src/tests/usr.bin/xlint/lint1/msg_076.c	Sat Feb  3 09:36:14 2024
@@ -1,7 +1,10 @@
-/*	$NetBSD: msg_076.c,v 1.6 2024/02/02 19:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_076.c,v 1.7 2024/02/03 09:36:14 rillig Exp $	*/
 # 3 "msg_076.c"
 
 // Test for message: character escape does not fit in character [76]
+//
+// See also:
+//	msg_075.c		for hex escapes
 
 /* lint1-extra-flags: -X 351 */
 
@@ -21,3 +24,19 @@ int wide_256 = L'\400';
 int wide_511 = L'\777';
 /* expect+1: error: too many characters in character constant [71] */
 int wide_512 = L'\1000';
+
+char char_string_255[] = "\377";
+/* expect+1: warning: character escape does not fit in character [76] */
+char char_string_256[] = "\400";
+/* expect+1: warning: character escape does not fit in character [76] */
+char char_string_511[] = "\777";
+char char_string_512[] = "\1000";
+
+int wide_string_255[] = L"\377";
+/* FIXME: A wide character can represent 256. */
+/* expect+1: warning: character escape does not fit in character [76] */
+int wide_string_256[] = L"\400";
+/* FIXME: A wide character can represent 511. */
+/* expect+1: warning: character escape does not fit in character [76] */
+int wide_string_511[] = L"\777";
+int wide_string_512[] = L"\1000";



CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Feb  2 22:45:48 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: lex_wide_string.c

Log Message:
tests/lint: add UTF-8 test for string literals


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/lex_wide_string.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/lex_wide_string.c
diff -u src/tests/usr.bin/xlint/lint1/lex_wide_string.c:1.4 src/tests/usr.bin/xlint/lint1/lex_wide_string.c:1.5
--- src/tests/usr.bin/xlint/lint1/lex_wide_string.c:1.4	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/lex_wide_string.c	Fri Feb  2 22:45:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lex_wide_string.c,v 1.4 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: lex_wide_string.c,v 1.5 2024/02/02 22:45:48 rillig Exp $	*/
 # 3 "lex_wide_string.c"
 
 /*
@@ -33,3 +33,12 @@ test(void)
 	/* expect+1: error: cannot concatenate wide and regular string literals [292] */
 	sink(L"wide" "plain");
 }
+
+/*
+ * Since lint always runs in the default "C" locale, it does not support any
+ * multibyte character encoding, thus treating each byte as a separate
+ * character. If lint were to support UTF-8, the array dimension would be 3
+ * instead of 7.
+ */
+/* expect+1: error: negative array dimension (-7) [20] */
+typedef int mblen[-(int)(sizeof(L"Ä") / sizeof(L""))];



CVS commit: src/tests/usr.bin/xlint/lint1

2024-02-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Feb  2 22:45:48 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: lex_wide_string.c

Log Message:
tests/lint: add UTF-8 test for string literals


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/lex_wide_string.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 08:54:28 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_019.c queries.c
queries_schar.c queries_uchar.c

Log Message:
tests/lint: enforce diagnostics to be listed in chronologic order

While here, fix the tests on uchar platforms.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_019.c
cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/xlint/lint1/queries.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/queries_schar.c \
src/tests/usr.bin/xlint/lint1/queries_uchar.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/check-expect.lua
diff -u src/tests/usr.bin/xlint/lint1/check-expect.lua:1.11 src/tests/usr.bin/xlint/lint1/check-expect.lua:1.12
--- src/tests/usr.bin/xlint/lint1/check-expect.lua:1.11	Sun Jan 28 08:26:07 2024
+++ src/tests/usr.bin/xlint/lint1/check-expect.lua	Sun Jan 28 08:54:27 2024
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.11 2024/01/28 08:26:07 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.12 2024/01/28 08:54:27 rillig Exp $
 
 --[[
 
@@ -236,9 +236,11 @@ local function check_test(c_fname, updat
 
 local found = false
 for i, c_comment in ipairs(c_comments) do
-  if c_comment ~= "" and matches(expected_message, c_comment) then
-c_comments[i] = ""
-found = true
+  if c_comment ~= "" then
+if matches(expected_message, c_comment) then
+  c_comments[i] = ""
+  found = true
+end
 break
   end
 end

Index: src/tests/usr.bin/xlint/lint1/msg_019.c
diff -u src/tests/usr.bin/xlint/lint1/msg_019.c:1.8 src/tests/usr.bin/xlint/lint1/msg_019.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_019.c:1.8	Sun Jul  9 11:18:55 2023
+++ src/tests/usr.bin/xlint/lint1/msg_019.c	Sun Jan 28 08:54:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_019.c,v 1.8 2023/07/09 11:18:55 rillig Exp $	*/
+/*	$NetBSD: msg_019.c,v 1.9 2024/01/28 08:54:27 rillig Exp $	*/
 # 3 "msg_019.c"
 
 // Test for message: void type for '%s' [19]
@@ -12,8 +12,8 @@ void global_variable;
 /* expect+1: warning: static variable 'unit_variable' unused [226] */
 static void unit_variable;
 
-/* expect+3: warning: parameter 'parameter' unused in function 'function' [231] */
-/* expect+2: error: void parameter 'parameter' cannot have name [61] */
+/* expect+3: error: void parameter 'parameter' cannot have name [61] */
+/* expect+2: warning: parameter 'parameter' unused in function 'function' [231] */
 void
 function(void parameter)
 {

Index: src/tests/usr.bin/xlint/lint1/queries.c
diff -u src/tests/usr.bin/xlint/lint1/queries.c:1.22 src/tests/usr.bin/xlint/lint1/queries.c:1.23
--- src/tests/usr.bin/xlint/lint1/queries.c:1.22	Sat Jan 20 10:02:31 2024
+++ src/tests/usr.bin/xlint/lint1/queries.c	Sun Jan 28 08:54:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: queries.c,v 1.22 2024/01/20 10:02:31 rillig Exp $	*/
+/*	$NetBSD: queries.c,v 1.23 2024/01/28 08:54:27 rillig Exp $	*/
 # 3 "queries.c"
 
 /*
@@ -464,23 +464,7 @@ char Q17_char[] = { ' ', '\0', '	' };
 /* expect+1: invisible character U+0009 in string literal [Q17] */
 char Q17_string[] = " \0	";
 
-/*
- * Variables with automatic storage duration often have so small scope that
- * adding the 'const' qualifier hurts readability more than it helps.
- */
-int
-/* expect+1: const automatic variable 'const_arg' [Q18] */
-Q18(const int const_arg, int arg)
-{
-	/* expect+1: const automatic variable 'Q18_scalar' [Q18] */
-	const char Q18_scalar = '1';
-	const char Q18_array[] = { '1', '2', '3' };
-	const char Q18_string[] = "123";
-	const char *Q18_string_pointer = "123";
-
-	return const_arg + arg
-	+ Q18_scalar + Q18_array[0] + Q18_string[0] + Q18_string_pointer[0];
-}
+/* For Q18, see queries_schar.c and queries_uchar.c. */
 
 /*
  * Since queries do not affect the exit status, force a warning to make this

Index: src/tests/usr.bin/xlint/lint1/queries_schar.c
diff -u src/tests/usr.bin/xlint/lint1/queries_schar.c:1.1 src/tests/usr.bin/xlint/lint1/queries_schar.c:1.2
--- src/tests/usr.bin/xlint/lint1/queries_schar.c:1.1	Mon Jul  3 15:29:42 2023
+++ src/tests/usr.bin/xlint/lint1/queries_schar.c	Sun Jan 28 08:54:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: queries_schar.c,v 1.1 2023/07/03 15:29:42 rillig Exp $	*/
+/*	$NetBSD: queries_schar.c,v 1.2 2024/01/28 08:54:27 rillig Exp $	*/
 # 3 "queries_schar.c"
 
 /*
@@ -11,7 +11,7 @@
  */
 
 /* lint1-only-if: schar */
-/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 -X 351 */
+/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 -X 351 */
 
 int
 Q14(char c)
@@ -24,6 +24,24 @@ Q14(char c)
 }
 
 /*
+ * Variables with automatic storage duration often have so small scope that
+ * adding the 'const' 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 08:54:28 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_019.c queries.c
queries_schar.c queries_uchar.c

Log Message:
tests/lint: enforce diagnostics to be listed in chronologic order

While here, fix the tests on uchar platforms.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_019.c
cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/xlint/lint1/queries.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/queries_schar.c \
src/tests/usr.bin/xlint/lint1/queries_uchar.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 08:26:07 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua platform_ilp32_c90.c
platform_ilp32_c99.c platform_ilp32_trad.c

Log Message:
tests/lint: sort diagnostics in ilp32 tests chronologically


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_c90.c \
src/tests/usr.bin/xlint/lint1/platform_ilp32_c99.c \
src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.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/check-expect.lua
diff -u src/tests/usr.bin/xlint/lint1/check-expect.lua:1.10 src/tests/usr.bin/xlint/lint1/check-expect.lua:1.11
--- src/tests/usr.bin/xlint/lint1/check-expect.lua:1.10	Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/check-expect.lua	Sun Jan 28 08:26:07 2024
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.10 2024/01/28 08:17:27 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.11 2024/01/28 08:26:07 rillig Exp $
 
 --[[
 
@@ -212,7 +212,6 @@ local function insert_missing(missing)
   local indent = (lines[lineno] or ""):match("^([ \t]*)")
   local offset = 1 + (seen[lineno] or 0)
   local line = ("%s/* expect+%d: %s */"):format(indent, offset, message)
-  print(("insert %s:%d %s"):format(fname, lineno, line))
   table.insert(lines, lineno, line)
   seen[lineno] = (seen[lineno] or 0) + 1
 end

Index: src/tests/usr.bin/xlint/lint1/platform_ilp32_c90.c
diff -u src/tests/usr.bin/xlint/lint1/platform_ilp32_c90.c:1.2 src/tests/usr.bin/xlint/lint1/platform_ilp32_c90.c:1.3
--- src/tests/usr.bin/xlint/lint1/platform_ilp32_c90.c:1.2	Sat Jan 27 20:03:14 2024
+++ src/tests/usr.bin/xlint/lint1/platform_ilp32_c90.c	Sun Jan 28 08:26:07 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_ilp32_c90.c,v 1.2 2024/01/27 20:03:14 rillig Exp $	*/
+/*	$NetBSD: platform_ilp32_c90.c,v 1.3 2024/01/28 08:26:07 rillig Exp $	*/
 # 3 "platform_ilp32_c90.c"
 
 /*
@@ -27,27 +27,27 @@ void *lex_integer[] = {
 	4294967296,
 	/* expect+1: warning: integer constant out of range [252] */
 	0x0001,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	9223372036854775807,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	0x7fff,
 	/* expect+1: warning: integer constant out of range [252] */
 	9223372036854775808,
 	/* expect+1: warning: integer constant out of range [252] */
 	0x8000,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	18446744073709551615,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	0x,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	18446744073709551616,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	0x0001,
 
 	/* expect+1: ... integer 'unsigned int' ... */
@@ -66,8 +66,8 @@ void *lex_integer[] = {
 	4294967296U,
 	/* expect+1: warning: integer constant out of range [252] */
 	0x0001U,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	9223372036854775807U,
 	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: ... integer 'unsigned long' ... */
@@ -76,17 +76,17 @@ void *lex_integer[] = {
 	9223372036854775808U,
 	/* expect+1: warning: integer constant out of range [252] */
 	0x8000U,
-	/* expect+2: ... integer 'unsigned long' ... */
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+2: warning: integer constant out of range [252] */
+	/* expect+1: ... integer 'unsigned long' ... */
 	18446744073709551615U,
-	/* expect+2: ... integer 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 08:26:07 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua platform_ilp32_c90.c
platform_ilp32_c99.c platform_ilp32_trad.c

Log Message:
tests/lint: sort diagnostics in ilp32 tests chronologically


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_ilp32_c90.c \
src/tests/usr.bin/xlint/lint1/platform_ilp32_c99.c \
src/tests/usr.bin/xlint/lint1/platform_ilp32_trad.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 08:17:27 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: accept.sh c11.c c23.c check-expect.lua
d_c99_init.c decl.c decl_arg.c decl_direct_abstract.c msg_083.c
msg_090.c msg_092.c msg_095.c msg_128.c msg_132.c msg_138.c
msg_165.c msg_182.c msg_188.c msg_249.c msg_277.c msg_324.c
msg_343.c op_colon.c platform_lp64_c90.c platform_lp64_c99.c
platform_lp64_trad.c

Log Message:
tests/lint: sort multiple diagnostics per line chronologically

For now, the chronologic order is not enforced but has to be established
manually, for example by removing all 'expect' comment lines and
regenerating them with 'accept.sh -u'.

While here, clean up a few instances that came up when regenerating the
'expect' comments, such as wrong indentation or needless deviation from
the 'expect+1' form.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/accept.sh \
src/tests/usr.bin/xlint/lint1/msg_249.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/c11.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/c23.c \
src/tests/usr.bin/xlint/lint1/msg_083.c \
src/tests/usr.bin/xlint/lint1/msg_090.c \
src/tests/usr.bin/xlint/lint1/msg_095.c \
src/tests/usr.bin/xlint/lint1/msg_128.c \
src/tests/usr.bin/xlint/lint1/op_colon.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/check-expect.lua \
src/tests/usr.bin/xlint/lint1/msg_324.c
cvs rdiff -u -r1.46 -r1.47 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.27 -r1.28 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/decl_arg.c
cvs rdiff -u -r1.11 -r1.12 \
src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_092.c \
src/tests/usr.bin/xlint/lint1/msg_138.c \
src/tests/usr.bin/xlint/lint1/msg_165.c \
src/tests/usr.bin/xlint/lint1/msg_182.c \
src/tests/usr.bin/xlint/lint1/msg_188.c
cvs rdiff -u -r1.32 -r1.33 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_277.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_343.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_lp64_c90.c \
src/tests/usr.bin/xlint/lint1/platform_lp64_c99.c \
src/tests/usr.bin/xlint/lint1/platform_lp64_trad.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/accept.sh
diff -u src/tests/usr.bin/xlint/lint1/accept.sh:1.14 src/tests/usr.bin/xlint/lint1/accept.sh:1.15
--- src/tests/usr.bin/xlint/lint1/accept.sh:1.14	Sat Jul  8 10:01:17 2023
+++ src/tests/usr.bin/xlint/lint1/accept.sh	Sun Jan 28 08:17:27 2024
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: accept.sh,v 1.14 2023/07/08 10:01:17 rillig Exp $
+# $NetBSD: accept.sh,v 1.15 2024/01/28 08:17:27 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -26,7 +26,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
-# usage: accept.sh ...
+# usage: accept.sh [-u] ...
 #
 #	Run one or more lint tests, saving their output in the corresponding
 #	.exp files, for incorporating the messages into the .c files as
Index: src/tests/usr.bin/xlint/lint1/msg_249.c
diff -u src/tests/usr.bin/xlint/lint1/msg_249.c:1.14 src/tests/usr.bin/xlint/lint1/msg_249.c:1.15
--- src/tests/usr.bin/xlint/lint1/msg_249.c:1.14	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_249.c	Sun Jan 28 08:17:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_249.c,v 1.14 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_249.c,v 1.15 2024/01/28 08:17:27 rillig Exp $	*/
 # 3 "msg_249.c"
 
 // Test for message: syntax error '%s' [249]
@@ -30,8 +30,8 @@ int recover_from_rbrace;
 void
 function(void)
 {
-	/* expect+2: warning: statement not reached [193] */
 	if (0)
+		/* expect+1: warning: statement not reached [193] */
 		;
 	/* expect+1: error: syntax error ')' [249] */
 	);
@@ -71,9 +71,9 @@ int gcc_statement_expression_1 = ({
 unused_label:
 	1;
 	1;
+	/* expect+2: error: syntax error 'labels are only valid inside a function' [249] */
+	/* expect+1: error: non-constant initializer [177] */
 });
-/* expect-1: error: non-constant initializer [177] */
-/* expect-2: error: syntax error 'labels are only valid inside a function' [249] */
 
 /* Even another function definition does not help. */
 void
@@ -85,6 +85,6 @@ int gcc_statement_expression_2 = ({
 unused_label:
 	1;
 	1;
+	/* expect+2: error: syntax error 'labels are only valid inside a function' [249] */
+	/* expect+1: error: non-constant initializer [177] */
 });
-/* expect-1: error: non-constant initializer [177] */
-/* expect-2: error: syntax error 'labels are only valid inside a function' [249] */

Index: src/tests/usr.bin/xlint/lint1/c11.c
diff -u 

CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 08:17:27 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: accept.sh c11.c c23.c check-expect.lua
d_c99_init.c decl.c decl_arg.c decl_direct_abstract.c msg_083.c
msg_090.c msg_092.c msg_095.c msg_128.c msg_132.c msg_138.c
msg_165.c msg_182.c msg_188.c msg_249.c msg_277.c msg_324.c
msg_343.c op_colon.c platform_lp64_c90.c platform_lp64_c99.c
platform_lp64_trad.c

Log Message:
tests/lint: sort multiple diagnostics per line chronologically

For now, the chronologic order is not enforced but has to be established
manually, for example by removing all 'expect' comment lines and
regenerating them with 'accept.sh -u'.

While here, clean up a few instances that came up when regenerating the
'expect' comments, such as wrong indentation or needless deviation from
the 'expect+1' form.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/accept.sh \
src/tests/usr.bin/xlint/lint1/msg_249.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/c11.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/c23.c \
src/tests/usr.bin/xlint/lint1/msg_083.c \
src/tests/usr.bin/xlint/lint1/msg_090.c \
src/tests/usr.bin/xlint/lint1/msg_095.c \
src/tests/usr.bin/xlint/lint1/msg_128.c \
src/tests/usr.bin/xlint/lint1/op_colon.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/check-expect.lua \
src/tests/usr.bin/xlint/lint1/msg_324.c
cvs rdiff -u -r1.46 -r1.47 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.27 -r1.28 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/decl_arg.c
cvs rdiff -u -r1.11 -r1.12 \
src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_092.c \
src/tests/usr.bin/xlint/lint1/msg_138.c \
src/tests/usr.bin/xlint/lint1/msg_165.c \
src/tests/usr.bin/xlint/lint1/msg_182.c \
src/tests/usr.bin/xlint/lint1/msg_188.c
cvs rdiff -u -r1.32 -r1.33 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_277.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_343.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/platform_lp64_c90.c \
src/tests/usr.bin/xlint/lint1/platform_lp64_c99.c \
src/tests/usr.bin/xlint/lint1/platform_lp64_trad.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 06:57:41 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: lex_integer_ilp32.c msg_218.c

Log Message:
tests/lint: fix tests for integer constants on ILP32 platforms

The comment in msg_218 was both off-topic and wrong, so remove it.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_218.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan 28 06:57:41 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: lex_integer_ilp32.c msg_218.c

Log Message:
tests/lint: fix tests for integer constants on ILP32 platforms

The comment in msg_218 was both off-topic and wrong, so remove it.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_218.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/lex_integer_ilp32.c
diff -u src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c:1.8 src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c:1.9
--- src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c:1.8	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/lex_integer_ilp32.c	Sun Jan 28 06:57:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lex_integer_ilp32.c,v 1.8 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: lex_integer_ilp32.c,v 1.9 2024/01/28 06:57:41 rillig Exp $	*/
 # 3 "lex_integer_ilp32.c"
 
 /*
@@ -23,12 +23,11 @@ test_signed_int(void)
 
 	sinki(2147483647);
 
-	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
+	/* expect+1: warning: conversion of 'long long' to 'int' is out of range, arg #1 [295] */
 	sinki(2147483648);
 
 	sinki(-2147483647);
 
-	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
 	sinki(-2147483648);
 }
 
@@ -43,6 +42,6 @@ test_unsigned_int(void)
 	sinku(2147483648U);
 	sinku(4294967295U);
 
-	/* expect+1: warning: integer constant out of range [252] */
+	/* expect+1: warning: conversion of 'unsigned long long' to 'unsigned int' is out of range, arg #1 [295] */
 	sinku(4294967296U);
 }

Index: src/tests/usr.bin/xlint/lint1/msg_218.c
diff -u src/tests/usr.bin/xlint/lint1/msg_218.c:1.9 src/tests/usr.bin/xlint/lint1/msg_218.c:1.10
--- src/tests/usr.bin/xlint/lint1/msg_218.c:1.9	Sat Aug 26 10:43:53 2023
+++ src/tests/usr.bin/xlint/lint1/msg_218.c	Sun Jan 28 06:57:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_218.c,v 1.9 2023/08/26 10:43:53 rillig Exp $	*/
+/*	$NetBSD: msg_218.c,v 1.10 2024/01/28 06:57:41 rillig Exp $	*/
 # 3 "msg_218.c"
 
 /* Test for message: C90 treats constant as unsigned, op '%s' [218] */
@@ -20,40 +20,41 @@ void sink_int(int);
 void
 test_signed_int(void)
 {
+	/* expect+3: warning: integer constant out of range [252] */
 	/* expect+2: warning: C90 treats constant as unsigned, op '-' [218] */
 	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
 	sink_int(-2147483648);
 }
 
 /*
- * In traditional C, integer constants with an 'L' suffix that didn't fit
- * into 'long' were promoted to the next larger integer type, if that existed
- * at all, as the suffix 'LL' was introduced by C90.
- *
- * Starting with C90, integer constants with an 'L' suffix that didn't fit
- * into 'long' were promoted to 'unsigned long' first, before trying 'long
- * long'.
- *
- * In C99 mode, this distinction is no longer necessary since it is far
- * enough from traditional C.
+ * TODO: Investigate whether the message 218 is actually correct.
+ * See C1978 2.4.1 "Integer constants" and 6.6 "Arithmetic conversions".
  */
 void
 compare_large_constant(void)
 {
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = s32 < 30L;
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = 30L < s32;
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = u32 < 30L;
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = 30L < u32;
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = s64 < 30L;
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = 30L < s64;
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = u64 < 30L;
+	/* expect+2: warning: integer constant out of range [252] */
 	/* expect+1: warning: C90 treats constant as unsigned, op '<' [218] */
 	cond = 30L < u64;
 }



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jan  8 17:11:32 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c

Log Message:
tests/lint: fix overflow test for 32-bit platforms (since yesterday)

Plain integer constants without suffix are first tried to fit into
'int', then 'long', but not 'long long'.  This means that numbers larger
than 32 bits must be written with the LL suffix.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_141.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_141.c
diff -u src/tests/usr.bin/xlint/lint1/msg_141.c:1.8 src/tests/usr.bin/xlint/lint1/msg_141.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_141.c:1.8	Sun Jan  7 21:19:42 2024
+++ src/tests/usr.bin/xlint/lint1/msg_141.c	Mon Jan  8 17:11:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_141.c,v 1.8 2024/01/07 21:19:42 rillig Exp $	*/
+/*	$NetBSD: msg_141.c,v 1.9 2024/01/08 17:11:32 rillig Exp $	*/
 # 3 "msg_141.c"
 
 // Test for message: operator '%s' produces integer overflow [141]
@@ -68,7 +68,7 @@ unsigned long long overflow_unsigned[] =
 	0x1U * 0x1U,
 	0x1ULL * 0x1U,
 	/* expect+1: warning: operator '*' produces integer overflow [141] */
-	0x1U * 0x1U,
+	0x1ULL * 0x1ULL,
 
 	// '/'
 
@@ -123,12 +123,12 @@ long long overflow_signed[] = {
 	// unary '+'
 
 	+(unsigned char)255,
-	+0x7fff,
+	+0x7fffLL,
 
 	// unary '-'
 
 	-(unsigned char)255,
-	-0x7fff,
+	-0x7fffLL,
 
 	// '~'
 



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jan  8 17:11:32 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_141.c

Log Message:
tests/lint: fix overflow test for 32-bit platforms (since yesterday)

Plain integer constants without suffix are first tried to fit into
'int', then 'long', but not 'long long'.  This means that numbers larger
than 32 bits must be written with the LL suffix.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_141.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  7 21:19:42 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_107.c msg_141.c msg_305.c

Log Message:
tests/lint: test operators, integer overflow, conversions


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_107.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_141.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_305.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_107.c
diff -u src/tests/usr.bin/xlint/lint1/msg_107.c:1.6 src/tests/usr.bin/xlint/lint1/msg_107.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_107.c:1.6	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_107.c	Sun Jan  7 21:19:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_107.c,v 1.6 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_107.c,v 1.7 2024/01/07 21:19:42 rillig Exp $	*/
 # 3 "msg_107.c"
 
 // Test for message: operands of '%s' have incompatible types '%s' and '%s' [107]
@@ -12,3 +12,12 @@ compare(double d, void *ptr)
 	/* expect+1: error: operands of '==' have incompatible types 'double' and 'pointer to void' [107] */
 	return d == ptr;
 }
+
+static inline void
+typeok_minus(const char *p, int i, double d)
+{
+	if (p[i] != p[(int)d])
+		return;
+	/* expect+1: error: operands of '-' have incompatible types 'pointer to const char' and 'double' [107] */
+	return (p - i) - (p - d);
+}

Index: src/tests/usr.bin/xlint/lint1/msg_141.c
diff -u src/tests/usr.bin/xlint/lint1/msg_141.c:1.7 src/tests/usr.bin/xlint/lint1/msg_141.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_141.c:1.7	Sun Jul  9 11:01:27 2023
+++ src/tests/usr.bin/xlint/lint1/msg_141.c	Sun Jan  7 21:19:42 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_141.c,v 1.7 2023/07/09 11:01:27 rillig Exp $	*/
+/*	$NetBSD: msg_141.c,v 1.8 2024/01/07 21:19:42 rillig Exp $	*/
 # 3 "msg_141.c"
 
 // Test for message: operator '%s' produces integer overflow [141]
@@ -9,13 +9,13 @@
  * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
  * overflow in '-'.
  */
-int signed_int_max = (1u << 31) - 1;
+int signed_int_max = (1U << 31) - 1;
 
 /*
  * Before tree.c 1.347 from 2021-08-23, lint wrongly warned about integer
  * overflow in '-'.
  */
-unsigned int unsigned_int_max = (1u << 31) - 1;
+unsigned int unsigned_int_max = (1U << 31) - 1;
 
 /* expect+1: warning: operator '+' produces integer overflow [141] */
 int int_overflow = (1 << 30) + (1 << 30);
@@ -27,7 +27,184 @@ unsigned int intermediate_overflow = (1 
 unsigned int no_overflow = (1U << 30) + (1 << 30);
 
 /* expect+1: warning: operator '-' produces integer overflow [141] */
-unsigned int unsigned_int_min = 0u - (1u << 31);
+unsigned int unsigned_int_min = 0U - (1U << 31);
 
 /* expect+1: warning: operator '-' produces integer overflow [141] */
-unsigned int unsigned_int_min_unary = -(1u << 31);
+unsigned int unsigned_int_min_unary = -(1U << 31);
+
+enum {
+	INT_MAX = 2147483647,
+	INT_MIN = -INT_MAX - 1,
+};
+
+unsigned long long overflow_unsigned[] = {
+
+	// unary '+'
+
+	+0U,
+	+~0U,
+	+~0ULL,
+
+	// unary '-'
+
+	-0U,
+	-~0U,
+	/* expect+1: warning: operator '-' produces integer overflow [141] */
+	-(1ULL << 63),
+	/* expect+1: warning: operator '-' produces integer overflow [141] */
+	-(1U << 31),
+
+	// '~'
+
+	~0U,
+	~~0U,
+	~0ULL,
+	~~0ULL,
+
+	// '*'
+
+	0x10001U * 0xU,
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	0x1U * 0x1U,
+	0x1ULL * 0x1U,
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	0x1U * 0x1U,
+
+	// '/'
+
+	0xU / ~0U,
+	/* expect+1: error: division by 0 [139] */
+	0xU / 0U,
+
+	// '%'
+
+	0xU % ~0U,
+	/* expect+1: error: modulus by 0 [140] */
+	0xU % 0U,
+
+	// '+'
+
+	0U + 0U,
+	~0U + 0U,
+	0U + ~0U,
+	/* expect+1: warning: operator '+' produces integer overflow [141] */
+	~0U + 1U,
+	/* expect+1: warning: operator '+' produces integer overflow [141] */
+	1U + ~0U,
+	/* expect+1: warning: operator '+' produces integer overflow [141] */
+	~0U + ~0U,
+
+	// '-'
+
+	0U - 0U,
+	0U - 1U,
+	0U - ~0U,
+
+	// '<<'
+
+	256U << 23,
+	/* expect+1: warning: operator '<<' produces integer overflow [141] */
+	256U << 24,
+
+	// '>>'
+
+	10U >> 1,
+	-10U >> 1,
+
+	// bitwise operators
+
+	1U & -1U,
+	1U ^ -1U,
+	1U | -1U,
+};
+
+long long overflow_signed[] = {
+
+	// unary '+'
+
+	+(unsigned char)255,
+	+0x7fff,
+
+	// unary '-'
+
+	-(unsigned char)255,
+	-0x7fff,
+
+	// '~'
+
+	~0,
+	~1,
+	~1,
+	~-1,
+
+	// '*'
+
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	0x1 * 0x8000,
+	/* expect+1: warning: operator '*' produces integer overflow [141] */
+	0x1 * 0x1,
+	0x1LL * 0x1,
+	/* TODO: expect+1: warning: operator '*' produces integer overflow [141] */
+	

CVS commit: src/tests/usr.bin/xlint/lint1

2024-01-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jan  7 21:19:42 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_107.c msg_141.c msg_305.c

Log Message:
tests/lint: test operators, integer overflow, conversions


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_107.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_141.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_305.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 22:44:22 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_promote.exp-ln
expr_promote_trad.exp-ln

Log Message:
tests/lint: add spaces to expected files, for better readability


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln \
src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln

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/expr_promote.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln:1.3 src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln:1.4
--- src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln:1.3	Wed Jan  4 05:47:19 2023
+++ src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln	Sat Dec 30 22:44:22 2023
@@ -1,5 +1,5 @@
-0sexpr_promote.c
-Sexpr_promote.c
-10d0.10e4sinkF2PcCEV
-59c0.59i4sinkf20PcCBIIuILuLQuQDDlDsXXlXeT331.0.0V
-37d0.37d6callerF1PsT116arithmetic_typesV
+0 s expr_promote.c
+S expr_promote.c
+10 d 0.10 e 4sink F2 PcC E V
+59 c 0.59 i 4sink f20 PcC B I I I I I I uI L uL Q uQ D D lD sX X lX eT3 31.0.0 V
+37 d 0.37 d 6caller F1 PsT1 16arithmetic_types V
Index: src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln:1.3 src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln:1.4
--- src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln:1.3	Wed Jan  4 05:47:19 2023
+++ src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln	Sat Dec 30 22:44:22 2023
@@ -1,5 +1,5 @@
-0sexpr_promote_trad.c
-Sexpr_promote_trad.c
-10d0.10e4sinkFI
-50c0.50s1""i4sinkf12PCIuIIuIIuILuLDDeT330.0.0I
-35d0.35do6callerf1PsT116arithmetic_typesI
+0 s expr_promote_trad.c
+S expr_promote_trad.c
+10 d 0.10 e 4sink F I
+50 c 0.50 s1"" i 4sink f12 PC I uI I uI I uI L uL D D eT3 30.0.0 I
+35 d 0.35 do 6caller f1 PsT1 16arithmetic_types I



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 22:44:22 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_promote.exp-ln
expr_promote_trad.exp-ln

Log Message:
tests/lint: add spaces to expected files, for better readability


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/expr_promote.exp-ln \
src/tests/usr.bin/xlint/lint1/expr_promote_trad.exp-ln

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 17:09:42 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c

Log Message:
tests/lint: sync comments in test for strict bool mode with reality


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.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/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.47 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.48
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.47	Sat Dec 30 15:37:27 2023
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Sat Dec 30 17:09:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict.c,v 1.47 2023/12/30 15:37:27 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict.c,v 1.48 2023/12/30 17:09:42 rillig Exp $	*/
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -59,14 +59,14 @@
  *
  * strict-bool-bitwise-and:
  *	Expressions of the form "flags & FLAG" are compatible with _Bool if
- *	the left operand has enum type, the right operand is an integer
- *	constant and the resulting value is used in a context where it is
- *	implicitly and immediately compared to zero.
+ *	the resulting value is used in a context where it is implicitly and
+ *	immediately compared to zero.
  *
  *	Note: An efficient implementation technique for a collection of bool
  *	flags is an enum.  The enum declaration groups the available
  *	constants, and as of 2020, compilers such as GCC and Clang have basic
- *	support for detecting type mismatches on enums.
+ *	support for detecting type mismatches on enums.  Another implementation
+ *	technique for bit sets is a plain integer.
  *
  *	Note: Examples for such contexts are controlling expressions or the
  *	operands of the operators '!', '&&', '||'.
@@ -795,14 +795,14 @@ strict_bool_operator_result(bool b)
 /*
  * strict-bool-bitwise-and:
  *	Expressions of the form "flags & FLAG" are compatible with _Bool if
- *	the left operand has enum type, the right operand is an integer
- *	constant and the resulting value is used in a context where it is
- *	implicitly and immediately compared to zero.
+ *	the resulting value is used in a context where it is implicitly and
+ *	immediately compared to zero.
  *
  *	Note: Examples for such contexts are controlling expressions or the
  *	operands of the operators '!', '&&', '||'.
  *
- *	Note: Counterexamples for contexts are assignments to a bool variable.
+ *	Note: Counterexamples for contexts are assignments to a bool variable,
+ *	as before C99, the conversion was defined differently.
  *
  *	Note: These rules ensure that conforming code can be compiled without
  *	change in behavior using old compilers that implement bool as an



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 17:09:42 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c

Log Message:
tests/lint: sync comments in test for strict bool mode with reality


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 15:18:57 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c

Log Message:
tests/lint: test '&' for non-enum types in strict bool mode


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.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/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.45 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.46
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.45	Sun Dec 10 14:59:47 2023
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Sat Dec 30 15:18:57 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict.c,v 1.45 2023/12/10 14:59:47 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict.c,v 1.46 2023/12/30 15:18:57 rillig Exp $	*/
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -880,6 +880,32 @@ query_flag_from_enum_bit_set(enum Flags 
 		println("FLAG28 is set");
 }
 
+void
+query_flag_from_int(int flags)
+{
+	/* expect+1: error: controlling expression must be bool, not 'int' [333] */
+	if (flags & FLAG0)
+		println("FLAG0 is set");
+
+	if ((flags & FLAG1) != 0)
+		println("FLAG1 is set");
+
+	if ((flags & (FLAG0 | FLAG1)) == (FLAG0 | FLAG1))
+		println("FLAG0 and FLAG1 are both set");
+
+	/* expect+2: error: left operand of '&&' must be bool, not 'int' [331] */
+	/* expect+1: error: right operand of '&&' must be bool, not 'int' [332] */
+	if (flags & FLAG0 && flags & FLAG1)
+		println("FLAG0 and FLAG1 are both set");
+
+	if ((flags & (FLAG0 | FLAG1)) != 0)
+		println("At least one of FLAG0 and FLAG1 is set");
+
+	/* expect+1: error: controlling expression must be bool, not 'int' [333] */
+	if (flags & FLAG28)
+		println("FLAG28 is set");
+}
+
 
 void
 strict_bool_operator_eq_bool_int(void)
@@ -963,10 +989,10 @@ typedef struct stdio_file {
 int ferror(FILE *);
 FILE stdio_files[3];
 FILE *stdio_stdout;
-# 967 "d_c99_bool_strict.c" 2
+# 993 "d_c99_bool_strict.c" 2
 # 1 "string.h" 1 3 4
 int strcmp(const char *, const char *);
-# 970 "d_c99_bool_strict.c" 2
+# 996 "d_c99_bool_strict.c" 2
 
 void
 controlling_expression(FILE *f, const char *a, const char *b)
@@ -1000,9 +1026,9 @@ controlling_expression(FILE *f, const ch
 	 */
 	/* expect+5: error: controlling expression must be bool, not 'int' [333] */
 	if (ferror(
-# 1004 "d_c99_bool_strict.c" 3 4
+# 1030 "d_c99_bool_strict.c" 3 4
 	_files[1]
-# 1006 "d_c99_bool_strict.c"
+# 1032 "d_c99_bool_strict.c"
 	))
 		return;
 
@@ -1018,9 +1044,9 @@ controlling_expression(FILE *f, const ch
 	 */
 	/* expect+5: error: controlling expression must be bool, not 'int' [333] */
 	if (ferror(
-# 1022 "d_c99_bool_strict.c" 3 4
+# 1048 "d_c99_bool_strict.c" 3 4
 	stdio_stdout
-# 1024 "d_c99_bool_strict.c"
+# 1050 "d_c99_bool_strict.c"
 	))
 		return;
 
@@ -1033,9 +1059,9 @@ controlling_expression(FILE *f, const ch
 	 */
 	/* expect+5: error: controlling expression must be bool, not 'int' [333] */
 	if (ferror(
-# 1037 "d_c99_bool_strict.c" 3 4
+# 1063 "d_c99_bool_strict.c" 3 4
 	(stdio_stdout)
-# 1039 "d_c99_bool_strict.c"
+# 1065 "d_c99_bool_strict.c"
 	))
 		return;
 
@@ -1059,9 +1085,9 @@ controlling_expression(FILE *f, const ch
 	 */
 	/* expect+5: error: controlling expression must be bool, not 'int' [333] */
 	if (ferror(
-# 1063 "d_c99_bool_strict.c" 3 4
+# 1089 "d_c99_bool_strict.c" 3 4
 	stdio_stdout /* comment */
-# 1065 "d_c99_bool_strict.c"
+# 1091 "d_c99_bool_strict.c"
 	))
 		return;
 }



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec 30 15:18:57 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c

Log Message:
tests/lint: test '&' for non-enum types in strict bool mode


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec  2 23:54:49 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_schar.c platform_uchar.c

Log Message:
tests/lint: add more test cases for nonportable character comparison


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_schar.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_uchar.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/platform_schar.c
diff -u src/tests/usr.bin/xlint/lint1/platform_schar.c:1.4 src/tests/usr.bin/xlint/lint1/platform_schar.c:1.5
--- src/tests/usr.bin/xlint/lint1/platform_schar.c:1.4	Wed Feb 22 22:30:40 2023
+++ src/tests/usr.bin/xlint/lint1/platform_schar.c	Sat Dec  2 23:54:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_schar.c,v 1.4 2023/02/22 22:30:40 rillig Exp $	*/
+/*	$NetBSD: platform_schar.c,v 1.5 2023/12/02 23:54:49 rillig Exp $	*/
 # 3 "platform_schar.c"
 
 /*
@@ -6,9 +6,14 @@
  * representation as signed char.
  */
 
-/* lint1-extra-flags: -c -h -a -p -b -r -z */
+/* lint1-extra-flags: -c -h -a -p -b -r -z -X 161 */
 /* lint1-only-if: schar */
 
-/* CONSTCOND */
 /* expect+1: warning: nonportable character comparison '-128 < ?' [230] */
-typedef int is_signed[(char)'\200' < (char)'\177' ? 1 : -1];
+typedef int char_char[(char)'\200' < (char)'\177' ? 1 : -1];
+/* expect+1: warning: nonportable character comparison '-128 < ?' [230] */
+typedef int char_int[(char)'\200' < (char)127 ? 1 : -1];
+/* expect+1: warning: nonportable character comparison '-128 < ?' [230] */
+typedef int int_char[(char)-128 < (char)'\177' ? 1 : -1];
+/* expect+1: warning: nonportable character comparison '-128 < ?' [230] */
+typedef int int_int[(char)-128 < (char)127 ? 1 : -1];

Index: src/tests/usr.bin/xlint/lint1/platform_uchar.c
diff -u src/tests/usr.bin/xlint/lint1/platform_uchar.c:1.3 src/tests/usr.bin/xlint/lint1/platform_uchar.c:1.4
--- src/tests/usr.bin/xlint/lint1/platform_uchar.c:1.3	Wed Feb 22 22:12:35 2023
+++ src/tests/usr.bin/xlint/lint1/platform_uchar.c	Sat Dec  2 23:54:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_uchar.c,v 1.3 2023/02/22 22:12:35 rillig Exp $	*/
+/*	$NetBSD: platform_uchar.c,v 1.4 2023/12/02 23:54:49 rillig Exp $	*/
 # 3 "platform_uchar.c"
 
 /*
@@ -6,9 +6,14 @@
  * representation as unsigned char.
  */
 
-/* lint1-extra-flags: -c -h -a -p -b -r -z */
+/* lint1-extra-flags: -c -h -a -p -b -r -z -X 161 */
 /* lint1-only-if: uchar */
 
-/* CONSTCOND */
 /* expect+1: warning: nonportable character comparison '< 128' [230] */
-typedef int is_unsigned[(char)'\177' < (char)'\200' ? 1 : -1];
+typedef int char_char[(char)'\177' < (char)'\200' ? 1 : -1];
+/* expect+1: warning: nonportable character comparison '< 128' [230] */
+typedef int int_char[(char)127 < (char)'\200' ? 1 : -1];
+/* expect+1: warning: nonportable character comparison '< 128' [230] */
+typedef int char_int[(char)'\177' < (char)128 ? 1 : -1];
+/* expect+1: warning: nonportable character comparison '< 128' [230] */
+typedef int int_int[(char)127 < (char)128 ? 1 : -1];



CVS commit: src/tests/usr.bin/xlint/lint1

2023-12-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Dec  2 23:54:49 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_schar.c platform_uchar.c

Log Message:
tests/lint: add more test cases for nonportable character comparison


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/platform_schar.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/platform_uchar.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-10-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Oct 22 21:30:32 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl_direct_abstract.c

Log Message:
tests/lint: test GCC attributes after abstract function type


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/tests/usr.bin/xlint/lint1/decl_direct_abstract.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/decl_direct_abstract.c
diff -u src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.10 src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.11
--- src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.10	Wed Aug  2 21:11:35 2023
+++ src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c	Sun Oct 22 21:30:32 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl_direct_abstract.c,v 1.10 2023/08/02 21:11:35 rillig Exp $	*/
+/*	$NetBSD: decl_direct_abstract.c,v 1.11 2023/10/22 21:30:32 rillig Exp $	*/
 # 3 "decl_direct_abstract.c"
 
 /*
@@ -215,3 +215,12 @@ int prototype_named_32_return_04[-1000 -
 /* expect+2: error: cannot take size/alignment of function type 'function(struct typedef a32) returning struct typedef a08' [144] */
 /* expect+1: error: negative array dimension (-1000) [20] */
 int prototype_named_32_return_08[-1000 - (int)sizeof(a08(a32 arg))];
+
+void
+abstract_decl_param_list_with_attributes(void)
+{
+	typedef int unspecified_parameters(void (*)() __attribute__(()));
+	typedef int no_parameters(void (*)(void) __attribute__(()));
+	typedef int single_parameter(void (*)(int) __attribute__(()));
+	typedef int several_parameters(void (*)(int, int) __attribute__(()));
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-10-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Oct 22 21:30:32 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl_direct_abstract.c

Log Message:
tests/lint: test GCC attributes after abstract function type


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-09-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Sep 12 06:51:02 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_192.c

Log Message:
tests/lint: show that '?:' skips untaken branches early

This is probably done to avoid wrong warnings from branches that are
only taken on other platforms, but it also generates a wrong 'unused'
warning.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_192.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_192.c
diff -u src/tests/usr.bin/xlint/lint1/msg_192.c:1.6 src/tests/usr.bin/xlint/lint1/msg_192.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_192.c:1.6	Sun Jul  9 11:18:55 2023
+++ src/tests/usr.bin/xlint/lint1/msg_192.c	Tue Sep 12 06:51:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_192.c,v 1.6 2023/07/09 11:18:55 rillig Exp $	*/
+/*	$NetBSD: msg_192.c,v 1.7 2023/09/12 06:51:02 rillig Exp $	*/
 # 3 "msg_192.c"
 
 // Test for message: '%s' unused in function '%s' [192]
@@ -12,3 +12,32 @@ example(int param)
 	/* expect+1: warning: 'local' unused in function 'example' [192] */
 	int local;
 }
+
+
+void assertion_failed(const char *);
+
+void
+assert_true(void)
+{
+	sizeof(char) == 1
+	? (void)0
+/* FIXME: '__func__' is used, the code is just not reachable. */
+/* expect+1: warning: '__func__' unused in function 'assert_true' [192] */
+	: assertion_failed(__func__);
+}
+
+void
+assert_false(void)
+{
+	sizeof(char) == 0
+	? (void)0
+	: assertion_failed(__func__);
+}
+
+void
+assert_unknown(_Bool cond)
+{
+	cond
+	? (void)0
+	: assertion_failed(__func__);
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-09-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Sep 12 06:51:02 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_192.c

Log Message:
tests/lint: show that '?:' skips untaken branches early

This is probably done to avoid wrong warnings from branches that are
only taken on other platforms, but it also generates a wrong 'unused'
warning.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_192.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  7 06:17:35 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_196.c

Log Message:
tests/lint: test case labels with out-of-bounds values


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_196.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_196.c
diff -u src/tests/usr.bin/xlint/lint1/msg_196.c:1.3 src/tests/usr.bin/xlint/lint1/msg_196.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_196.c:1.3	Thu Jun 16 16:58:36 2022
+++ src/tests/usr.bin/xlint/lint1/msg_196.c	Thu Sep  7 06:17:35 2023
@@ -1,8 +1,20 @@
-/*	$NetBSD: msg_196.c,v 1.3 2022/06/16 16:58:36 rillig Exp $	*/
+/*	$NetBSD: msg_196.c,v 1.4 2023/09/07 06:17:35 rillig Exp $	*/
 # 3 "msg_196.c"
 
 // Test for message: case label affected by conversion [196]
 
-/* expect+1: error: syntax error ':' [249] */
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -X 351 */
+
+void
+switch_int_unsigned(int x)
+{
+	switch (x) {
+		/* expect+1: warning: case label affected by conversion [196] */
+	case (unsigned int)-1:
+		/* expect+1: warning: case label affected by conversion [196] */
+	case -2U:
+		/* expect+1: warning: case label affected by conversion [196] */
+	case 0x1000200030004000ULL:
+		return;
+	}
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-09-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep  7 06:17:35 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_196.c

Log Message:
tests/lint: test case labels with out-of-bounds values


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_196.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Aug 11 04:27:49 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_255.c

Log Message:
tests/lint: test parsing of preprocessing directives


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_255.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/check-expect.lua
diff -u src/tests/usr.bin/xlint/lint1/check-expect.lua:1.7 src/tests/usr.bin/xlint/lint1/check-expect.lua:1.8
--- src/tests/usr.bin/xlint/lint1/check-expect.lua:1.7	Sat Jul  8 11:03:00 2023
+++ src/tests/usr.bin/xlint/lint1/check-expect.lua	Fri Aug 11 04:27:49 2023
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.7 2023/07/08 11:03:00 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.8 2023/08/11 04:27:49 rillig Exp $
 
 --[[
 
@@ -62,7 +62,7 @@ end
 --
 -- example return values:
 --   {
--- ["file.c(18)"] = {"invalid argument 'a'", "invalid argument 'b'"},
+-- ["file.c(18)"] = {"syntax error 'a' [249]", "syntax error 'b' [249]"},
 -- ["file.c(23)"] = {"not a constant expression [123]"},
 --   },
 --   { "file.c(18)", "file.c(23)" }
@@ -132,7 +132,7 @@ local function load_exp(exp_fname)
 
   local messages = {}
   for exp_lineno, line in ipairs(lines) do
-for location, message in line:gmatch("(%S+%(%d+%)): (.+)$") do
+for location, message in line:gmatch("(.+%(%d+%)): (.+)$") do
   table.insert(messages, {
 exp_lineno = exp_lineno,
 location = location,

Index: src/tests/usr.bin/xlint/lint1/msg_255.c
diff -u src/tests/usr.bin/xlint/lint1/msg_255.c:1.5 src/tests/usr.bin/xlint/lint1/msg_255.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_255.c:1.5	Sun Jul  9 11:01:27 2023
+++ src/tests/usr.bin/xlint/lint1/msg_255.c	Fri Aug 11 04:27:49 2023
@@ -1,13 +1,45 @@
-/*	$NetBSD: msg_255.c,v 1.5 2023/07/09 11:01:27 rillig Exp $	*/
+/*	$NetBSD: msg_255.c,v 1.6 2023/08/11 04:27:49 rillig Exp $	*/
 # 3 "msg_255.c"
 
 // Test for message: undefined or invalid '#' directive [255]
 
 /* lint1-extra-flags: -X 351 */
 
+/* expect+1: warning: undefined or invalid '#' directive [255] */
+#
+
+/* expect+1: warning: undefined or invalid '#' directive [255] */
+#pragma
+
 #pragma once
 
 /* expect+1: warning: undefined or invalid '#' directive [255] */
 #fatal_error
 
+/* expect+1: warning: undefined or invalid '#' directive [255] */
+#ident "obsolete"
+
+/* expect+1: warning: undefined or invalid '#' directive [255] */
+#1
+
+// Sets the line number of the current file.
+# 2
+
+// Switch back to the main file.
+# 30 "msg_255.c"
+
+/* expect+1: warning: undefined or invalid '#' directive [255] */
+# 3/
+
+/* expect+1: warning: undefined or invalid '#' directive [255] */
+# 4 /
+
+/* expect+1: warning: undefined or invalid '#' directive [255] */
+# 5 "unfinished
+
+// An empty string means standard input; tabs may be used for spacing.
+#	6	""
+
+# 44 "msg_255.c"
+
 int dummy;



CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Aug 11 04:27:49 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_255.c

Log Message:
tests/lint: test parsing of preprocessing directives


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_255.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug  8 19:57:23 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132_ilp32.c

Log Message:
tests/lint: test integer conversions on ilp32 int platforms


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug  8 19:57:23 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_132_ilp32.c

Log Message:
tests/lint: test integer conversions on ilp32 int platforms


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_132_ilp32.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_132_ilp32.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c:1.3 src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c:1.3	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/msg_132_ilp32.c	Tue Aug  8 19:57:23 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132_ilp32.c,v 1.3 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: msg_132_ilp32.c,v 1.4 2023/08/08 19:57:23 rillig Exp $	*/
 # 3 "msg_132_ilp32.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -40,3 +40,214 @@ convert_pointer_to_smaller_integer(void 
 {
 	return (unsigned long)(ptr) >> 12;
 }
+
+_Bool bool_var;
+char char_var;
+signed char schar_var;
+unsigned char uchar_var;
+short short_var;
+unsigned short ushort_var;
+int int_var;
+unsigned int uint_var;
+long long_var;
+unsigned long ulong_var;
+long long llong_var;
+unsigned long long ullong_var;
+
+void
+convert_all(void)
+{
+	bool_var = bool_var;
+	bool_var = char_var;
+	bool_var = schar_var;
+	bool_var = uchar_var;
+	bool_var = short_var;
+	bool_var = ushort_var;
+	bool_var = int_var;
+	bool_var = uint_var;
+	bool_var = long_var;
+	bool_var = ulong_var;
+	bool_var = llong_var;
+	bool_var = ullong_var;
+
+	char_var = bool_var;
+	char_var = char_var;
+	char_var = schar_var;
+	char_var = uchar_var;
+	char_var = short_var;
+	char_var = ushort_var;
+	/* expect+1: warning: conversion from 'int' to 'char' may lose accuracy [132] */
+	char_var = int_var;
+	/* expect+1: warning: conversion from 'unsigned int' to 'char' may lose accuracy [132] */
+	char_var = uint_var;
+	/* expect+1: warning: conversion from 'long' to 'char' may lose accuracy [132] */
+	char_var = long_var;
+	/* expect+1: warning: conversion from 'unsigned long' to 'char' may lose accuracy [132] */
+	char_var = ulong_var;
+	/* expect+1: warning: conversion from 'long long' to 'char' may lose accuracy [132] */
+	char_var = llong_var;
+	/* expect+1: warning: conversion from 'unsigned long long' to 'char' may lose accuracy [132] */
+	char_var = ullong_var;
+
+	schar_var = bool_var;
+	schar_var = char_var;
+	schar_var = schar_var;
+	schar_var = uchar_var;
+	schar_var = short_var;
+	schar_var = ushort_var;
+	/* expect+1: warning: conversion from 'int' to 'signed char' may lose accuracy [132] */
+	schar_var = int_var;
+	/* expect+1: warning: conversion from 'unsigned int' to 'signed char' may lose accuracy [132] */
+	schar_var = uint_var;
+	/* expect+1: warning: conversion from 'long' to 'signed char' may lose accuracy [132] */
+	schar_var = long_var;
+	/* expect+1: warning: conversion from 'unsigned long' to 'signed char' may lose accuracy [132] */
+	schar_var = ulong_var;
+	/* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
+	schar_var = llong_var;
+	/* expect+1: warning: conversion from 'unsigned long long' to 'signed char' may lose accuracy [132] */
+	schar_var = ullong_var;
+
+	uchar_var = bool_var;
+	uchar_var = char_var;
+	uchar_var = schar_var;
+	uchar_var = uchar_var;
+	uchar_var = short_var;
+	uchar_var = ushort_var;
+	/* expect+1: warning: conversion from 'int' to 'unsigned char' may lose accuracy [132] */
+	uchar_var = int_var;
+	/* expect+1: warning: conversion from 'unsigned int' to 'unsigned char' may lose accuracy [132] */
+	uchar_var = uint_var;
+	/* expect+1: warning: conversion from 'long' to 'unsigned char' may lose accuracy [132] */
+	uchar_var = long_var;
+	/* expect+1: warning: conversion from 'unsigned long' to 'unsigned char' may lose accuracy [132] */
+	uchar_var = ulong_var;
+	/* expect+1: warning: conversion from 'long long' to 'unsigned char' may lose accuracy [132] */
+	uchar_var = llong_var;
+	/* expect+1: warning: conversion from 'unsigned long long' to 'unsigned char' may lose accuracy [132] */
+	uchar_var = ullong_var;
+
+	short_var = bool_var;
+	short_var = char_var;
+	short_var = schar_var;
+	short_var = uchar_var;
+	short_var = short_var;
+	short_var = ushort_var;
+	/* expect+1: warning: conversion from 'int' to 'short' may lose accuracy [132] */
+	short_var = int_var;
+	/* expect+1: warning: conversion from 'unsigned int' to 'short' may lose accuracy [132] */
+	short_var = uint_var;
+	/* expect+1: warning: conversion from 'long' to 'short' may lose accuracy [132] */
+	short_var = long_var;
+	/* expect+1: warning: conversion from 'unsigned long' to 'short' may lose accuracy [132] */
+	short_var = ulong_var;
+	/* expect+1: warning: conversion from 'long long' to 'short' may lose 

CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug  5 10:00:59 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_packed_structs.c

Log Message:
tests/lint: fix test for packed structs on 32-bit platforms


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_packed_structs.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/d_packed_structs.c
diff -u src/tests/usr.bin/xlint/lint1/d_packed_structs.c:1.5 src/tests/usr.bin/xlint/lint1/d_packed_structs.c:1.6
--- src/tests/usr.bin/xlint/lint1/d_packed_structs.c:1.5	Tue Aug  1 19:52:15 2023
+++ src/tests/usr.bin/xlint/lint1/d_packed_structs.c	Sat Aug  5 10:00:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_packed_structs.c,v 1.5 2023/08/01 19:52:15 rillig Exp $	*/
+/*	$NetBSD: d_packed_structs.c,v 1.6 2023/08/05 10:00:59 rillig Exp $	*/
 # 3 "d_packed_structs.c"
 
 /* packed tests */
@@ -30,12 +30,12 @@ typedef struct __packed {
 
 struct x {
 	char c;
-	long l;
+	long long l;
 } __packed;
 
 struct y {
 	char c;
-	long l;
+	long long l;
 };
 
 int a[sizeof(struct y) - sizeof(struct x) - 1];



CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Aug  5 10:00:59 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_packed_structs.c

Log Message:
tests/lint: fix test for packed structs on 32-bit platforms


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_packed_structs.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug  1 19:52:16 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_packed_structs.c decl.c

Log Message:
tests/lint: test packed and in-parameter declarations


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_packed_structs.c
cvs rdiff -u -r1.25 -r1.26 src/tests/usr.bin/xlint/lint1/decl.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/d_packed_structs.c
diff -u src/tests/usr.bin/xlint/lint1/d_packed_structs.c:1.4 src/tests/usr.bin/xlint/lint1/d_packed_structs.c:1.5
--- src/tests/usr.bin/xlint/lint1/d_packed_structs.c:1.4	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/d_packed_structs.c	Tue Aug  1 19:52:15 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_packed_structs.c,v 1.4 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: d_packed_structs.c,v 1.5 2023/08/01 19:52:15 rillig Exp $	*/
 # 3 "d_packed_structs.c"
 
 /* packed tests */
@@ -39,3 +39,8 @@ struct y {
 };
 
 int a[sizeof(struct y) - sizeof(struct x) - 1];
+
+/* expect+1: error: negative array dimension (-9) [20] */
+typedef int sizeof_x[-(int)sizeof(struct x)];
+/* expect+1: error: negative array dimension (-16) [20] */
+typedef int sizeof_y[-(int)sizeof(struct y)];

Index: src/tests/usr.bin/xlint/lint1/decl.c
diff -u src/tests/usr.bin/xlint/lint1/decl.c:1.25 src/tests/usr.bin/xlint/lint1/decl.c:1.26
--- src/tests/usr.bin/xlint/lint1/decl.c:1.25	Mon Jul 31 20:52:26 2023
+++ src/tests/usr.bin/xlint/lint1/decl.c	Tue Aug  1 19:52:15 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl.c,v 1.25 2023/07/31 20:52:26 rillig Exp $	*/
+/*	$NetBSD: decl.c,v 1.26 2023/08/01 19:52:15 rillig Exp $	*/
 # 3 "decl.c"
 
 /*
@@ -229,3 +229,15 @@ symbol_type_in_unnamed_bit_field_member(
 		int named_member;
 	};
 }
+
+// Symbols that are defined in the parameter list of a function definition can
+// be accessed in the body of the function, even if they are nested.
+int
+get_x(struct point3d { struct point3d_number { int v; } x, y, z; } arg)
+{
+/* expect-1: warning: dubious tag declaration 'struct point3d' [85] */
+/* expect-2: warning: dubious tag declaration 'struct point3d_number' [85] */
+	static struct point3d local;
+	static struct point3d_number z;
+	return arg.x.v + local.x.v + z.v;
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug  1 19:52:16 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_packed_structs.c decl.c

Log Message:
tests/lint: test packed and in-parameter declarations


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_packed_structs.c
cvs rdiff -u -r1.25 -r1.26 src/tests/usr.bin/xlint/lint1/decl.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul 31 20:52:26 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl.c

Log Message:
tests/lint: test symbol lookup in unnamed bit-field member declaration


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/usr.bin/xlint/lint1/decl.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/decl.c
diff -u src/tests/usr.bin/xlint/lint1/decl.c:1.24 src/tests/usr.bin/xlint/lint1/decl.c:1.25
--- src/tests/usr.bin/xlint/lint1/decl.c:1.24	Mon Jul 31 20:31:58 2023
+++ src/tests/usr.bin/xlint/lint1/decl.c	Mon Jul 31 20:52:26 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl.c,v 1.24 2023/07/31 20:31:58 rillig Exp $	*/
+/*	$NetBSD: decl.c,v 1.25 2023/07/31 20:52:26 rillig Exp $	*/
 # 3 "decl.c"
 
 /*
@@ -211,3 +211,21 @@ bit_and_data(struct bit_and_data *node)
 {
 	return node->data;
 }
+
+
+// See cgram.y, rule 'notype_member_declarator'.
+void
+symbol_type_in_unnamed_bit_field_member(void)
+{
+	enum {
+		bits = 4,
+	};
+
+	struct s {
+		// Since there is no name in the declarator, the next symbol
+		// after the ':' must not be interpreted as a member name, but
+		// instead as a variable, type or function (FVFT).
+		unsigned int :bits;
+		int named_member;
+	};
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul 31 20:52:26 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl.c

Log Message:
tests/lint: test symbol lookup in unnamed bit-field member declaration


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/usr.bin/xlint/lint1/decl.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 28 22:05:44 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: c11.c c23.c

Log Message:
tests/lint: test declarations in C11 and C23


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/c11.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/c23.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 28 22:05:44 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: c11.c c23.c

Log Message:
tests/lint: test declarations in C11 and C23


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/c11.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/c23.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/c11.c
diff -u src/tests/usr.bin/xlint/lint1/c11.c:1.3 src/tests/usr.bin/xlint/lint1/c11.c:1.4
--- src/tests/usr.bin/xlint/lint1/c11.c:1.3	Thu Jul 13 20:30:21 2023
+++ src/tests/usr.bin/xlint/lint1/c11.c	Fri Jul 28 22:05:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: c11.c,v 1.3 2023/07/13 20:30:21 rillig Exp $	*/
+/*	$NetBSD: c11.c,v 1.4 2023/07/28 22:05:44 rillig Exp $	*/
 # 3 "c11.c"
 
 /*
@@ -6,7 +6,7 @@
  * functions, anonymous struct/union members, and several more.
  */
 
-/* lint1-flags: -Ac11 -w -X 236 -X 351 */
+/* lint1-flags: -Ac11 -w -X 192,231,236,351 */
 
 _Noreturn void exit(int);
 void _Noreturn exit(int);
@@ -42,6 +42,109 @@ three_times(void)
 	exit(0);
 }
 
+
+_Static_assert(1 > 0, "string");
+/* XXX: requires C23 or later */
+_Static_assert(1 > 0);
+
+
+// C11 6.7.6.1p3
+const int *ptr_to_constant;
+int *const constant_ptr;
+
+// C11 6.7.6.1p4
+typedef int *int_ptr;
+const int_ptr constant_ptr;
+
+// C11 6.7.6.2p7
+float fa[11], *afp[17];
+
+// C11 6.7.6.2p8
+extern int *x;
+extern int y[];
+
+// C11 6.7.6.2p9
+extern int n;
+extern int m;
+void fcompat(void)
+{
+	int a[n][6][m];
+	int (*p)[4][n+1];
+	int c[n][n][6][m];
+	int (*r)[n][n][n+1];
+	/* expect+2: warning: 'p' set but not used in function 'fcompat' [191] */
+	/* expect+1: warning: illegal combination of 'pointer to array[4] of array[1] of int' and 'pointer to array[6] of array[1] of int', op '=' [124] */
+	p = a;
+	/* expect+2: warning: 'r' set but not used in function 'fcompat' [191] */
+	/* expect+1: warning: illegal combination of 'pointer to array[1] of array[1] of array[1] of int' and 'pointer to array[1] of array[6] of array[1] of int', op '=' [124] */
+	r = c;
+}
+
+// C11 6.7.6.2p10
+extern int n;
+int A[n];
+extern int (*p2)[n];
+int B[100];
+void fvla(int m, int C[m][m]);
+void fvla(int m, int C[m][m])
+{
+	typedef int VLA[m][m];
+	struct tag {
+		int (*y)[n];
+		int z[n];
+	};
+	int D[m];
+	static int E[m];
+	/* expect+1: warning: nested 'extern' declaration of 'F' [352] */
+	extern int F[m];
+	int (*s)[m];
+	/* expect+1: warning: nested 'extern' declaration of 'r' [352] */
+	extern int (*r)[m];
+	/* expect+2: warning: illegal combination of 'pointer to array[1] of int' and 'pointer to int', op 'init' [124] */
+	/* expect+1: warning: 'q' set but not used in function 'fvla' [191] */
+	static int (*q)[m] = 
+}
+
+// C11 6.7.6.3p15
+int f(void), *fip(), (*pfi)();
+
+// C11 6.7.6.3p17
+int (*apfi[3])(int *x, int *y);
+
+// C11 6.7.6.3p18
+int (*fpfi(int (*)(long), int))(int, ...);
+
+// C11 6.7.6.3p19
+void addscalar(int n, int m, double a[n][n*m+300], double x);
+int main(void)
+{
+	double b[4][308];
+	/* expect+1: warning: converting 'pointer to array[308] of double' to incompatible 'pointer to array[1] of double' for argument 3 [153] */
+	addscalar(4, 2, b, 2.17);
+	return 0;
+}
+void addscalar(int n, int m, double a[n][n*m+300], double x)
+{
+	for (int i = 0; i < n; i++)
+		for (int j = 0, k = n*m+300; j < k; j++)
+			a[i][j] += x;
+}
+
+// C11 6.7.6.3p20
+double maximum(int n, int m, double a[n][m]);
+/* expect+1: error: null dimension [17] */
+double maximum(int n, int m, double a[*][*]);
+/* expect+1: error: null dimension [17] */
+double maximum(int n, int m, double a[ ][*]);
+double maximum(int n, int m, double a[ ][m]);
+
+void f1(double (* restrict a)[5]);
+void f2(double a[restrict][5]);
+/* expect+1: error: syntax error '3' [249] */
+void f3(double a[restrict 3][5]);
+void f4(double a[restrict static 3][5]);
+
+
 // In C11 mode, 'thread_local' is not yet known, but '_Thread_local' is.
 /* expect+2: error: old-style declaration; add 'int' [1] */
 /* expect+1: error: syntax error 'int' [249] */

Index: src/tests/usr.bin/xlint/lint1/c23.c
diff -u src/tests/usr.bin/xlint/lint1/c23.c:1.6 src/tests/usr.bin/xlint/lint1/c23.c:1.7
--- src/tests/usr.bin/xlint/lint1/c23.c:1.6	Tue Jul 25 16:56:35 2023
+++ src/tests/usr.bin/xlint/lint1/c23.c	Fri Jul 28 22:05:44 2023
@@ -1,10 +1,11 @@
-/*	$NetBSD: c23.c,v 1.6 2023/07/25 16:56:35 rillig Exp $	*/
+/*	$NetBSD: c23.c,v 1.7 2023/07/28 22:05:44 rillig Exp $	*/
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
 // ISO standards, but none of the GNU extensions.
 //
 // See also:
+//	c11.c
 //	msg_353.c		for empty initializer braces
 
 /* lint1-flags: -Ac23 -w -X 351 */
@@ -22,6 +23,11 @@ empty_initializer_braces(void)
 	return s.member;
 }
 
+
+_Static_assert(1 > 0, "string");
+_Static_assert(1 > 0);
+
+
 // The 

CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 21 05:51:12 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_181.c

Log Message:
tests/lint: document an example of a non-constant initializer


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_181.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_181.c
diff -u src/tests/usr.bin/xlint/lint1/msg_181.c:1.5 src/tests/usr.bin/xlint/lint1/msg_181.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_181.c:1.5	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_181.c	Fri Jul 21 05:51:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_181.c,v 1.5 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_181.c,v 1.6 2023/07/21 05:51:12 rillig Exp $	*/
 # 3 "msg_181.c"
 
 // Test for message: {}-enclosed initializer required [181]
@@ -8,3 +8,16 @@
 /* expect+1: error: {}-enclosed initializer required [181] */
 struct { int x; } missing_braces = 3;
 struct { int x; } including_braces = { 3 };
+
+
+// C11 6.6p7 requires the initializer of an object with static storage duration
+// to be a constant expression or an address constant, and a compound literal
+// is neither.  C11 6.6p10 allows an implementation to accept "other forms of
+// constant expressions", and GCC accepts compound literals that contain only
+// constant expressions.
+struct number {
+	int value;
+} num = (struct number){
+.value = 3,
+};
+/* expect-1: error: {}-enclosed initializer required [181] */



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 21 05:51:12 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_181.c

Log Message:
tests/lint: document an example of a non-constant initializer


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_181.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 15 21:40:03 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_attribute_var.c

Log Message:
tests/lint: test GCC attributes in member declarations


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/gcc_attribute_var.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/gcc_attribute_var.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_var.c:1.9 src/tests/usr.bin/xlint/lint1/gcc_attribute_var.c:1.10
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_var.c:1.9	Fri Jul  7 06:03:31 2023
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_var.c	Sat Jul 15 21:40:03 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_attribute_var.c,v 1.9 2023/07/07 06:03:31 rillig Exp $	*/
+/*	$NetBSD: gcc_attribute_var.c,v 1.10 2023/07/15 21:40:03 rillig Exp $	*/
 # 3 "gcc_attribute_var.c"
 
 /*
@@ -72,3 +72,16 @@ attribute_after_array_brackets(
 )
 {
 }
+
+struct attribute_in_member_declaration {
+	int __attribute__(())
+	x __attribute__(()),
+	y __attribute__(());
+
+	unsigned int __attribute__(())
+/* FIXME */
+/* expect+1: error: syntax error ',' [249] */
+	bit1:1 __attribute__(()),
+	bit2:2 __attribute__(()),
+	bit3:3 __attribute__(());
+};



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 15 21:40:03 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_attribute_var.c

Log Message:
tests/lint: test GCC attributes in member declarations


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/gcc_attribute_var.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 15 16:11:32 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c

Log Message:
tests/lint: test 'extern thread_local' storage classes

Seen in external/mpl/bind/dist/lib/isc/pthreads/include/isc/thread.h:32.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/c23.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/c23.c
diff -u src/tests/usr.bin/xlint/lint1/c23.c:1.3 src/tests/usr.bin/xlint/lint1/c23.c:1.4
--- src/tests/usr.bin/xlint/lint1/c23.c:1.3	Fri Jul 14 08:53:52 2023
+++ src/tests/usr.bin/xlint/lint1/c23.c	Sat Jul 15 16:11:32 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: c23.c,v 1.3 2023/07/14 08:53:52 rillig Exp $	*/
+/*	$NetBSD: c23.c,v 1.4 2023/07/15 16:11:32 rillig Exp $	*/
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
@@ -39,3 +39,10 @@ function(void)
 	// this case.
 	thread_local int function_scoped_thread_local;
 }
+
+/* FIXME: 'thread_local' and 'extern' can be combined. */
+/* expect+1: error: only one storage class allowed [7] */
+extern thread_local int extern_thread_local_1;
+/* FIXME: 'thread_local' and 'extern' can be combined. */
+/* expect+1: error: only one storage class allowed [7] */
+thread_local extern int extern_thread_local_2;



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 15 16:11:32 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c

Log Message:
tests/lint: test 'extern thread_local' storage classes

Seen in external/mpl/bind/dist/lib/isc/pthreads/include/isc/thread.h:32.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/c23.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 15 09:53:46 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_lint_assert.c

Log Message:
tests/lint: document how to reliably crash lint1 after a parse error


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/d_lint_assert.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/d_lint_assert.c
diff -u src/tests/usr.bin/xlint/lint1/d_lint_assert.c:1.8 src/tests/usr.bin/xlint/lint1/d_lint_assert.c:1.9
--- src/tests/usr.bin/xlint/lint1/d_lint_assert.c:1.8	Sat Jul 15 09:40:37 2023
+++ src/tests/usr.bin/xlint/lint1/d_lint_assert.c	Sat Jul 15 09:53:46 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_lint_assert.c,v 1.8 2023/07/15 09:40:37 rillig Exp $	*/
+/*	$NetBSD: d_lint_assert.c,v 1.9 2023/07/15 09:53:46 rillig Exp $	*/
 # 3 "d_lint_assert.c"
 
 /*
@@ -25,21 +25,21 @@ enum {
 c(void());
 
 
-// As of 2023-07-15, the following code leads to a crash, due to the word
-// 'unknown_type_modifier'.  The parser then goes into error recovery mode and
-// discards the declaration in the 'for' loop.  In the end, the symbol table
-// still contains symbols that were already freed when parsing the '}' from the
-// 'switch' statement.  To reproduce the crash, run 'make -DDEBUG DBG="-O0 -g"'
-// and run with -Sy.
-//
-// static inline void
-// f(void)
-// {
-//	int i = 3;
-//
-//	for (unknown_type_modifier char *p = "";; ) {
-//		switch (i) {
-//		case 3:;
-//		}
-//	}
-// }
+// As of 2023-07-15, replacing 'const' with 'unknown_type_modifier' leads to a
+// crash.  When the '}' from the 'switch' statement is processed, symbols that
+// are already freed are still in the symbol table.  To reproduce the crash,
+// run:
+//	make -s -DDEBUG DBG="-O0 -g"
+//	MALLOC_OPTIONS='JA' MALLOC_CONF='junk:true' ./lint1 -Sy \
+//	../../../tests/usr.bin/xlint/lint1/d_lint_assert.c
+ static inline void
+ f(void)
+ {
+	int i = 3;
+
+	for (const char *p = "";; ) {
+		switch (i) {
+		case 3:;
+		}
+	}
+ }



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 15 09:53:46 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_lint_assert.c

Log Message:
tests/lint: document how to reliably crash lint1 after a parse error


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/d_lint_assert.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 13 22:44:10 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl.c

Log Message:
tests/lint: test duplicate type qualifiers in pointer types


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/xlint/lint1/decl.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/decl.c
diff -u src/tests/usr.bin/xlint/lint1/decl.c:1.22 src/tests/usr.bin/xlint/lint1/decl.c:1.23
--- src/tests/usr.bin/xlint/lint1/decl.c:1.22	Fri Jul  7 06:03:31 2023
+++ src/tests/usr.bin/xlint/lint1/decl.c	Thu Jul 13 22:44:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl.c,v 1.22 2023/07/07 06:03:31 rillig Exp $	*/
+/*	$NetBSD: decl.c,v 1.23 2023/07/13 22:44:10 rillig Exp $	*/
 # 3 "decl.c"
 
 /*
@@ -183,3 +183,10 @@ cover_func_declarator(void)
 /* expect+2: error: syntax error 'goto' [249] */
 /* expect+1: warning: empty array declaration for 'void_array_error' [190] */
 void void_array_error[] goto;
+
+const volatile int
+/* expect+1: warning: duplicate 'const' [10] */
+*const volatile const
+/* expect+1: warning: duplicate 'volatile' [10] */
+*volatile const volatile
+*duplicate_ptr;



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 13 22:44:10 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl.c

Log Message:
tests/lint: test duplicate type qualifiers in pointer types


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/xlint/lint1/decl.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 12:42:11 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_lp64.c

Log Message:
tests/lint: demonstrate missing warning for converting int128_t


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/platform_lp64.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 12:42:11 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: platform_lp64.c

Log Message:
tests/lint: demonstrate missing warning for converting int128_t


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/platform_lp64.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/platform_lp64.c
diff -u src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.5 src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.6
--- src/tests/usr.bin/xlint/lint1/platform_lp64.c:1.5	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/platform_lp64.c	Sat Jul  8 12:42:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: platform_lp64.c,v 1.5 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: platform_lp64.c,v 1.6 2023/07/08 12:42:11 rillig Exp $	*/
 # 3 "platform_lp64.c"
 
 /*
@@ -13,6 +13,8 @@ int s32;
 unsigned int u32;
 long sl32;
 unsigned long ul32;
+__int128_t s128;
+__uint128_t u128;
 
 void
 convert_between_int_and_long(void)
@@ -33,3 +35,11 @@ convert_unsigned_char_to_size_t(unsigned
 	/* no warning, unlike platform_int */
 	to_size_t(uc);
 }
+
+void
+convert_128(void)
+{
+	/* TODO: Warn about 128-bit types as well. */
+	s32 = s128;
+	u32 = u128;
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 11:03:01 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_218.c
msg_230_uchar.c msg_247_ilp32_ldbl64.c

Log Message:
tests/lint: fix a few ilp32 tests


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_218.c
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/msg_230_uchar.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.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/check-expect.lua
diff -u src/tests/usr.bin/xlint/lint1/check-expect.lua:1.6 src/tests/usr.bin/xlint/lint1/check-expect.lua:1.7
--- src/tests/usr.bin/xlint/lint1/check-expect.lua:1.6	Sat Jul  8 10:01:17 2023
+++ src/tests/usr.bin/xlint/lint1/check-expect.lua	Sat Jul  8 11:03:00 2023
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.6 2023/07/08 10:01:17 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.7 2023/07/08 11:03:00 rillig Exp $
 
 --[[
 
@@ -37,8 +37,8 @@ end
 local function load_lines(fname)
   local lines = {}
 
-  local f = io.open(fname, "r")
-  if f == nil then return nil end
+  local f, err, errno = io.open(fname, "r")
+  if f == nil then return nil, err, errno end
 
   for line in f:lines() do
 table.insert(lines, line)
@@ -194,7 +194,7 @@ end)
 local function insert_missing(missing)
   for fname, items in pairs(missing) do
 table.sort(items, function(a, b) return a.lineno > b.lineno end)
-local lines = load_lines(fname)
+local lines = assert(load_lines(fname))
 for _, item in ipairs(items) do
   local lineno, message = item.lineno, item.message
   local indent = (lines[lineno] or ""):match("^([ \t]*)")

Index: src/tests/usr.bin/xlint/lint1/msg_218.c
diff -u src/tests/usr.bin/xlint/lint1/msg_218.c:1.7 src/tests/usr.bin/xlint/lint1/msg_218.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_218.c:1.7	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_218.c	Sat Jul  8 11:03:00 2023
@@ -1,15 +1,17 @@
-/*	$NetBSD: msg_218.c,v 1.7 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_218.c,v 1.8 2023/07/08 11:03:00 rillig Exp $	*/
 # 3 "msg_218.c"
 
-// Test for message: ANSI C treats constant as unsigned, op '%s' [218]
+/* Test for message: ANSI C treats constant as unsigned, op '%s' [218] */
 
 /* lint1-only-if: ilp32 */
-/* lint1-extra-flags: -X 351 */
+/* lint1-flags: -w -X 351 */
 
-_Bool cond;
+int cond;
 signed int s32;
 unsigned int u32;
+/* expect+1: warning: C90 does not support 'long long' [265] */
 signed long long s64;
+/* expect+1: warning: C90 does not support 'long long' [265] */
 unsigned long long u64;
 
 void sink_int(int);
@@ -18,6 +20,7 @@ void sink_int(int);
 void
 test_signed_int(void)
 {
+	/* expect+2: warning: ANSI C treats constant as unsigned, op '-' [218] */
 	/* expect+1: warning: conversion of 'unsigned long' to 'int' is out of range, arg #1 [295] */
 	sink_int(-2147483648);
 }
@@ -37,12 +40,20 @@ test_signed_int(void)
 void
 compare_large_constant(void)
 {
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = s32 < 30L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = 30L < s32;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = u32 < 30L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = 30L < u32;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = s64 < 30L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = 30L < s64;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = u64 < 30L;
+	/* expect+1: warning: ANSI C treats constant as unsigned, op '<' [218] */
 	cond = 30L < u64;
 }

Index: src/tests/usr.bin/xlint/lint1/msg_230_uchar.c
diff -u src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.12 src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.13
--- src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.12	Sat Jun 24 17:50:31 2023
+++ src/tests/usr.bin/xlint/lint1/msg_230_uchar.c	Sat Jul  8 11:03:00 2023
@@ -1,9 +1,9 @@
-/*	$NetBSD: msg_230_uchar.c,v 1.12 2023/06/24 17:50:31 rillig Exp $	*/
+/*	$NetBSD: msg_230_uchar.c,v 1.13 2023/07/08 11:03:00 rillig Exp $	*/
 # 3 "msg_230_uchar.c"
 
 // Test for message: nonportable character comparison '%s' [230]
 
-/* lint1-flags: -S -g -p -w */
+/* lint1-flags: -S -g -p -w -X 351 */
 /* lint1-only-if: uchar */
 
 /*

Index: src/tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c:1.2 src/tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c:1.3
--- 

CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 11:03:01 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_218.c
msg_230_uchar.c msg_247_ilp32_ldbl64.c

Log Message:
tests/lint: fix a few ilp32 tests


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_218.c
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/msg_230_uchar.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_247_ilp32_ldbl64.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 10:01:17 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: accept.sh check-expect.lua

Log Message:
tests/lint: automate accepting changed test results


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/accept.sh
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/check-expect.lua

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/accept.sh
diff -u src/tests/usr.bin/xlint/lint1/accept.sh:1.13 src/tests/usr.bin/xlint/lint1/accept.sh:1.14
--- src/tests/usr.bin/xlint/lint1/accept.sh:1.13	Sat Jul  8 08:02:45 2023
+++ src/tests/usr.bin/xlint/lint1/accept.sh	Sat Jul  8 10:01:17 2023
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: accept.sh,v 1.13 2023/07/08 08:02:45 rillig Exp $
+# $NetBSD: accept.sh,v 1.14 2023/07/08 10:01:17 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -37,6 +37,16 @@ set -eu
 : "${archsubdir:=$(make -v ARCHSUBDIR)}"
 . './t_integration.sh'		# for configure_test_case
 
+update_flags=''
+while getopts 'u' opt; do
+	case $opt in
+	u)	update_flags='-u';;
+	*)	echo "usage: $0 [-u] pattern..." 1>&2
+		exit 1;;
+	esac
+done
+shift $((OPTIND - 1))
+
 done_tests=''
 for pattern in "$@"; do
 	# shellcheck disable=SC2231
@@ -115,4 +125,4 @@ for pattern in "$@"; do
 done
 
 # shellcheck disable=SC2086
-lua './check-expect.lua' $done_tests
+lua './check-expect.lua' $update_flags $done_tests

Index: src/tests/usr.bin/xlint/lint1/check-expect.lua
diff -u src/tests/usr.bin/xlint/lint1/check-expect.lua:1.5 src/tests/usr.bin/xlint/lint1/check-expect.lua:1.6
--- src/tests/usr.bin/xlint/lint1/check-expect.lua:1.5	Thu Jul  6 07:33:36 2023
+++ src/tests/usr.bin/xlint/lint1/check-expect.lua	Sat Jul  8 10:01:17 2023
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.5 2023/07/06 07:33:36 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.6 2023/07/08 10:01:17 rillig Exp $
 
 --[[
 
@@ -49,6 +49,15 @@ local function load_lines(fname)
 end
 
 
+local function save_lines(fname, lines)
+  local f = io.open(fname, "w")
+  for _, line in ipairs(lines) do
+f:write(line .. "\n")
+  end
+  f:close()
+end
+
+
 -- Load the 'expect:' comments from a C source file.
 --
 -- example return values:
@@ -136,9 +145,6 @@ local function load_exp(exp_fname)
 end
 
 
@param comment string
@param pattern string
@return boolean
 local function matches(comment, pattern)
   if comment == "" then return false end
 
@@ -182,13 +188,32 @@ test(function()
 end)
 
 
-local function check_test(c_fname)
+-- Inserts the '/* expect */' lines to the .c file, so that the .c file matches
+-- the .exp file.  Multiple 'expect' comments for a single line of code are not
+-- handled correctly, but it's still better than doing the same work manually.
+local function insert_missing(missing)
+  for fname, items in pairs(missing) do
+table.sort(items, function(a, b) return a.lineno > b.lineno end)
+local lines = load_lines(fname)
+for _, item in ipairs(items) do
+  local lineno, message = item.lineno, item.message
+  local indent = (lines[lineno] or ""):match("^([ \t]*)")
+  local line = ("%s/* expect+1: %s */"):format(indent, message)
+  table.insert(lines, lineno, line)
+end
+save_lines(fname, lines)
+  end
+end
+
+
+local function check_test(c_fname, update)
   local exp_fname = c_fname:gsub("%.c$", ".exp"):gsub(".+/", "")
 
   local c_comment_locations, c_comments_by_location = load_c(c_fname)
   if c_comment_locations == nil then return end
 
   local exp_messages = load_exp(exp_fname) or {}
+  local missing = {}
 
   for _, exp_message in ipairs(exp_messages) do
 local c_comments = c_comments_by_location[exp_message.location] or {}
@@ -207,6 +232,16 @@ local function check_test(c_fname)
 if not found then
   print_error("error: %s: missing /* expect+1: %s */",
 exp_message.location, expected_message)
+
+  if update then
+local fname = exp_message.location:match("^([^(]+)")
+local lineno = tonumber(exp_message.location:match("%((%d+)%)$"))
+if not missing[fname] then missing[fname] = {} end
+table.insert(missing[fname], {
+  lineno = lineno,
+  message = expected_message,
+})
+  end
 end
   end
 
@@ -219,12 +254,21 @@ local function check_test(c_fname)
   end
 end
   end
+
+  if missing then
+insert_missing(missing)
+  end
 end
 
 
 local function main(args)
+  local update = args[1] == "-u"
+  if update then
+table.remove(args, 1)
+  end
+
   for _, name in ipairs(args) do
-check_test(name)
+check_test(name, update)
   end
 end
 



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 10:01:17 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: accept.sh check-expect.lua

Log Message:
tests/lint: automate accepting changed test results


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/xlint/lint1/accept.sh
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/check-expect.lua

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 08:02:45 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: accept.sh

Log Message:
tests/lint: only overwrite .exp files if the output actually changes


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/accept.sh

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  8 08:02:45 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: accept.sh

Log Message:
tests/lint: only overwrite .exp files if the output actually changes


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/accept.sh

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/accept.sh
diff -u src/tests/usr.bin/xlint/lint1/accept.sh:1.12 src/tests/usr.bin/xlint/lint1/accept.sh:1.13
--- src/tests/usr.bin/xlint/lint1/accept.sh:1.12	Wed Jun 28 20:51:31 2023
+++ src/tests/usr.bin/xlint/lint1/accept.sh	Sat Jul  8 08:02:45 2023
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: accept.sh,v 1.12 2023/06/28 20:51:31 rillig Exp $
+# $NetBSD: accept.sh,v 1.13 2023/07/08 08:02:45 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -42,7 +42,8 @@ for pattern in "$@"; do
 	# shellcheck disable=SC2231
 	for cfile in *$pattern*.c; do
 		base=${cfile%.*}
-		expfile="$base.exp"
+		exp_tmp_file="$base.exp.tmp"
+		exp_file="$base.exp"
 		ln_tmp_file="$base.exp-ln.tmp"
 		ln_file="$base.exp-ln"
 
@@ -58,16 +59,22 @@ for pattern in "$@"; do
 
 		# shellcheck disable=SC2154
 		# shellcheck disable=SC2086
-		if "$lint1" $flags "$base.c" "$ln_tmp_file" > "$expfile"; then
-			if [ -s "$expfile" ]; then
+		if "$lint1" $flags "$base.c" "$ln_tmp_file" > "$exp_tmp_file"; then
+			if [ -s "$exp_tmp_file" ]; then
 echo "$base produces output but exits successfully"
-sed 's,^,| ,' "$expfile"
+sed 's,^,| ,' "$exp_tmp_file"
 			fi
 		elif [ $? -ge 128 ]; then
 			echo "$base crashed"
 			continue
 		fi
 
+		if [ -f "$exp_file" ] && cmp -s "$exp_tmp_file"  "$exp_file"; then
+			rm "$exp_tmp_file"
+		else
+			mv "$exp_tmp_file" "$exp_file"
+		fi
+
 		if [ ! -f "$ln_tmp_file" ]; then
 			: 'No cleanup necessary.'
 		elif [ "$ln_file" = '/dev/null' ]; then
@@ -87,7 +94,7 @@ for pattern in "$@"; do
 		case "$base" in (msg_*)
 			if grep 'This message is not used\.' "$cfile" >/dev/null; then
 : 'Skip further checks.'
-			elif [ ! -s "$expfile" ]; then
+			elif [ ! -s "$exp_file" ]; then
 echo "$base should produce warnings"
 			elif grep '^TODO: "Add example code' "$cfile" >/dev/null; then
 : 'ok, this test is not yet written'
@@ -97,7 +104,7 @@ for pattern in "$@"; do
 msgid=${msgid#msg_0}
 msgid=${msgid#msg_}
 msgid=${msgid%%_*}
-if ! grep "\\[$msgid\\]\$" "$expfile" >/dev/null; then
+if ! grep "\\[$msgid\\]\$" "$exp_file" >/dev/null; then
 	echo "$base should trigger the message '$msgid'"
 fi
 			fi



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul  7 00:25:23 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_351.c

Log Message:
tests/lint: test all combinations of {func,obj}_{decl,def}

For a non-static function definition that is not declared in a header,
lint doesn't currently warn.  The previous test didn't notice this.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_351.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_351.c
diff -u src/tests/usr.bin/xlint/lint1/msg_351.c:1.5 src/tests/usr.bin/xlint/lint1/msg_351.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_351.c:1.5	Wed Jun 28 17:53:21 2023
+++ src/tests/usr.bin/xlint/lint1/msg_351.c	Fri Jul  7 00:25:23 2023
@@ -1,54 +1,103 @@
-/*	$NetBSD: msg_351.c,v 1.5 2023/06/28 17:53:21 rillig Exp $	*/
+/*	$NetBSD: msg_351.c,v 1.6 2023/07/07 00:25:23 rillig Exp $	*/
 # 3 "msg_351.c"
 
 // Test for message 351: missing%s header declaration for '%s' [351]
 
 /*
- * Warn about variable definitions or function definitions that are visible
- * outside the current translation unit but do not have a previous
+ * Warn about declarations or definitions for functions or objects that are
+ * visible outside the current translation unit but do not have a previous
  * declaration in a header file.
  *
  * All symbols that are used across translation units should be declared in a
  * header file, to ensure consistent types.
  *
  * Since the storage class 'extern' is redundant for functions but not for
- * objects, omit it for functions.
+ * objects, the diagnostic omits it for functions.
  *
  * https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-declarations
  */
 
-/* expect+1: warning: missing header declaration for 'implicitly_extern_function' [351] */
-void implicitly_extern_function(void);
-/* expect+1: warning: missing header declaration for 'explicitly_extern_function' [351] */
-extern void explicitly_extern_function(void);
-
-/* expect+1: warning: missing 'extern' header declaration for 'definition' [351] */
-int definition;
-/* expect+1: warning: missing 'extern' header declaration for 'reference' [351] */
-extern int reference;
-/* expect+1: warning: static variable 'file_scoped_definition' unused [226] */
-static int file_scoped_definition;
+/* expect+1: warning: missing header declaration for 'func_decl' [351] */
+void func_decl(void);
+/* expect+1: warning: missing header declaration for 'extern_func_decl' [351] */
+extern void extern_func_decl(void);
+static int static_func_decl(void);
+
+// TODO: missing header declaration
+void
+func_def(void)
+{
+}
+
+// TODO: missing header declaration
+extern void
+extern_func_def(void)
+{
+}
+
+/* expect+2: warning: static function 'static_func_def' unused [236] */
+static void
+static_func_def(void)
+{
+}
+
+/* expect+1: warning: missing 'extern' header declaration for 'obj_decl' [351] */
+extern int obj_decl;
+/* expect+1: warning: missing 'extern' header declaration for 'obj_def' [351] */
+int obj_def;
+static int static_obj_def;
 
 
 # 18 "header.h" 1 3 4
-static int static_def;
-int external_def;
-extern int external_ref;
-
-static int static_func_def(void);
-int extern_func_decl(void);
-extern int extern_func_decl_verbose(void);
-
-# 43 "msg_351.c" 2
-/* expect+1: warning: static variable 'static_def' unused [226] */
-static int static_def;
-int external_def;
-extern int external_ref;
-
-/* expect+1: warning: static function 'static_func_def' declared but not defined [290] */
-static int static_func_def(void);
-int extern_func_decl(void);
-extern int extern_func_decl_verbose(void);
 
+void func_decl(void);
+extern void extern_func_decl(void);
+static int static_func_decl(void);
+
+void func_def(void);
+extern void extern_func_def(void);
+static void static_func_def(void);
+
+void func_def_ok(void);
+extern void extern_func_def_ok(void);
+static void static_func_def_ok(void);
+
+extern int obj_decl;
+int obj_def;
+static int static_obj_def;
+
+# 70 "msg_351.c" 2
+
+void func_decl(void);
+extern void extern_func_decl(void);
+/* expect+1: warning: static function 'static_func_decl' declared but not defined [290] */
+static int static_func_decl(void);
+
+void
+func_def_ok(void)
+{
+}
+
+extern void
+extern_func_def_ok(void)
+{
+}
+
+/* expect+2: warning: static function 'static_func_def_ok' unused [236] */
+static void
+static_func_def_ok(void)
+{
+}
+
+extern int obj_decl;
+int obj_def;
+/* expect+1: warning: static variable 'static_obj_def' unused [226] */
+static int static_obj_def;
+
+
+/*
+ * Do not warn about the temporary identifier generated for the object from the
+ * compound literal.
+ */
 /* expect+1: warning: missing 'extern' header declaration for 'dbl_ptr' [351] */
 double *dbl_ptr = &(double) { 0.0 };



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul  7 00:25:23 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: msg_351.c

Log Message:
tests/lint: test all combinations of {func,obj}_{decl,def}

For a non-static function definition that is not declared in a header,
lint doesn't currently warn.  The previous test didn't notice this.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_351.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul  6 07:33:36 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_247_lp64_ldbl128.c

Log Message:
tests/lint: ensure consistent preprocessor filenames in tests

The deviations often happen when copying or renaming tests.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.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/check-expect.lua
diff -u src/tests/usr.bin/xlint/lint1/check-expect.lua:1.4 src/tests/usr.bin/xlint/lint1/check-expect.lua:1.5
--- src/tests/usr.bin/xlint/lint1/check-expect.lua:1.4	Sat Jul  1 09:21:31 2023
+++ src/tests/usr.bin/xlint/lint1/check-expect.lua	Thu Jul  6 07:33:36 2023
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.4 2023/07/01 09:21:31 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.5 2023/07/06 07:33:36 rillig Exp $
 
 --[[
 
@@ -91,6 +91,10 @@ local function load_c(fname)
 print_error("error: %s:%d: preprocessor line number must be %d",
   fname, phys_lineno, phys_lineno + 1)
   end
+  if ppl_fname:match("%.c$") and ppl_fname ~= basename then
+print_error("error: %s:%d: preprocessor filename must be '%s'",
+  fname, phys_lineno, basename)
+  end
   pp_fname = ppl_fname
   pp_lineno = ppl_lineno
 end
@@ -104,7 +108,7 @@ end
 --
 -- example return value: {
 --   {
--- exp_lineno = "18",
+-- exp_lineno = 18,
 -- location = "file.c(18)",
 -- message = "not a constant expression [123]",
 --   }

Index: src/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c:1.2 src/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c:1.2	Wed Jul  5 11:42:14 2023
+++ src/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c	Thu Jul  6 07:33:36 2023
@@ -1,5 +1,5 @@
-/*	$NetBSD: msg_247_lp64_ldbl128.c,v 1.2 2023/07/05 11:42:14 rillig Exp $	*/
-# 3 "msg_247_lp64.c"
+/*	$NetBSD: msg_247_lp64_ldbl128.c,v 1.3 2023/07/06 07:33:36 rillig Exp $	*/
+# 3 "msg_247_lp64_ldbl128.c"
 
 // Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
 



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul  6 07:33:36 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: check-expect.lua msg_247_lp64_ldbl128.c

Log Message:
tests/lint: ensure consistent preprocessor filenames in tests

The deviations often happen when copying or renaming tests.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/check-expect.lua
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_247_lp64_ldbl128.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul  3 09:37:14 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool.c d_c99_bool_strict.c

Log Message:
tests/lint: clean up tests for C99 bool


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/d_c99_bool.c
cvs rdiff -u -r1.40 -r1.41 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.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/d_c99_bool.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.10 src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.11
--- src/tests/usr.bin/xlint/lint1/d_c99_bool.c:1.10	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool.c	Mon Jul  3 09:37:14 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool.c,v 1.10 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool.c,v 1.11 2023/07/03 09:37:14 rillig Exp $	*/
 # 3 "d_c99_bool.c"
 
 /*
@@ -11,114 +11,78 @@
 
 /* lint1-extra-flags: -X 351 */
 
-/* Below, each false statement produces "negative array dimension" [20]. */
+/* expect+1: error: negative array dimension (-2) [20] */
+int int_0[(_Bool)0 ? -1 : -2];
 
-int int_0_converts_to_false[(_Bool)0 ? -1 : 1];
 /* expect+1: error: negative array dimension (-1) [20] */
-int int_0_converts_to_true_[(_Bool)0 ? 1 : -1];
+int int_1[(_Bool)1 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int int_1_converts_to_false[(_Bool)1 ? -1 : 1];
-int int_1_converts_to_true_[(_Bool)1 ? 1 : -1];
+int int_2[(_Bool)2 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int int_2_converts_to_false[(_Bool)2 ? -1 : 1];
-int int_2_converts_to_true_[(_Bool)2 ? 1 : -1];
+int int_256[(_Bool)256 ? -1 : -2];
 
-/* expect+1: error: negative array dimension (-1) [20] */
-int int_256_converts_to_false[(_Bool)256 ? -1 : 1];
-int int_256_converts_to_true_[(_Bool)256 ? 1 : -1];
-
-int null_pointer_converts_to_false[(_Bool)(void *)0 ? -1 : 1];
-/* expect+1: error: negative array dimension (-1) [20] */
-int null_pointer_converts_to_true_[(_Bool)(void *)0 ? 1 : -1];
+/* expect+1: error: negative array dimension (-2) [20] */
+int null_pointer[(_Bool)(void *)0 ? -1 : -2];
 
 /*
- * XXX: lint does not treat the address of a global variable as a constant
- * expression.  This goes against C99 6.6p7 but is probably not too relevant
- * in practice.
+ * XXX: In initializers for global variables, taking the address of a variable
+ * is allowed and may be modified by a constant offset.  This is not a constant
+ * expression though.
  *
- * In such a case, to_int_constant(tn, false) in cgram.y:array_size_opt
- * returns 1 for the array size.  This is why neither of the following array
- * declarations generates an error message.
+ * In such a case, the grammar rule array_size_opt calls to_int_constant, which
+ * returns 1 for the array size without reporting an error.  This is why
+ * neither of the following array declarations generates an error message.
  */
 char ch;
 int nonnull_pointer_converts_to_false[(_Bool) ? -1 : 1];
 int nonnull_pointer_converts_to_true_[(_Bool) ? 1 : -1];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_minus_1_0_converts_to_false[(_Bool)-1.0 ? -1 : 1];
-int double_minus_1_0_converts_to_true_[(_Bool)-1.0 ? 1 : -1];
+int double_minus_1_0[(_Bool)-1.0 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_minus_0_5_converts_to_false[(_Bool)-0.5 ? -1 : 1];
-int double_minus_0_5_converts_to_true_[(_Bool)-0.5 ? 1 : -1];
+int double_minus_0_5[(_Bool)-0.5 ? -1 : -2];
 
-int double_minus_0_0_converts_to_false[(_Bool)-0.0 ? -1 : 1];
-/* expect+1: error: negative array dimension (-1) [20] */
-int double_minus_0_0_converts_to_true_[(_Bool)-0.0 ? 1 : -1];
+/* expect+1: error: negative array dimension (-2) [20] */
+int double_minus_0_0[(_Bool)-0.0 ? -1 : -2];
 
-int double_0_0_converts_to_false[(_Bool)0.0 ? -1 : 1];
-/* expect+1: error: negative array dimension (-1) [20] */
-int double_0_0_converts_to_true_[(_Bool)0.0 ? 1 : -1];
+/* expect+1: error: negative array dimension (-2) [20] */
+int double_0_0[(_Bool)0.0 ? -1 : -2];
 
 /* The C99 rationale explains in 6.3.1.2 why (_Bool)0.5 is true. */
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : 1];
-int double_0_5_converts_to_true_[(_Bool)0.5 ? 1 : -1];
+int double_0_5_converts_to_false[(_Bool)0.5 ? -1 : -2];
 
 /* expect+1: error: negative array dimension (-1) [20] */
-int double_1_0_converts_to_false[(_Bool)1.0 ? -1 : 1];
-int double_1_0_converts_to_true_[(_Bool)1.0 ? 1 : -1];
-
-_Bool
-bool_to_bool(_Bool b)
-{
-	return b;
-}
-
-_Bool
-char_to_bool(char c)
-{
-	return c;
-}
-
-_Bool
-int_to_bool(int i)
-{
-	return i;
-}
-
-_Bool
-double_to_bool(double d)
-{
-	return d;
-}
-
-enum color {
-	RED
-};
-
-_Bool
-enum_to_bool(enum color e)
-{
-	return e;
-}
-

CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul  3 09:37:14 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool.c d_c99_bool_strict.c

Log Message:
tests/lint: clean up tests for C99 bool


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/d_c99_bool.c
cvs rdiff -u -r1.40 -r1.41 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul  2 23:45:10 UTC 2023

Added Files:
src/tests/usr.bin/xlint/lint1: c23.c msg_353.c

Log Message:
tests/lint: add C23 tests


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/c23.c \
src/tests/usr.bin/xlint/lint1/msg_353.c

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

Added files:

Index: src/tests/usr.bin/xlint/lint1/c23.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/c23.c:1.1
--- /dev/null	Sun Jul  2 23:45:10 2023
+++ src/tests/usr.bin/xlint/lint1/c23.c	Sun Jul  2 23:45:10 2023
@@ -0,0 +1,22 @@
+/*	$NetBSD: c23.c,v 1.1 2023/07/02 23:45:10 rillig Exp $	*/
+# 3 "c23.c"
+
+// Tests for the option -Ac23, which allows features from C23 and all earlier
+// ISO standards, but none of the GNU extensions.
+//
+// See also:
+//	msg_353.c
+
+/* lint1-flags: -Ac23 -w -X 351 */
+
+int
+c23(void)
+{
+	struct s {
+		int member;
+	} s;
+
+	s = (struct s){};
+	s = (struct s){s.member};
+	return s.member;
+}
Index: src/tests/usr.bin/xlint/lint1/msg_353.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/msg_353.c:1.1
--- /dev/null	Sun Jul  2 23:45:10 2023
+++ src/tests/usr.bin/xlint/lint1/msg_353.c	Sun Jul  2 23:45:10 2023
@@ -0,0 +1,19 @@
+/*	$NetBSD: msg_353.c,v 1.1 2023/07/02 23:45:10 rillig Exp $	*/
+# 3 "msg_353.c"
+
+// Test for message 353: empty initializer braces require C23 or later [353]
+//
+// See also:
+//	c23.c
+
+void
+c23(void)
+{
+	struct s {
+		int member;
+	} s;
+
+	/* expect+1: error: empty initializer braces require C23 or later [353] */
+	s = (struct s){};
+	s = (struct s){0};
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul  2 23:45:10 UTC 2023

Added Files:
src/tests/usr.bin/xlint/lint1: c23.c msg_353.c

Log Message:
tests/lint: add C23 tests


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/c23.c \
src/tests/usr.bin/xlint/lint1/msg_353.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul  2 22:50:18 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_gcc_compound_statements1.c

Log Message:
tests/lint: demonstrate empty statement in GCC statement expression

Seen in external/mit/xorg/lib/dri.old.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 \
src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.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/d_gcc_compound_statements1.c
diff -u src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c:1.12 src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c:1.13
--- src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c:1.12	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c	Sun Jul  2 22:50:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_gcc_compound_statements1.c,v 1.12 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: d_gcc_compound_statements1.c,v 1.13 2023/07/02 22:50:18 rillig Exp $	*/
 # 3 "d_gcc_compound_statements1.c"
 
 /* GCC compound statement with expression */
@@ -65,3 +65,19 @@ crash(void)
 		;
 	});
 }
+
+/*
+ * Before 2023-07-03, lint did not accept empty statements in GCC statement
+ * expressions.  These empty statements can be generated by a disabled 'assert'
+ * macro.
+ */
+unsigned int
+empty_statement(void)
+{
+	return ({
+		unsigned int mega = 1 << 20;
+		/* expect+1: error: syntax error ';' [249] */
+		;
+		mega;
+	});
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul  2 22:50:18 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_gcc_compound_statements1.c

Log Message:
tests/lint: demonstrate empty statement in GCC statement expression

Seen in external/mit/xorg/lib/dri.old.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 \
src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  1 20:57:37 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl_direct_abstract.c

Log Message:
tests/lint: rework tests for type names


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/decl_direct_abstract.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/decl_direct_abstract.c
diff -u src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.8 src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.9
--- src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.8	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c	Sat Jul  1 20:57:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl_direct_abstract.c,v 1.8 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: decl_direct_abstract.c,v 1.9 2023/07/01 20:57:37 rillig Exp $	*/
 # 3 "decl_direct_abstract.c"
 
 /*
@@ -11,58 +11,67 @@
 
 /* lint1-extra-flags: -X 351 */
 
-/*
- * The following tests do not use int, to avoid confusion with the implicit
- * return type.
- */
-
-char func0001(short (*)(long));
-
-/* GCC says 'char (*)(short int (*)(long int))' */
-/* Clang says 'char (short (*)(long))' */
-/* cdecl says 'function (pointer to function (long) returning short) returning char' */
-/* expect+1: error: cannot initialize 'double' from 'pointer to function(pointer to function(long) returning short) returning char' [185] */
-double type_of_func0001 = func0001;
-
-char func0002(short *(long));
-
-/* GCC says 'char (*)(short int * (*)(long int))' */
-/* Clang says 'char (short *(*)(long))' */
-/* cdecl says 'syntax error' */
-/* FIXME: lint is wrong, it discards the 'short *' */
-/* expect+1: error: cannot initialize 'double' from 'pointer to function(long) returning char' [185] */
-double type_of_func0002 = func0002;
-
-void c99_6_7_6_example_a(int);
-void c99_6_7_6_example_b(int *);
-void c99_6_7_6_example_c(int *[3]);
-void c99_6_7_6_example_d(int (*)[3]);
-void c99_6_7_6_example_e(int (*)[*]);
-void c99_6_7_6_example_f(int *());
-void c99_6_7_6_example_g(int (*)(void));
-void c99_6_7_6_example_h(int (*const[])(unsigned int, ...));
-
 struct incompatible {
 	int member;
 } x;
 
-/* expect+1: ... 'pointer to function(int) returning void' ... */
-double type_of_c99_6_7_6_example_a = c99_6_7_6_example_a;
-/* expect+1: ... 'pointer to function(pointer to int) returning void' ... */
-double type_of_c99_6_7_6_example_b = c99_6_7_6_example_b;
-/* expect+1: ... 'pointer to function(pointer to pointer to int) returning void' ... */
-double type_of_c99_6_7_6_example_c = c99_6_7_6_example_c;
-/* expect+1: ... 'pointer to function(pointer to array[3] of int) returning void' ... */
-double type_of_c99_6_7_6_example_d = c99_6_7_6_example_d;
-/* expect+1: ... 'pointer to function(pointer to array[unknown_size] of int) returning void' ... */
-double type_of_c99_6_7_6_example_e = c99_6_7_6_example_e;
-/* Wrong type before decl.c 1.256 from 2022-04-01. */
-/* expect+1: ... 'pointer to function(pointer to function() returning pointer to int) returning void' ... */
-double type_of_c99_6_7_6_example_f = c99_6_7_6_example_f;
-/* expect+1: ... 'pointer to function(pointer to function(void) returning int) returning void' ... */
-double type_of_c99_6_7_6_example_g = c99_6_7_6_example_g;
-/* expect+1: ... 'pointer to function(pointer to const pointer to function(unsigned int, ...) returning int) returning void' ... */
-double type_of_c99_6_7_6_example_h = c99_6_7_6_example_h;
+void
+c99_6_7_6_examples(void)
+{
+	/* expect+1: ... 'int' ... */
+	x = (int)x;
+	/* expect+1: ... 'pointer to int' ... */
+	x = (int *)x;
+	/* expect+1: ... 'array[3] of pointer to int' ... */
+	x = (int *[3])x;
+	/* expect+1: ... 'pointer to array[3] of int' ... */
+	x = (int (*)[3])x;
+	/* expect+1: ... 'pointer to array[unknown_size] of int' ... */
+	x = (int (*)[*])x;
+	/* expect+1: ... 'function() returning pointer to int' ... */
+	x = (int *())x;
+	/* expect+1: ... 'pointer to function(void) returning int' ... */
+	x = (int (*)(void))x;
+	/* expect+1: ... 'array[unknown_size] of const pointer to function(unsigned int, ...) returning int' ... */
+	x = (int (*const[])(unsigned int, ...))x;
+}
+
+void
+function_returning_char(void)
+{
+	// GCC adds a pointer, then says 'char (*)(short int (*)(long int))'.
+	// Clang says 'char (short (*)(long))'.
+	/* cdecl says 'function (pointer to function (long) returning short) returning char' */
+	/* FIXME: It's a function type, not only 'short'. */
+	/* expect+1: ... 'short' ... */
+	x = (char(short (*)(long)))x;
+
+	/* expect+1: warning: nested 'extern' declaration of 'f1' [352] */
+	char f1(short (*)(long));
+
+	/* expect+1: ... 'pointer to function(pointer to function(long) returning short) returning char' ... */
+	x = f1;
+}
+
+void
+function_returning_pointer(void)
+{
+	// GCC says 'error: cast specifies 

CVS commit: src/tests/usr.bin/xlint/lint1

2023-07-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul  1 20:57:37 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl_direct_abstract.c

Log Message:
tests/lint: rework tests for type names


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-06-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 30 22:27:47 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: init_braces.c

Log Message:
tests/lint: test initializing an unnamed union


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/init_braces.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/init_braces.c
diff -u src/tests/usr.bin/xlint/lint1/init_braces.c:1.5 src/tests/usr.bin/xlint/lint1/init_braces.c:1.6
--- src/tests/usr.bin/xlint/lint1/init_braces.c:1.5	Fri Jun 30 21:06:18 2023
+++ src/tests/usr.bin/xlint/lint1/init_braces.c	Fri Jun 30 22:27:47 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_braces.c,v 1.5 2023/06/30 21:06:18 rillig Exp $	*/
+/*	$NetBSD: init_braces.c,v 1.6 2023/06/30 22:27:47 rillig Exp $	*/
 # 3 "init_braces.c"
 
 /*
@@ -96,3 +96,38 @@ init_anonymous_struct_and_union(void)
 
 	return var.times.t0.ns;
 }
+
+// Minimized example taken from jemalloc.c, init_lock.
+unsigned char
+init_unnamed_union(void)
+{
+	struct init_unnamed_union {
+		union {
+			struct {
+struct padded_union {
+	unsigned char pad1[3];
+	union {
+		unsigned char u1;
+		unsigned char u2;
+	};
+	unsigned char pad2[3];
+} padded_union;
+			};
+		};
+	};
+
+	struct init_unnamed_union var = {
+		{
+			{
+.padded_union = {
+	.pad1 = { 0, 0, 0 },
+/* FIXME: Allow access to unnamed struct/union members. */
+/* expect+1: error: type 'struct padded_union' does not have member 'u1' [101] */
+	.u1 = 0,
+	.pad2 = { 0, 0, 0 },
+},
+			}
+		},
+	};
+	return var.padded_union.u1;
+}



CVS commit: src/tests/usr.bin/xlint/lint1

2023-06-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 30 22:27:47 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: init_braces.c

Log Message:
tests/lint: test initializing an unnamed union


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/init_braces.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-06-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 30 16:39:17 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_alignof.c expr_sizeof.c

Log Message:
tests/lint: extend tests for sizeof and alignof


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/d_alignof.c \
src/tests/usr.bin/xlint/lint1/expr_sizeof.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/d_alignof.c
diff -u src/tests/usr.bin/xlint/lint1/d_alignof.c:1.10 src/tests/usr.bin/xlint/lint1/d_alignof.c:1.11
--- src/tests/usr.bin/xlint/lint1/d_alignof.c:1.10	Fri Jun 30 09:26:03 2023
+++ src/tests/usr.bin/xlint/lint1/d_alignof.c	Fri Jun 30 16:39:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_alignof.c,v 1.10 2023/06/30 09:26:03 rillig Exp $	*/
+/*	$NetBSD: d_alignof.c,v 1.11 2023/06/30 16:39:17 rillig Exp $	*/
 # 3 "d_alignof.c"
 
 /* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */
@@ -108,6 +108,9 @@ alignof_variants(void)
 	/* expect+1: error: cannot take size/alignment of incomplete type [143] */
 	typedef int incomplete_enum[-(int)__alignof(enum incomplete_enum)];
 
+	/* expect+1: error: cannot take size/alignment of incomplete type [143] */
+	typedef int incomplete_array[-(int)__alignof(int[])];
+
 	struct bit_fields {
 		_Bool bit_field:1;
 	};
@@ -117,7 +120,11 @@ alignof_variants(void)
 	 */
 	/* expect+2: error: cannot initialize typedef '_tmp' [25] */
 	/* expect+1: error: cannot take size/alignment of bit-field [145] */
-	typedef int bit_field[-(int)__alignof((struct bit_fields){0}.bit_field)];
+	typedef int bit_field_1[-(int)__alignof((struct bit_fields){0}.bit_field)];
+
+	struct bit_fields bit_fields;
+	/* expect+1: error: cannot take size/alignment of bit-field [145] */
+	typedef int bit_field_2[-(int)__alignof(bit_fields.bit_field)];
 
 	/* expect+1: error: cannot take size/alignment of void [146] */
 	typedef int plain_void[-(int)__alignof(void)];
Index: src/tests/usr.bin/xlint/lint1/expr_sizeof.c
diff -u src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.10 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.11
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.10	Fri Jun 30 15:19:09 2023
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c	Fri Jun 30 16:39:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_sizeof.c,v 1.10 2023/06/30 15:19:09 rillig Exp $	*/
+/*	$NetBSD: expr_sizeof.c,v 1.11 2023/06/30 16:39:17 rillig Exp $	*/
 # 3 "expr_sizeof.c"
 
 /*
@@ -11,6 +11,7 @@
 /*
  * A sizeof expression can either take a type name or an expression.
  */
+
 void sink(unsigned long);
 
 struct {
@@ -164,3 +165,39 @@ anonymous_struct_and_union(void)
 	/* expect+1: error: negative array dimension (-48) [20] */
 	typedef int sizeof_us_16_32[-(int)sizeof(us_16_32)];
 }
+
+
+void
+sizeof_errors(void)
+{
+	/* expect+1: error: cannot take size/alignment of void [146] */
+	typedef int sizeof_void[-(int)sizeof(void)];
+
+	/*
+	 * A 'void array' gets replaced with an 'int array' before
+	 * type_size_in_bits gets to see it, thus the 256 * 4 = 1024.
+	 */
+	/* expect+2: error: illegal use of 'void' [18] */
+	/* expect+1: error: negative array dimension (-1024) [20] */
+	typedef int sizeof_void_array[-(int)sizeof(void[256])];
+
+	/* expect+1: warning: enum 'incomplete_enum' never defined [235] */
+	enum incomplete_enum;
+	/* expect+2: warning: cannot take size/alignment of incomplete type [143] */
+	/* expect+1: error: negative array dimension (-4) [20] */
+	typedef int sizeof_incomplete_enum[-(int)sizeof(enum incomplete_enum)];
+}
+
+
+/*
+ * Due to the 'double' member, the alignment of this struct is 8, so the size
+ * has to be 24 (or at least divisible by 8), otherwise the 'double' member
+ * would not get the correct alignment in an array of this struct.
+ */
+struct s24 {
+	char c0;
+	double d8;
+	char c16;
+};
+/* expect+1: error: negative array dimension (-24) [20] */
+typedef int sizeof_s24[-(int)sizeof(struct s24)];



CVS commit: src/tests/usr.bin/xlint/lint1

2023-06-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 30 16:39:17 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_alignof.c expr_sizeof.c

Log Message:
tests/lint: extend tests for sizeof and alignof


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/d_alignof.c \
src/tests/usr.bin/xlint/lint1/expr_sizeof.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-06-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 30 09:21:53 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_alignof.c expr_sizeof.c init_braces.c
msg_102.c

Log Message:
tests/lint: add more tests for sizeof, offsetof, alignof


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/d_alignof.c \
src/tests/usr.bin/xlint/lint1/expr_sizeof.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/init_braces.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_102.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/d_alignof.c
diff -u src/tests/usr.bin/xlint/lint1/d_alignof.c:1.8 src/tests/usr.bin/xlint/lint1/d_alignof.c:1.9
--- src/tests/usr.bin/xlint/lint1/d_alignof.c:1.8	Wed Jun 22 19:23:18 2022
+++ src/tests/usr.bin/xlint/lint1/d_alignof.c	Fri Jun 30 09:21:52 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_alignof.c,v 1.8 2022/06/22 19:23:18 rillig Exp $	*/
+/*	$NetBSD: d_alignof.c,v 1.9 2023/06/30 09:21:52 rillig Exp $	*/
 # 3 "d_alignof.c"
 
 /* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */
@@ -67,3 +67,58 @@ alignof_pointer_to_member(void)
 
 	return __alignof__(ptr)->member + ptr->member;
 }
+
+void
+alignof_variants(void)
+{
+	/* expect+1: error: negative array dimension (-4) [20] */
+	typedef int array_int[-(int)__alignof(int[3])];
+
+	/* expect+1: error: negative array dimension (-8) [20] */
+	typedef int array_double[-(int)__alignof(double[3])];
+
+	/* expect+1: error: cannot take size/alignment of function type 'function(int) returning int' [144] */
+	typedef int func[-(int)__alignof(int(int))];
+
+	struct int_double {
+		int i;
+		double d;
+	};
+	/* expect+1: error: negative array dimension (-8) [20] */
+	typedef int struct_int_double[-(int)__alignof(struct int_double)];
+
+	struct chars {
+		char name[20];
+	};
+	/* expect+1: error: negative array dimension (-1) [20] */
+	typedef int struct_chars[-(int)__alignof(struct chars)];
+
+	/* expect+1: warning: struct 'incomplete_struct' never defined [233] */
+	struct incomplete_struct;
+	/* expect+1: error: cannot take size/alignment of incomplete type [143] */
+	typedef int incomplete_struct[-(int)__alignof(struct incomplete_struct)];
+
+	/* expect+1: warning: union 'incomplete_union' never defined [234] */
+	union incomplete_union;
+	/* expect+1: error: cannot take size/alignment of incomplete type [143] */
+	typedef int incomplete_union[-(int)__alignof(union incomplete_union)];
+
+	/* expect+1: warning: enum 'incomplete_enum' never defined [235] */
+	enum incomplete_enum;
+	/* expect+1: error: negative array dimension (-4) [20] */
+	typedef int incomplete_enum[-(int)__alignof(enum incomplete_enum)];
+
+	struct bit_fields {
+		_Bool bit_field:1;
+	};
+	/*
+	 * FIXME: This is not an attempt to initialize the typedef, it's the
+	 * initialization of a nested expression.
+	 */
+	/* expect+2: error: cannot initialize typedef '_tmp' [25] */
+	/* expect+1: error: cannot take size/alignment of bit-field [145] */
+	typedef int bit_field[-(int)__alignof((struct bit_fields){0}.bit_field)];
+
+	/* expect+1: error: cannot take size/alignment of void [146] */
+	typedef int plain_void[-(int)__alignof(void)];
+}
Index: src/tests/usr.bin/xlint/lint1/expr_sizeof.c
diff -u src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.8 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.9
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.8	Fri Jun 30 08:03:01 2023
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c	Fri Jun 30 09:21:52 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_sizeof.c,v 1.8 2023/06/30 08:03:01 rillig Exp $	*/
+/*	$NetBSD: expr_sizeof.c,v 1.9 2023/06/30 09:21:52 rillig Exp $	*/
 # 3 "expr_sizeof.c"
 
 /*
@@ -116,22 +116,23 @@ bit_fields(void)
 	/*
 	 * The bit-fields in a struct may be merged into the same storage
 	 * units, even if their types differ. GCC 10, Clang 15 and lint all
-	 * agree in packing the bit-fields and the char into 4 bytes, even
-	 * though their underlying types
+	 * agree in packing the first group of bit-fields and the char into
+	 * 4 bytes, even though their underlying types differ.  The second
+	 * group of bit-fields gets its own storage unit.
 	 */
 	struct mixed {
 		_Bool flag0:1;
 		signed int signed0:1;
 		unsigned int unsigned0:1;
-		char ch;
+		char ch[3];
 		_Bool flag1:1;
 		signed int signed1:1;
 		unsigned int unsigned1:1;
 	} mixed;
-	/* expect+1: error: negative array dimension (-4) [20] */
+	/* expect+1: error: negative array dimension (-8) [20] */
 	typedef int sizeof_mixed[-(int)sizeof(mixed)];
 	/* FIXME: Implement build_offsetof correctly. */
-	/* expect+3: error: negative array dimension (-4) [20] */
+	/* expect+3: error: negative array dimension (-8) [20] */
 	typedef int offsetof_mixed_ch[
 	-(int)__builtin_offsetof(struct mixed, ch)
 	];

Index: src/tests/usr.bin/xlint/lint1/init_braces.c
diff -u 

CVS commit: src/tests/usr.bin/xlint/lint1

2023-06-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jun 30 09:21:53 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: d_alignof.c expr_sizeof.c init_braces.c
msg_102.c

Log Message:
tests/lint: add more tests for sizeof, offsetof, alignof


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/d_alignof.c \
src/tests/usr.bin/xlint/lint1/expr_sizeof.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/init_braces.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_102.c

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



  1   2   3   4   5   >