CVS commit: src/lib/libc/gdtoa

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 21:17:24 UTC 2024

Modified Files:
src/lib/libc/gdtoa: Makefile.inc

Log Message:
libc/hdtoa: suppress lint warning about possible accuracy loss

on sparc64: hdtoa.c(340): warning: conversion from 'unsigned long'
to 'char' may lose accuracy [132]


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/gdtoa/Makefile.inc

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

Modified files:

Index: src/lib/libc/gdtoa/Makefile.inc
diff -u src/lib/libc/gdtoa/Makefile.inc:1.13 src/lib/libc/gdtoa/Makefile.inc:1.14
--- src/lib/libc/gdtoa/Makefile.inc:1.13	Sat Oct  7 12:15:53 2023
+++ src/lib/libc/gdtoa/Makefile.inc	Mon May 13 21:17:24 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.13 2023/10/07 12:15:53 rin Exp $
+#	$NetBSD: Makefile.inc,v 1.14 2024/05/13 21:17:24 rillig Exp $
 
 # gdtoa sources
 .PATH: ${.CURDIR}/gdtoa
@@ -44,3 +44,5 @@ SRCS+=	dmisc.c \
 .if ${MACHINE_ARCH} != "vax"
 SRCS+=	strtord.c
 .endif
+
+LINTFLAGS.hdtoa.c+=	-X 132	# conversion may lose accuracy



CVS commit: src/lib/libc/gdtoa

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 21:17:24 UTC 2024

Modified Files:
src/lib/libc/gdtoa: Makefile.inc

Log Message:
libc/hdtoa: suppress lint warning about possible accuracy loss

on sparc64: hdtoa.c(340): warning: conversion from 'unsigned long'
to 'char' may lose accuracy [132]


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/gdtoa/Makefile.inc

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



CVS commit: src/usr.sbin/flashctl

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 20:38:05 UTC 2024

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
usr.sbin/flashctl: skip lint's strict bool mode with Clang

The strict bool mode is already checked in GCC mode, so restore the
previous idiomatic code.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/Makefile
diff -u src/usr.sbin/flashctl/Makefile:1.3 src/usr.sbin/flashctl/Makefile:1.4
--- src/usr.sbin/flashctl/Makefile:1.3	Sun Jan  8 15:49:51 2023
+++ src/usr.sbin/flashctl/Makefile	Mon May 13 20:38:05 2024
@@ -1,11 +1,12 @@
-# $NetBSD: Makefile,v 1.3 2023/01/08 15:49:51 rillig Exp $
+# $NetBSD: Makefile,v 1.4 2024/05/13 20:38:05 rillig Exp $
 
 SRCS=		flashctl.c
 
 PROG=		flashctl
 MAN=		flashctl.8
-LINTFLAGS+=	-T		# strict bool mode
+LINTFLAGS+=	${MKLLVM:U-T:D}	# strict bool mode
 
 WARNS=		4
 
 .include 
+

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.10 src/usr.sbin/flashctl/flashctl.c:1.11
--- src/usr.sbin/flashctl/flashctl.c:1.10	Sun May 12 19:03:55 2024
+++ src/usr.sbin/flashctl/flashctl.c	Mon May 13 20:38:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.11 2024/05/13 20:38:05 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.11 2024/05/13 20:38:05 rillig Exp $");
 
 #include 
 #include 
@@ -233,11 +233,11 @@ to_intmax(intmax_t *num, const char *str
 
 	errno = 0;
 	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
-		if (isxdigit((unsigned char)str[2]) == 0)
+		if (!isxdigit((unsigned char)str[2]))
 			return EINVAL;
 		*num = strtoimax(str, , 16);
 	} else {
-		if (isdigit((unsigned char)str[0]) == 0)
+		if (!isdigit((unsigned char)str[0]))
 			return EINVAL;
 		*num = strtoimax(str, , 10);
 	}



CVS commit: src/usr.sbin/flashctl

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 20:38:05 UTC 2024

Modified Files:
src/usr.sbin/flashctl: Makefile flashctl.c

Log Message:
usr.sbin/flashctl: skip lint's strict bool mode with Clang

The strict bool mode is already checked in GCC mode, so restore the
previous idiomatic code.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/flashctl/Makefile
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/tests/lib/libm

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 20:28:15 UTC 2024

Modified Files:
src/tests/lib/libm: t_hypot.c

Log Message:
tests/t_hypot: actually add nan test


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libm/t_hypot.c

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



CVS commit: src/tests/lib/libm

2024-05-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 13 20:28:15 UTC 2024

Modified Files:
src/tests/lib/libm: t_hypot.c

Log Message:
tests/t_hypot: actually add nan test


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/lib/libm/t_hypot.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/lib/libm/t_hypot.c
diff -u src/tests/lib/libm/t_hypot.c:1.7 src/tests/lib/libm/t_hypot.c:1.8
--- src/tests/lib/libm/t_hypot.c:1.7	Sun May 12 20:58:44 2024
+++ src/tests/lib/libm/t_hypot.c	Mon May 13 20:28:15 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: t_hypot.c,v 1.7 2024/05/12 20:58:44 riastradh Exp $ */
+/* $NetBSD: t_hypot.c,v 1.8 2024/05/13 20:28:15 rillig Exp $ */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -689,6 +689,7 @@ ATF_TP_ADD_TCS(tp)
 {
 
 	ATF_TP_ADD_TC(tp, hypot_exact);
+	ATF_TP_ADD_TC(tp, hypot_nan);
 	ATF_TP_ADD_TC(tp, hypot_trivial);
 	ATF_TP_ADD_TC(tp, hypotf_exact);
 	ATF_TP_ADD_TC(tp, hypotf_trivial);



lint's strict bool mode (was: Re: CVS commit: src/usr.sbin/flashctl)

2024-05-13 Thread Roland Illig
Am 13.05.2024 um 16:06 schrieb Taylor R Campbell:
>> Module Name:src
>> Committed By:   rillig
>> Date:   Sun May 12 19:03:55 UTC 2024
>>
>> Modified Files:
>> src/usr.sbin/flashctl: flashctl.c
>>
>> Log Message:
>> flashctl: fix lint's strict bool mode with Clang preprocessor
>>
>> Treating the return value from the  character classification
>> functions as an 'int' is neither elegant nor idiomatic, but it works for
>> now.
>>
>> -   if (!isxdigit((unsigned char)str[2]))
>> +   if (isxdigit((unsigned char)str[2]) == 0)
>
> Why is this change necessary?  Weren't you teaching lint to handle
> this case without complaining?

Yes, I did. The thing is that I only ever tested lint's strict bool mode
with the GCC preprocessor, and that preprocessor marks every token from
a macro expansion as coming from a system header or coming from the
user's code. Therefore, lint could be more lenient when checking the
result of the isxdigit macro, as its main operator, the cast to '(int)',
is from a system header, so it's OK that it has the "wrong" type.

On the other hand, the strcmp function is not listed in "namespace.h"
and does not have a macro definition, and although the function
declaration comes from a system header, the GCC preprocessor does not
mark the function call expression as coming from a system header.

This is the difference by which lint treats 'isxdigit(ch)' as bool-like
but 'strcmp(s1, s2)' as strictly 'int'.

A few days or weeks ago, Christos started builds that have both
MKLLVM=yes and MKLINT=yes, thus using the Clang preprocessor as lint's
preprocessor. Apparently nobody else has done this in the last few
years. Clang's preprocessor's output does not mark the tokens from macro
expansions as coming from a system header or from the user's code. Due
to this, lint can no longer be lenient for system header macro
expansions as it doesn't get the system header information anymore.

> We shouldn't change anything like
>
>   if (!isxdigit(...))
>   if (ferror(...))
>
> to
>
>   if (isxdigit(...) == 0)
>   if (ferror(...) != 0)
>
> The original is clearer and idiomatic code, even if it's a little
> silly that the return value is declared as int and not bool
> (presumably for historical reasons, if the interfaces were defined
> before bool existed).

I agree. For usr.bin/error, I tried a different variant, namely to only
activate lint's strict bool mode when MKLLVM is undefined, thus when the
GCC preprocessor is used. I guess activating the strict bool mode only
in GCC mode is good enough to catch all type mismatches.

The combination of MKLLVM=yes MKLINT=yes is also the cause why lint now
allows do-while-0 even in strict bool mode, as the FD_ZERO macro uses
that idiom and I didn't dare to change the macro to do-while-false, as
that would either require , or to deviate from the idiom
by using 'do { ... } while (0 != 0)', as that would look suspicious.

I will switch usr.sbin/flashctl to the only-in-GCC-mode variant and
restore the previous idiomatic code.

Roland



CVS commit: src/usr.sbin/flashctl

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 19:03:55 UTC 2024

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix lint's strict bool mode with Clang preprocessor

Treating the return value from the  character classification
functions as an 'int' is neither elegant nor idiomatic, but it works for
now.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/flashctl/flashctl.c

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



CVS commit: src/usr.sbin/flashctl

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 19:03:55 UTC 2024

Modified Files:
src/usr.sbin/flashctl: flashctl.c

Log Message:
flashctl: fix lint's strict bool mode with Clang preprocessor

Treating the return value from the  character classification
functions as an 'int' is neither elegant nor idiomatic, but it works for
now.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/flashctl/flashctl.c

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

Modified files:

Index: src/usr.sbin/flashctl/flashctl.c
diff -u src/usr.sbin/flashctl/flashctl.c:1.9 src/usr.sbin/flashctl/flashctl.c:1.10
--- src/usr.sbin/flashctl/flashctl.c:1.9	Sun Jan  8 16:01:49 2023
+++ src/usr.sbin/flashctl/flashctl.c	Sun May 12 19:03:55 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $	*/
+/*	$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: flashctl.c,v 1.9 2023/01/08 16:01:49 rillig Exp $");
+__RCSID("$NetBSD: flashctl.c,v 1.10 2024/05/12 19:03:55 rillig Exp $");
 
 #include 
 #include 
@@ -233,11 +233,11 @@ to_intmax(intmax_t *num, const char *str
 
 	errno = 0;
 	if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) {
-		if (!isxdigit((unsigned char)str[2]))
+		if (isxdigit((unsigned char)str[2]) == 0)
 			return EINVAL;
 		*num = strtoimax(str, , 16);
 	} else {
-		if (!isdigit((unsigned char)str[0]))
+		if (isdigit((unsigned char)str[0]) == 0)
 			return EINVAL;
 		*num = strtoimax(str, , 10);
 	}



CVS commit: src/usr.bin/xlint/lint2

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 19:00:10 UTC 2024

Modified Files:
src/usr.bin/xlint/lint2: Makefile

Log Message:
lint: remove redundant LINTFLAGS for lint2

The -T flag is already provided by ../Makefile.inc, along with several
other flags.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint2/Makefile

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

Modified files:

Index: src/usr.bin/xlint/lint2/Makefile
diff -u src/usr.bin/xlint/lint2/Makefile:1.23 src/usr.bin/xlint/lint2/Makefile:1.24
--- src/usr.bin/xlint/lint2/Makefile:1.23	Fri Jan 13 19:50:00 2023
+++ src/usr.bin/xlint/lint2/Makefile	Sun May 12 19:00:10 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.23 2023/01/13 19:50:00 rillig Exp $
+#	$NetBSD: Makefile,v 1.24 2024/05/12 19:00:10 rillig Exp $
 
 NOMAN=		# defined
 
@@ -8,7 +8,6 @@ SRCS=		main2.c hash.c read.c mem.c chk.c
 BINDIR=		/usr/libexec
 CPPFLAGS+=	-I${.CURDIR}
 CPPFLAGS+=	-DIS_LINT2
-LINTFLAGS+=	-T		# strict bool mode
 
 COPTS.msg.c+=	${${ACTIVE_CC} == "clang":? -Wno-format-nonliteral :}
 



CVS commit: src/usr.bin/xlint/lint2

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 19:00:10 UTC 2024

Modified Files:
src/usr.bin/xlint/lint2: Makefile

Log Message:
lint: remove redundant LINTFLAGS for lint2

The -T flag is already provided by ../Makefile.inc, along with several
other flags.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint2/Makefile

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



CVS commit: src/usr.bin/xlint

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 18:49:36 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: cksnprintb.c decl.c emit1.c err.c lex.c
src/usr.bin/xlint/lint2: chk.c emit2.c read.c
src/usr.bin/xlint/xlint: xlint.c

Log Message:
lint: add wrapper for  functions, for strict bool mode

When using the Clang preprocessor (with MKLLVM=yes), the preprocessor
output does not indicate which tokens come from a system header and
which tokens come from the user code.  Lint's strict bool mode relies on
this information to treat the character classification functions from
 as if their return type were bool instead of int.

These wrapper functions are only used when their argument is indeed a
'char', but not when the argument might be 'EOF or representable as an
unsigned char', such as when reading a byte from the input.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.402 -r1.403 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.243 -r1.244 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint2/read.c
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/xlint/xlint/xlint.c

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

Modified files:

Index: src/usr.bin/xlint/common/lint.h
diff -u src/usr.bin/xlint/common/lint.h:1.49 src/usr.bin/xlint/common/lint.h:1.50
--- src/usr.bin/xlint/common/lint.h:1.49	Sat Mar  2 09:32:18 2024
+++ src/usr.bin/xlint/common/lint.h	Sun May 12 18:49:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lint.h,v 1.49 2024/03/02 09:32:18 rillig Exp $	*/
+/*	$NetBSD: lint.h,v 1.50 2024/05/12 18:49:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -160,4 +160,46 @@ typedef struct lint2_type type_t;
 #endif
 #endif
 
+static inline bool
+ch_isalnum(char ch)
+{
+	return isalnum((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isalpha(char ch)
+{
+	return isalpha((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isdigit(char ch)
+{
+	return isdigit((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_islower(char ch)
+{
+	return islower((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isprint(char ch)
+{
+	return isprint((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isspace(char ch)
+{
+	return isspace((unsigned char)ch) != 0;
+}
+
+static inline bool
+ch_isupper(char ch)
+{
+	return isupper((unsigned char)ch) != 0;
+}
+
 #include "externs.h"

Index: src/usr.bin/xlint/lint1/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.14 src/usr.bin/xlint/lint1/cksnprintb.c:1.15
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.14	Fri Apr 12 05:44:38 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.15 2024/05/12 18:49:36 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.15 2024/05/12 18:49:36 rillig Exp $");
 #endif
 
 #include 
@@ -86,9 +86,9 @@ check_hex_escape(const buffer *buf, quot
 		bool upper = false;
 		bool lower = false;
 		for (size_t i = it.start + 2; i < it.end; i++) {
-			if (isupper((unsigned char)buf->data[i]))
+			if (ch_isupper(buf->data[i]))
 upper = true;
-			if (islower((unsigned char)buf->data[i]))
+			if (ch_islower(buf->data[i]))
 lower = true;
 		}
 		if (upper && lower)

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.402 src/usr.bin/xlint/lint1/decl.c:1.403
--- src/usr.bin/xlint/lint1/decl.c:1.402	Sat May  4 06:52:16 2024
+++ src/usr.bin/xlint/lint1/decl.c	Sun May 12 18:49:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.402 2024/05/04 06:52:16 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.403 2024/05/12 18:49:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.402 2024/05/04 06:52:16 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.403 2024/05/12 18:49:36 rillig Exp $");
 #endif
 
 #include 
@@ -1808,7 +1808,7 @@ check_extern_declaration(const sym_t *sy
 	dcs->d_redeclared_symbol == NULL &&
 	ends_with(curr_pos.p_file, ".c") &&
 	allow_c90 &&
-	!isdigit((unsigned char)sym->s_name[0]) &&	/* see mktempsym */
+	!ch_isdigit(sym->s_name[0]) &&	/* see mktempsym */
 	strcmp(sym->s_name, "main") != 0) {
 		/* missing%s header declaration for 

CVS commit: src/usr.bin/xlint

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 18:49:36 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: cksnprintb.c decl.c emit1.c err.c lex.c
src/usr.bin/xlint/lint2: chk.c emit2.c read.c
src/usr.bin/xlint/xlint: xlint.c

Log Message:
lint: add wrapper for  functions, for strict bool mode

When using the Clang preprocessor (with MKLLVM=yes), the preprocessor
output does not indicate which tokens come from a system header and
which tokens come from the user code.  Lint's strict bool mode relies on
this information to treat the character classification functions from
 as if their return type were bool instead of int.

These wrapper functions are only used when their argument is indeed a
'char', but not when the argument might be 'EOF or representable as an
unsigned char', such as when reading a byte from the input.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.402 -r1.403 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.243 -r1.244 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint2/read.c
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/xlint/xlint/xlint.c

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



CVS commit: src/usr.bin/xlint

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 18:00:59 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: externs1.h main1.c
src/usr.bin/xlint/xlint: xlint.c

Log Message:
lint: remove unused flag '-u' from lint1

This flag is completely handled by lint2.


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/main1.c
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/xlint/xlint/xlint.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.228 src/usr.bin/xlint/lint1/externs1.h:1.229
--- src/usr.bin/xlint/lint1/externs1.h:1.228	Sun May 12 12:28:34 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Sun May 12 18:00:58 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.228 2024/05/12 12:28:34 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.229 2024/05/12 18:00:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -46,7 +46,6 @@ extern bool eflag;
 extern bool hflag;
 extern bool pflag;
 extern bool rflag;
-extern bool uflag;
 extern bool vflag;
 extern bool wflag;
 extern bool yflag;

Index: src/usr.bin/xlint/lint1/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.82 src/usr.bin/xlint/lint1/main1.c:1.83
--- src/usr.bin/xlint/lint1/main1.c:1.82	Sat Feb  3 19:37:02 2024
+++ src/usr.bin/xlint/lint1/main1.c	Sun May 12 18:00:58 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main1.c,v 1.82 2024/02/03 19:37:02 rillig Exp $	*/
+/*	$NetBSD: main1.c,v 1.83 2024/05/12 18:00:58 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: main1.c,v 1.82 2024/02/03 19:37:02 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.83 2024/05/12 18:00:58 rillig Exp $");
 #endif
 
 #include 
@@ -60,7 +60,6 @@ bool Pflag;
 bool pflag;
 bool rflag;
 bool Tflag;
-bool uflag;
 bool vflag;
 bool wflag;
 bool yflag;
@@ -138,7 +137,7 @@ main(int argc, char *argv[])
 	setlocale(LC_ALL, "");
 	setprogname(argv[0]);
 
-	while ((c = getopt(argc, argv, "abceghpq:rstuvwyzA:FPR:STX:")) != -1) {
+	while ((c = getopt(argc, argv, "abceghpq:rstvwyzA:FPR:STX:")) != -1) {
 		switch (c) {
 		case 'a':	aflag++;	break;
 		case 'b':	bflag = true;	break;
@@ -173,7 +172,6 @@ main(int argc, char *argv[])
 			allow_c11 = false;
 			allow_c23 = false;
 			break;
-		case 'u':	uflag = true;	break;
 		case 'w':	wflag = true;	break;
 		case 'v':	vflag = true;	break;
 		case 'y':	yflag = true;	break;
@@ -262,7 +260,7 @@ static void __dead
 usage(void)
 {
 	(void)fprintf(stderr,
-	"usage: %s [-abceghmprstuvwyzFPST] [-Alevel] [-ddirectory] "
+	"usage: %s [-abceghmprstvwyzFPST] [-Alevel] [-d directory] "
 	"[-R old=new]\n"
 	"   %*s [-X id,...] [-q id,...] src dest\n",
 	getprogname(), (int)strlen(getprogname()), "");

Index: src/usr.bin/xlint/xlint/xlint.c
diff -u src/usr.bin/xlint/xlint/xlint.c:1.123 src/usr.bin/xlint/xlint/xlint.c:1.124
--- src/usr.bin/xlint/xlint/xlint.c:1.123	Sat Mar  2 09:32:19 2024
+++ src/usr.bin/xlint/xlint/xlint.c	Sun May 12 18:00:59 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: xlint.c,v 1.123 2024/03/02 09:32:19 rillig Exp $ */
+/* $NetBSD: xlint.c,v 1.124 2024/05/12 18:00:59 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: xlint.c,v 1.123 2024/03/02 09:32:19 rillig Exp $");
+__RCSID("$NetBSD: xlint.c,v 1.124 2024/05/12 18:00:59 rillig Exp $");
 #endif
 
 #include 
@@ -617,7 +617,6 @@ main(int argc, char *argv[])
 		case 'F':
 			Fflag = true;
 			/* FALLTHROUGH */
-		case 'u':
 		case 'h':
 			list_add_flag(, c);
 			list_add_flag(, c);
@@ -684,6 +683,7 @@ main(int argc, char *argv[])
 			break;
 #endif
 
+		case 'u':
 		case 'x':
 		case 'H':
 			list_add_flag(, c);



CVS commit: src/usr.bin/xlint

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 18:00:59 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: externs1.h main1.c
src/usr.bin/xlint/xlint: xlint.c

Log Message:
lint: remove unused flag '-u' from lint1

This flag is completely handled by lint2.


To generate a diff of this commit:
cvs rdiff -u -r1.228 -r1.229 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/main1.c
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/xlint/xlint/xlint.c

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



CVS commit: src

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 17:55:37 UTC 2024

Modified Files:
src/bin: Makefile.inc
src/sbin: Makefile.inc
src/usr.bin: Makefile.inc
src/usr.sbin: Makefile.inc

Log Message:
lint: suppress "used but not defined" for bin, sbin, usr.bin, usr.sbin

These diagnostics are emitted by lint2, and like all diagnostics from
lint2, they don't affect the exit status.

In libc, lint cannot handle the renamings from namespace.h, generating
many false positive diagnostics since 'libc_function' is used but
'_libc_function' is defined. Until this situation is handled properly,
suppress this diagnostic.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/bin/Makefile.inc
cvs rdiff -u -r1.24 -r1.25 src/sbin/Makefile.inc
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/Makefile.inc
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/Makefile.inc

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

Modified files:

Index: src/bin/Makefile.inc
diff -u src/bin/Makefile.inc:1.19 src/bin/Makefile.inc:1.20
--- src/bin/Makefile.inc:1.19	Sat Apr 20 13:24:48 2024
+++ src/bin/Makefile.inc	Sun May 12 17:55:36 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.19 2024/04/20 13:24:48 rillig Exp $
+#	$NetBSD: Makefile.inc,v 1.20 2024/05/12 17:55:36 rillig Exp $
 #	@(#)Makefile.inc	8.1 (Berkeley) 5/31/93
 
 .include 		# for MKDYNAMICROOT definition
@@ -6,6 +6,8 @@
 WARNS?=		5
 BINDIR?=	/bin
 
+LINTFLAGS+=	-u	# don't warn about "used but not defined"
+
 .if (${MKDYNAMICROOT} == "no")
 LDSTATIC?=	-static
 .endif

Index: src/sbin/Makefile.inc
diff -u src/sbin/Makefile.inc:1.24 src/sbin/Makefile.inc:1.25
--- src/sbin/Makefile.inc:1.24	Sat Apr 20 13:24:48 2024
+++ src/sbin/Makefile.inc	Sun May 12 17:55:36 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.24 2024/04/20 13:24:48 rillig Exp $
+#	$NetBSD: Makefile.inc,v 1.25 2024/05/12 17:55:36 rillig Exp $
 #	@(#)Makefile.inc	8.1 (Berkeley) 6/8/93
 
 .include 		# for MKDYNAMICROOT definition
@@ -6,6 +6,8 @@
 WARNS?=		5
 BINDIR?=	/sbin
 
+LINTFLAGS+=	-u	# don't warn about "used but not defined"
+
 .if (${MKDYNAMICROOT} == "no")
 LDSTATIC?=	-static
 .endif

Index: src/usr.bin/Makefile.inc
diff -u src/usr.bin/Makefile.inc:1.12 src/usr.bin/Makefile.inc:1.13
--- src/usr.bin/Makefile.inc:1.12	Sat Apr 20 13:24:49 2024
+++ src/usr.bin/Makefile.inc	Sun May 12 17:55:37 2024
@@ -1,9 +1,11 @@
-#	$NetBSD: Makefile.inc,v 1.12 2024/04/20 13:24:49 rillig Exp $
+#	$NetBSD: Makefile.inc,v 1.13 2024/05/12 17:55:37 rillig Exp $
 #	from: @(#)Makefile.inc	8.1 (Berkeley) 6/6/93
 
 WARNS?=	5
 BINDIR?=/usr/bin
 
+LINTFLAGS+=	-u	# don't warn about "used but not defined"
+
 .include 
 .if ${MKLINT} != "no" && !defined(NOLINT)
 realall: lint

Index: src/usr.sbin/Makefile.inc
diff -u src/usr.sbin/Makefile.inc:1.9 src/usr.sbin/Makefile.inc:1.10
--- src/usr.sbin/Makefile.inc:1.9	Sat Apr 20 13:24:49 2024
+++ src/usr.sbin/Makefile.inc	Sun May 12 17:55:37 2024
@@ -1,10 +1,12 @@
-#	$NetBSD: Makefile.inc,v 1.9 2024/04/20 13:24:49 rillig Exp $
+#	$NetBSD: Makefile.inc,v 1.10 2024/05/12 17:55:37 rillig Exp $
 #	from: @(#)Makefile.inc	8.1 (Berkeley) 6/6/93
 
 BINDIR?=	/usr/sbin
 WARNS?=		4
 CPPFLAGS+=	-D_KERNTYPES
 
+LINTFLAGS+=	-u	# don't warn about "used but not defined"
+
 .include 
 .if ${MKLINT} != "no" && !defined(NOLINT)
 realall: lint



CVS commit: src

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 17:55:37 UTC 2024

Modified Files:
src/bin: Makefile.inc
src/sbin: Makefile.inc
src/usr.bin: Makefile.inc
src/usr.sbin: Makefile.inc

Log Message:
lint: suppress "used but not defined" for bin, sbin, usr.bin, usr.sbin

These diagnostics are emitted by lint2, and like all diagnostics from
lint2, they don't affect the exit status.

In libc, lint cannot handle the renamings from namespace.h, generating
many false positive diagnostics since 'libc_function' is used but
'_libc_function' is defined. Until this situation is handled properly,
suppress this diagnostic.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/bin/Makefile.inc
cvs rdiff -u -r1.24 -r1.25 src/sbin/Makefile.inc
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/Makefile.inc
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/Makefile.inc

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



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

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 12:32:39 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckbool.c

Log Message:
lint: condense code for strict bool mode


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/lint1/ckbool.c

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



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

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 12:32:39 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckbool.c

Log Message:
lint: condense code for strict bool mode


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/lint1/ckbool.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.31 src/usr.bin/xlint/lint1/ckbool.c:1.32
--- src/usr.bin/xlint/lint1/ckbool.c:1.31	Sun May 12 12:28:34 2024
+++ src/usr.bin/xlint/lint1/ckbool.c	Sun May 12 12:32:39 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.31 2024/05/12 12:28:34 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.32 2024/05/12 12:32:39 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.31 2024/05/12 12:28:34 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.32 2024/05/12 12:32:39 rillig Exp $");
 #endif
 
 #include 
@@ -50,26 +50,6 @@ __RCSID("$NetBSD: ckbool.c,v 1.31 2024/0
  */
 
 
-/*
- * See if in strict bool mode, the operator takes either two bool operands
- * or two arbitrary other operands.
- */
-static bool
-is_assignment_bool_or_other(op_t op)
-{
-	return op == ASSIGN ||
-	op == ANDASS || op == XORASS || op == ORASS ||
-	op == RETURN || op == INIT || op == FARG;
-}
-
-static bool
-is_symmetric_bool_or_other(op_t op)
-{
-	return op == EQ || op == NE ||
-	op == BITAND || op == BITXOR || op == BITOR ||
-	op == COLON;
-}
-
 static bool
 is_int_constant_zero(const tnode_t *tn, tspec_t t)
 {
@@ -91,10 +71,16 @@ is_typeok_strict_bool_binary(op_t op,
 	(is_int_constant_zero(ln, lt) || is_int_constant_zero(rn, rt)))
 		return true;
 
-	if (is_assignment_bool_or_other(op))
+	if (op == ASSIGN || op == ANDASS || op == XORASS || op == ORASS ||
+	op == RETURN || op == INIT || op == FARG)
 		return lt != BOOL && (ln->tn_sys || rn->tn_sys);
 
-	return !is_symmetric_bool_or_other(op);
+	if (op == EQ || op == NE ||
+	op == BITAND || op == BITXOR || op == BITOR ||
+	op == COLON)
+		return false;
+
+	return true;
 }
 
 /*



CVS commit: src

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 12:28:35 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c
d_c99_bool_strict_syshdr.c
src/usr.bin/xlint/lint1: ckbool.c externs1.h func.c

Log Message:
lint: in strict bool mode, allow do-while-0

Even though 0 is not a boolean constant, allow this common idiom, to
help in those cases where the C preprocessor used by lint does not mark
tokens as coming from system headers (Clang).


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.23 -r1.24 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.186 -r1.187 src/usr.bin/xlint/lint1/func.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.49 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.50
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.49	Sun May 12 11:46:14 2024
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Sun May 12 12:28:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict.c,v 1.49 2024/05/12 11:46:14 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict.c,v 1.50 2024/05/12 12:28:35 rillig Exp $	*/
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -476,7 +476,6 @@ strict_bool_controlling_expression(bool 
 	// or nowhere.
 	/* expect+1: warning: loop not entered at top [207] */
 	do {
-	/* expect+1: error: controlling expression must be bool, not 'int' [333] */
 	} while (0);
 }
 

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.23 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.24
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.23	Sun May 12 11:46:14 2024
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c	Sun May 12 12:28:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.23 2024/05/12 11:46:14 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.24 2024/05/12 12:28:35 rillig Exp $	*/
 # 3 "d_c99_bool_strict_syshdr.c"
 
 /*
@@ -17,33 +17,33 @@ extern const unsigned short *ctype_table
 
 extern void println(const char *);
 
+
+
+
 /*
- * On NetBSD 8,  defines FD_ISSET by enclosing the statements
- * in the well-known 'do { ... } while (CONSTCOND 0)' loop.  The 0 in the
- * controlling expression has type INT but should be allowed nevertheless
- * since that header does not have a way to distinguish between bool and int.
- * It just follows the C99 standard, unlike the lint-provided stdbool.h,
- * which redefines 'false' to '__lint_false'.
+ * No matter whether the code is from a system header or not, the idiom
+ * 'do { ... } while (0)' is well known, and using the integer constant 0
+ * instead of the boolean constant 'false' neither creates any type confusion
+ * nor does its value take place in any conversions, as its scope is limited
+ * to the controlling expression of the loop.
  */
 void
-strict_bool_system_header_statement_macro(void)
+statement_macro(void)
 {
 
 	do {
 		println("nothing");
 	} while (/*CONSTCOND*/0);
-	/* expect-1: error: controlling expression must be bool, not 'int' [333] */
 
-# 38 "d_c99_bool_strict_syshdr.c" 3 4
+# 39 "d_c99_bool_strict_syshdr.c" 3 4
 	do {
 		println("nothing");
-	} while (/*CONSTCOND*/0);	/* ok */
+	} while (/*CONSTCOND*/0);
 
-# 43 "d_c99_bool_strict_syshdr.c"
+# 44 "d_c99_bool_strict_syshdr.c"
 	do {
 		println("nothing");
 	} while (/*CONSTCOND*/0);
-	/* expect-1: error: controlling expression must be bool, not 'int' [333] */
 }
 
 

Index: src/usr.bin/xlint/lint1/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.30 src/usr.bin/xlint/lint1/ckbool.c:1.31
--- src/usr.bin/xlint/lint1/ckbool.c:1.30	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/ckbool.c	Sun May 12 12:28:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.31 2024/05/12 12:28:34 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.31 2024/05/12 12:28:34 rillig Exp $");
 #endif
 
 #include 
@@ -149,7 +149,7 @@ typeok_scalar_strict_bool(op_t op, const
 
 	if (mp->m_compares_with_zero) {
 		bool binary = mp->m_binary;
-		bool lbool = is_typeok_bool_compares_with_zero(ln);
+		bool lbool = is_typeok_bool_compares_with_zero(ln, false);
 		bool ok = true;
 
 		if (!binary && !lbool) {
@@ -163,7 +163,7 @@ typeok_scalar_strict_bool(op_t op, const
 			ok = false;
 		}
 		if (binary && op != QUEST &&
-		

CVS commit: src

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 12:28:35 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c
d_c99_bool_strict_syshdr.c
src/usr.bin/xlint/lint1: ckbool.c externs1.h func.c

Log Message:
lint: in strict bool mode, allow do-while-0

Even though 0 is not a boolean constant, allow this common idiom, to
help in those cases where the C preprocessor used by lint does not mark
tokens as coming from system headers (Clang).


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.23 -r1.24 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.227 -r1.228 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.186 -r1.187 src/usr.bin/xlint/lint1/func.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-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 11:46:14 UTC 2024

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

Log Message:
tests/lint: clean up tests for strict bool mode


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.22 -r1.23 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.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-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 11:46:14 UTC 2024

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

Log Message:
tests/lint: clean up tests for strict bool mode


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.22 -r1.23 \
src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.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.48 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.49
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.48	Sat Dec 30 17:09:42 2023
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Sun May 12 11:46:14 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict.c,v 1.48 2023/12/30 17:09:42 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict.c,v 1.49 2024/05/12 11:46:14 rillig Exp $	*/
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -27,7 +27,7 @@
  *
  * strict-bool-controlling-expression:
  *	Controlling expressions in 'if', 'while', 'for', '?:' must be of
- *	type bool.
+ *	type bool, except for a literal 0 in a do-while loop.
  *
  * strict-bool-operand-unary:
  *	Operator	bool?	scalar?
@@ -62,29 +62,17 @@
  *	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.  Another implementation
- *	technique for bit sets is a plain integer.
- *
  *	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: These rules ensure that conforming code can be compiled without
- *	change in behavior using old compilers that implement bool as an
- *	ordinary integer type, without the special rule C99 6.3.1.2.
- *
- *	Note: There is a crucial difference between a _Bool variable and an
- *	ordinary integer variable.  C99 6.3.1.2 defines a conversion from an
- *	arbitrary scalar value to _Bool as equivalent to (value != 0 ? 1 : 0).
- *	This means that even if _Bool is implemented as an 8-bit unsigned
- *	integer, assigning 256 to it would still result in the value 1 being
- *	stored.  Storing 256 in an ordinary 8-bit unsigned integer would
- *	result in the value 0 being stored.  See the test d_c99_bool.c for
- *	more details.
+ *	Note: Counterexamples for contexts are assignments to a bool variable,
+ *	as without the conversion from C99 6.3.1.2, converting an integer to a
+ *	"bool-like" integer type truncated the value instead of comparing it
+ *	to 0.
+ *
+ *	Note: These rules ensure that conforming code behaves the same in both
+ *	C99 and in environments that emulate a boolean type using a small
+ *	integer type.
  */
 
 /*
@@ -413,9 +401,7 @@ strict_bool_conversion_from_bool_to_scal
 }
 
 /*
- * strict-bool-controlling-expression:
- *	Controlling expressions in 'if', 'while', 'for', '?:' must be of
- *	type bool.
+ * strict-bool-controlling-expression
  */
 
 void
@@ -466,14 +452,36 @@ strict_bool_controlling_expression(bool 
 		do_nothing();
 	if (p != (void *)0)
 		do_nothing();
+
+	// An endless loop. The preferred form is 'for (;;)' instead.
+	do {
+	/* expect+1: warning: constant in conditional context [161] */
+	} while (__lint_true);
+
+	// A do-once "loop", often used in statement macros.
+	/* expect+1: warning: loop not entered at top [207] */
+	do {
+	} while (__lint_false);
+
+	// This form is too unusual to be allowed in strict bool mode.
+	do {
+	/* expect+2: error: controlling expression must be bool, not 'int' [333] */
+	/* expect+1: warning: constant in conditional context [161] */
+	} while (1);
+
+	// Even though 0 is an integer instead of a bool, this idiom is so
+	// common that it is frequently used in system headers.  Since the
+	// Clang preprocessor does not mark each token as coming from a system
+	// header or from user code, this idiom can only be allowed everywhere
+	// or nowhere.
+	/* expect+1: warning: loop not entered at top [207] */
+	do {
+	/* expect+1: error: controlling expression must be bool, not 'int' [333] */
+	} while (0);
 }
 
 /*
- * strict-bool-operand-unary:
- *	Operator	bool?	scalar?
- *	!		yes	-
- *	&		yes	yes
- *	The other unary operators do not accept bool operands.
+ * strict-bool-operand-unary
  */
 
 void
@@ -517,23 +525,7 @@ strict_bool_operand_unary_address(void)
 /* see strict_bool_operand_unary_all below for the other unary operators. */
 
 /*
- * strict-bool-operand-binary:
- *	Operator	left:	bool?	other?	right:	

CVS commit: src/lib/libc/gen

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:58:58 UTC 2024

Modified Files:
src/lib/libc/gen: pwcache.c

Log Message:
libc/pwcache.c: remove stray semicolon from do-while-0 macro


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/gen/pwcache.c

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



CVS commit: src/lib/libc/gen

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:58:58 UTC 2024

Modified Files:
src/lib/libc/gen: pwcache.c

Log Message:
libc/pwcache.c: remove stray semicolon from do-while-0 macro


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/gen/pwcache.c

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

Modified files:

Index: src/lib/libc/gen/pwcache.c
diff -u src/lib/libc/gen/pwcache.c:1.34 src/lib/libc/gen/pwcache.c:1.35
--- src/lib/libc/gen/pwcache.c:1.34	Tue Apr 19 20:32:15 2022
+++ src/lib/libc/gen/pwcache.c	Sun May 12 10:58:58 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: pwcache.c,v 1.34 2022/04/19 20:32:15 rillig Exp $	*/
+/*	$NetBSD: pwcache.c,v 1.35 2024/05/12 10:58:58 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -74,7 +74,7 @@
 #if 0
 static char sccsid[] = "@(#)cache.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: pwcache.c,v 1.34 2022/04/19 20:32:15 rillig Exp $");
+__RCSID("$NetBSD: pwcache.c,v 1.35 2024/05/12 10:58:58 rillig Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -524,7 +524,7 @@ gid_from_group(const char *name, gid_t *
 			arr = NULL;			\
 		}	\
 		fail = 0;\
-	} while (0);
+	} while (0)
 
 int
 pwcache_userdb(



CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:45:13 UTC 2024

Modified Files:
src/sys/sys: lock.h

Log Message:
sys/lock.h: remove stray semicolon from SPINLOCK_BACKOFF macro


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/sys/lock.h

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



CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:45:13 UTC 2024

Modified Files:
src/sys/sys: lock.h

Log Message:
sys/lock.h: remove stray semicolon from SPINLOCK_BACKOFF macro


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/sys/lock.h

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

Modified files:

Index: src/sys/sys/lock.h
diff -u src/sys/sys/lock.h:1.93 src/sys/sys/lock.h:1.94
--- src/sys/sys/lock.h:1.93	Sun May 12 10:34:56 2024
+++ src/sys/sys/lock.h	Sun May 12 10:45:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock.h,v 1.93 2024/05/12 10:34:56 rillig Exp $	*/
+/*	$NetBSD: lock.h,v 1.94 2024/05/12 10:45:13 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2006, 2007 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@ do {\
 	}			\
 	if ((count) < SPINLOCK_BACKOFF_MAX)			\
 		(count) += (count);\
-} while (0);
+} while (0)
 
 #ifdef LOCKDEBUG
 #define	SPINLOCK_SPINOUT(spins)		((spins)++ > 0x0fff)



CVS commit: src/include

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:41:23 UTC 2024

Modified Files:
src/include: bitstring.h

Log Message:
include/bitstring.h: remove CONSTCOND comment from do-while-0 loop

Lint doesn't need this comment anymore, as there is nothing surprising
or unusual about this idiom.

sed -Ei 's,} *while *\(/\* *CONSTCOND *\*/ *0\),} while (0),' *.h


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/include/bitstring.h

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

Modified files:

Index: src/include/bitstring.h
diff -u src/include/bitstring.h:1.14 src/include/bitstring.h:1.15
--- src/include/bitstring.h:1.14	Thu Mar 17 02:25:32 2016
+++ src/include/bitstring.h	Sun May 12 10:41:23 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: bitstring.h,v 1.14 2016/03/17 02:25:32 christos Exp $	*/
+/*	$NetBSD: bitstring.h,v 1.15 2024/05/12 10:41:23 rillig Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -98,7 +98,7 @@ typedef	unsigned char bitstr_t;
 		bit_clear(_name, _start); \
 		_start++; \
 	} \
-} while(/*CONSTCOND*/0)
+} while (0)
 
 /* set bits start ... stop in bitstring */
 #define	bit_nset(name, start, stop) do { \
@@ -108,7 +108,7 @@ typedef	unsigned char bitstr_t;
 		bit_set(_name, _start); \
 		_start++; \
 	} \
-} while(/*CONSTCOND*/0)
+} while (0)
 
 /* find first bit clear in name */
 #define	bit_ffc(name, nbits, value) do { \
@@ -121,7 +121,7 @@ typedef	unsigned char bitstr_t;
 			break; \
 		} \
 	*(value) = _value; \
-} while(/*CONSTCOND*/0)
+} while (0)
 
 /* find first bit set in name */
 #define	bit_ffs(name, nbits, value) do { \
@@ -134,6 +134,6 @@ typedef	unsigned char bitstr_t;
 			break; \
 		} \
 	*(value) = _value; \
-} while(/*CONSTCOND*/0)
+} while (0)
 
 #endif /* !_BITSTRING_H_ */



CVS commit: src/include

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:41:23 UTC 2024

Modified Files:
src/include: bitstring.h

Log Message:
include/bitstring.h: remove CONSTCOND comment from do-while-0 loop

Lint doesn't need this comment anymore, as there is nothing surprising
or unusual about this idiom.

sed -Ei 's,} *while *\(/\* *CONSTCOND *\*/ *0\),} while (0),' *.h


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/include/bitstring.h

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



CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:38:03 UTC 2024

Modified Files:
src/sys/sys: module_hook.h

Log Message:
sys/module_hook.h: remove CONSTCOND comment from do-while-0 loop

Lint doesn't need this comment anymore, as there is nothing surprising
or unusual about this idiom.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/sys/module_hook.h

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

Modified files:

Index: src/sys/sys/module_hook.h
diff -u src/sys/sys/module_hook.h:1.6 src/sys/sys/module_hook.h:1.7
--- src/sys/sys/module_hook.h:1.6	Thu Dec 12 22:55:20 2019
+++ src/sys/sys/module_hook.h	Sun May 12 10:38:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: module_hook.h,v 1.6 2019/12/12 22:55:20 pgoyette Exp $	*/
+/* $NetBSD: module_hook.h,v 1.7 2024/05/12 10:38:03 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -70,14 +70,14 @@ extern struct hook ## _t {	\
 do {\
 	(hook).f = func;	\
 	module_hook_set(&(hook).hooked, &(hook).lc);		\
-} while /* CONSTCOND */ (0)
+} while (0)
 
 #define MODULE_HOOK_UNSET(hook)	\
 do {\
 	KASSERT((hook).f);	\
 	module_hook_unset(&(hook).hooked, &(hook).lc);		\
 	(hook).f = NULL;	/* paranoia */			\
-} while /* CONSTCOND */ (0)
+} while (0)
 
 #define MODULE_HOOK_CALL(hook, args, default, retval)		\
 do {\
@@ -87,7 +87,7 @@ do {\
 	} else {		\
 		(retval) = (default);\
 	}			\
-} while /* CONSTCOND */ (0)
+} while (0)
 
 #define MODULE_HOOK_CALL_VOID(hook, args, default)		\
 do {\
@@ -97,6 +97,6 @@ do {\
 	} else {		\
 		default;	\
 	}			\
-} while /* CONSTCOND */ (0)
+} while (0)
 
 #endif	/* _SYS_MODULE_HOOK_H */



CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:38:03 UTC 2024

Modified Files:
src/sys/sys: module_hook.h

Log Message:
sys/module_hook.h: remove CONSTCOND comment from do-while-0 loop

Lint doesn't need this comment anymore, as there is nothing surprising
or unusual about this idiom.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/sys/module_hook.h

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



CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:34:56 UTC 2024

Modified Files:
src/sys/sys: bitops.h boot_flag.h bootblock.h buf.h cctr.h cdefs.h
cpu_data.h fd_set.h ieee754.h ipc.h kernhist.h lock.h mbuf.h msg.h
queue.h rbtree.h resourcevar.h sem.h shm.h siginfo.h sigtypes.h
socketvar.h systm.h time.h tree.h

Log Message:
sys/sys: remove CONSTCOND comment from do-while-0 loop

Lint doesn't need this comment anymore, as there is nothing surprising
or unusual about this idiom.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/sys/bitops.h
cvs rdiff -u -r1.7 -r1.8 src/sys/sys/boot_flag.h src/sys/sys/fd_set.h
cvs rdiff -u -r1.59 -r1.60 src/sys/sys/bootblock.h
cvs rdiff -u -r1.134 -r1.135 src/sys/sys/buf.h
cvs rdiff -u -r1.4 -r1.5 src/sys/sys/cctr.h
cvs rdiff -u -r1.162 -r1.163 src/sys/sys/cdefs.h
cvs rdiff -u -r1.55 -r1.56 src/sys/sys/cpu_data.h src/sys/sys/shm.h
cvs rdiff -u -r1.17 -r1.18 src/sys/sys/ieee754.h
cvs rdiff -u -r1.37 -r1.38 src/sys/sys/ipc.h
cvs rdiff -u -r1.26 -r1.27 src/sys/sys/kernhist.h
cvs rdiff -u -r1.92 -r1.93 src/sys/sys/lock.h
cvs rdiff -u -r1.239 -r1.240 src/sys/sys/mbuf.h
cvs rdiff -u -r1.29 -r1.30 src/sys/sys/msg.h
cvs rdiff -u -r1.76 -r1.77 src/sys/sys/queue.h
cvs rdiff -u -r1.11 -r1.12 src/sys/sys/rbtree.h
cvs rdiff -u -r1.58 -r1.59 src/sys/sys/resourcevar.h
cvs rdiff -u -r1.34 -r1.35 src/sys/sys/sem.h src/sys/sys/siginfo.h
cvs rdiff -u -r1.12 -r1.13 src/sys/sys/sigtypes.h
cvs rdiff -u -r1.168 -r1.169 src/sys/sys/socketvar.h
cvs rdiff -u -r1.305 -r1.306 src/sys/sys/systm.h
cvs rdiff -u -r1.80 -r1.81 src/sys/sys/time.h
cvs rdiff -u -r1.20 -r1.21 src/sys/sys/tree.h

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



CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 10:34:56 UTC 2024

Modified Files:
src/sys/sys: bitops.h boot_flag.h bootblock.h buf.h cctr.h cdefs.h
cpu_data.h fd_set.h ieee754.h ipc.h kernhist.h lock.h mbuf.h msg.h
queue.h rbtree.h resourcevar.h sem.h shm.h siginfo.h sigtypes.h
socketvar.h systm.h time.h tree.h

Log Message:
sys/sys: remove CONSTCOND comment from do-while-0 loop

Lint doesn't need this comment anymore, as there is nothing surprising
or unusual about this idiom.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/sys/bitops.h
cvs rdiff -u -r1.7 -r1.8 src/sys/sys/boot_flag.h src/sys/sys/fd_set.h
cvs rdiff -u -r1.59 -r1.60 src/sys/sys/bootblock.h
cvs rdiff -u -r1.134 -r1.135 src/sys/sys/buf.h
cvs rdiff -u -r1.4 -r1.5 src/sys/sys/cctr.h
cvs rdiff -u -r1.162 -r1.163 src/sys/sys/cdefs.h
cvs rdiff -u -r1.55 -r1.56 src/sys/sys/cpu_data.h src/sys/sys/shm.h
cvs rdiff -u -r1.17 -r1.18 src/sys/sys/ieee754.h
cvs rdiff -u -r1.37 -r1.38 src/sys/sys/ipc.h
cvs rdiff -u -r1.26 -r1.27 src/sys/sys/kernhist.h
cvs rdiff -u -r1.92 -r1.93 src/sys/sys/lock.h
cvs rdiff -u -r1.239 -r1.240 src/sys/sys/mbuf.h
cvs rdiff -u -r1.29 -r1.30 src/sys/sys/msg.h
cvs rdiff -u -r1.76 -r1.77 src/sys/sys/queue.h
cvs rdiff -u -r1.11 -r1.12 src/sys/sys/rbtree.h
cvs rdiff -u -r1.58 -r1.59 src/sys/sys/resourcevar.h
cvs rdiff -u -r1.34 -r1.35 src/sys/sys/sem.h src/sys/sys/siginfo.h
cvs rdiff -u -r1.12 -r1.13 src/sys/sys/sigtypes.h
cvs rdiff -u -r1.168 -r1.169 src/sys/sys/socketvar.h
cvs rdiff -u -r1.305 -r1.306 src/sys/sys/systm.h
cvs rdiff -u -r1.80 -r1.81 src/sys/sys/time.h
cvs rdiff -u -r1.20 -r1.21 src/sys/sys/tree.h

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

Modified files:

Index: src/sys/sys/bitops.h
diff -u src/sys/sys/bitops.h:1.15 src/sys/sys/bitops.h:1.16
--- src/sys/sys/bitops.h:1.15	Sun Sep 12 15:22:05 2021
+++ src/sys/sys/bitops.h	Sun May 12 10:34:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: bitops.h,v 1.15 2021/09/12 15:22:05 rillig Exp $	*/
+/*	$NetBSD: bitops.h,v 1.16 2024/05/12 10:34:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
@@ -323,7 +323,7 @@ fast_remainder32(uint32_t _v, uint32_t _
 	size_t __i;			\
 	for (__i = 0; __i < __arraycount((__v)->_b); __i++)		\
 		(__v)->_b[__i] = 0;	\
-	} while (/* CONSTCOND */ 0)
+	} while (0)
 #endif /* GCC 2.95 */
 
 #endif /* _SYS_BITOPS_H_ */

Index: src/sys/sys/boot_flag.h
diff -u src/sys/sys/boot_flag.h:1.7 src/sys/sys/boot_flag.h:1.8
--- src/sys/sys/boot_flag.h:1.7	Tue Apr 29 19:16:08 2008
+++ src/sys/sys/boot_flag.h	Sun May 12 10:34:56 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: boot_flag.h,v 1.7 2008/04/29 19:16:08 ad Exp $ */
+/* $NetBSD: boot_flag.h,v 1.8 2024/05/12 10:34:56 rillig Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -86,6 +86,6 @@
 		break;		\
 	} /* switch */		\
 \
-	} while (/* CONSTCOND */ 0)
+	} while (0)
 
 #endif /* _SYS_BOOT_FLAG_H_ */
Index: src/sys/sys/fd_set.h
diff -u src/sys/sys/fd_set.h:1.7 src/sys/sys/fd_set.h:1.8
--- src/sys/sys/fd_set.h:1.7	Sun Jun 24 12:05:40 2018
+++ src/sys/sys/fd_set.h	Sun May 12 10:34:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: fd_set.h,v 1.7 2018/06/24 12:05:40 kamil Exp $	*/
+/*	$NetBSD: fd_set.h,v 1.8 2024/05/12 10:34:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -81,7 +81,7 @@ typedef	struct fd_set {
 	unsigned int __i;		\
 	for (__i = 0; __i < __NFD_SIZE; __i++)\
 		__fds->fds_bits[__i] = 0;\
-	} while (/* CONSTCOND */ 0)
+	} while (0)
 #endif /* GCC 2.95 */
 
 /*
@@ -100,7 +100,7 @@ typedef	struct fd_set {
 	unsigned int __i;		\
 	for (__i = 0; __i < __NFD_SIZE; __i++)\
 		__t->fds_bits[__i] = __f->fds_bits[__i];		\
-	} while (/* CONSTCOND */ 0)
+	} while (0)
 #endif /* GCC 2.95 */
 
 #endif /* _NETBSD_SOURCE */

Index: src/sys/sys/bootblock.h
diff -u src/sys/sys/bootblock.h:1.59 src/sys/sys/bootblock.h:1.60
--- src/sys/sys/bootblock.h:1.59	Sat May 11 22:10:27 2024
+++ src/sys/sys/bootblock.h	Sun May 12 10:34:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootblock.h,v 1.59 2024/05/11 22:10:27 tsutsui Exp $	*/
+/*	$NetBSD: bootblock.h,v 1.60 2024/05/12 10:34:56 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2002-2004 The NetBSD Foundation, Inc.
@@ -800,7 +800,7 @@ struct alpha_boot_block {
 		_i++)		\
 			_cksum += le64toh(_bb->bb_data[_i]);		\
 		*(cksum) = htole64(_cksum);\
-	} while (/*CONSTCOND*/ 0)
+	} while (0)
 
 /* --
  * apple --

Index: src/sys/sys/buf.h
diff -u src/sys/sys/buf.h:1.134 src/sys/sys/buf.h:1.135
--- src/sys/sys/buf.h:1.134	Fri Jul 31 04:07:30 2020
+++ src/sys/sys/buf.h	Sun May 12 10:34:56 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.134 2020/07/31 04:07:30 chs Exp $ */
+/* $NetBSD: buf.h,v 1.135 2024/05/12 10:34:56 rillig Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.

CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 09:34:25 UTC 2024

Modified Files:
src/sys/sys: ktrace.h

Log Message:
sys/ktrace.h: fix off-by-one in snprintb for ktrace flags

There's a one-bit gap between TRC_EMUL and INHERIT.

Noticed by RVP.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/sys/ktrace.h

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

Modified files:

Index: src/sys/sys/ktrace.h
diff -u src/sys/sys/ktrace.h:1.69 src/sys/sys/ktrace.h:1.70
--- src/sys/sys/ktrace.h:1.69	Fri May 10 09:30:47 2024
+++ src/sys/sys/ktrace.h	Sun May 12 09:34:25 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ktrace.h,v 1.69 2024/05/10 09:30:47 rillig Exp $	*/
+/*	$NetBSD: ktrace.h,v 1.70 2024/05/12 09:34:25 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -265,7 +265,7 @@ struct ktr_execfd {
 "b\16MIB\0" \
 "b\17EXEC_FD\0" \
 "f\30\4VERSION\0" \
-"b\35TRC_EMUL\0" \
+"b\34TRC_EMUL\0" \
 "b\36INHERIT\0" \
 "b\37PERSISTENT\0"
 



CVS commit: src/sys/sys

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 09:34:25 UTC 2024

Modified Files:
src/sys/sys: ktrace.h

Log Message:
sys/ktrace.h: fix off-by-one in snprintb for ktrace flags

There's a one-bit gap between TRC_EMUL and INHERIT.

Noticed by RVP.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/sys/ktrace.h

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



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

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 09:07:41 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y lex.c tree.c

Log Message:
lint: don't call memcpy with null pointer

Even copying 0 bytes from a null pointer invokes undefined behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.502 -r1.503 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.642 -r1.643 src/usr.bin/xlint/lint1/tree.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.502 src/usr.bin/xlint/lint1/cgram.y:1.503
--- src/usr.bin/xlint/lint1/cgram.y:1.502	Sun May 12 08:48:36 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sun May 12 09:07:41 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.502 2024/05/12 08:48:36 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.503 2024/05/12 09:07:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.502 2024/05/12 08:48:36 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.503 2024/05/12 09:07:41 rillig Exp $");
 #endif
 
 #include 
@@ -118,9 +118,10 @@ attribute_list_add(attribute_list *list,
 		attribute *old_attrs = list->attrs;
 		list->cap = 16 + 2 * list->cap;
 		list->attrs = block_zero_alloc(
-		list->cap * sizeof(*list->attrs), "attribute_list.attrs");
-		memcpy(list->attrs, old_attrs,
-		list->len * sizeof(*list->attrs));
+		list->cap * sizeof(*list->attrs), "attribute[]");
+		if (list->len > 0)
+			memcpy(list->attrs, old_attrs,
+			list->len * sizeof(*list->attrs));
 	}
 	list->attrs[list->len++] = attr;
 }

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.226 src/usr.bin/xlint/lint1/lex.c:1.227
--- src/usr.bin/xlint/lint1/lex.c:1.226	Sun May 12 08:48:36 2024
+++ src/usr.bin/xlint/lint1/lex.c	Sun May 12 09:07:41 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.226 2024/05/12 08:48:36 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.227 2024/05/12 09:07:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.226 2024/05/12 08:48:36 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.227 2024/05/12 09:07:41 rillig Exp $");
 #endif
 
 #include 
@@ -1545,9 +1545,10 @@ seq_reserve(balanced_token_sequence *seq
 		seq->cap = 16 + 2 * seq->cap;
 		const balanced_token *old_tokens = seq->tokens;
 		balanced_token *new_tokens = block_zero_alloc(
-		seq->cap * sizeof(*seq->tokens), "balanced_tokens");
-		memcpy(new_tokens, old_tokens,
-		seq->len * sizeof(*seq->tokens));
+		seq->cap * sizeof(*seq->tokens), "balanced_token[]");
+		if (seq->len > 0)
+			memcpy(new_tokens, old_tokens,
+			seq->len * sizeof(*seq->tokens));
 		seq->tokens = new_tokens;
 	}
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.642 src/usr.bin/xlint/lint1/tree.c:1.643
--- src/usr.bin/xlint/lint1/tree.c:1.642	Sat May 11 15:53:38 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sun May 12 09:07:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.642 2024/05/11 15:53:38 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.643 2024/05/12 09:07:41 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.642 2024/05/11 15:53:38 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.643 2024/05/12 09:07:41 rillig Exp $");
 #endif
 
 #include 
@@ -4214,10 +4214,10 @@ add_function_argument(function_call *cal
 	if (call->args_len >= call->args_cap) {
 		call->args_cap += 8;
 		tnode_t **new_args = expr_zero_alloc(
-		call->args_cap * sizeof(*call->args),
-		"function_call.args");
-		memcpy(new_args, call->args,
-		call->args_len * sizeof(*call->args));
+		call->args_cap * sizeof(*call->args), "tnode*[]");
+		if (call->args_len > 0)
+			memcpy(new_args, call->args,
+			call->args_len * sizeof(*call->args));
 		call->args = new_args;
 	}
 	call->args[call->args_len++] = arg;



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

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 09:07:41 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y lex.c tree.c

Log Message:
lint: don't call memcpy with null pointer

Even copying 0 bytes from a null pointer invokes undefined behavior.


To generate a diff of this commit:
cvs rdiff -u -r1.502 -r1.503 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.642 -r1.643 src/usr.bin/xlint/lint1/tree.c

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



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

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 08:48:36 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y externs1.h lex.c scan.l

Log Message:
lint: move code for parsing balanced token sequences to lex.c

To access yytext from lex.c, the lexer needs to be in %pointer mode,
which was specified in IEEE Std 1003.1, 2004 Edition and thus should be
old enough to be available on platforms other than NetBSD, for use in
tools/lint1 where lint1 is built before yacc and lex.


To generate a diff of this commit:
cvs rdiff -u -r1.501 -r1.502 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.141 -r1.142 src/usr.bin/xlint/lint1/scan.l

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.501 src/usr.bin/xlint/lint1/cgram.y:1.502
--- src/usr.bin/xlint/lint1/cgram.y:1.501	Sat May 11 16:58:59 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sun May 12 08:48:36 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.501 2024/05/11 16:58:59 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.502 2024/05/12 08:48:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.501 2024/05/11 16:58:59 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.502 2024/05/12 08:48:36 rillig Exp $");
 #endif
 
 #include 
@@ -2562,78 +2562,11 @@ read_until_rparen(void)
 	yyclearin;
 }
 
-static void
-fill_token(token *tok)
-{
-	switch (yychar) {
-	case T_NAME:
-	case T_TYPENAME:
-		tok->kind = TK_IDENTIFIER;
-		tok->u.identifier = xstrdup(yylval.y_name->sb_name);
-		break;
-	case T_CON:
-		tok->kind = TK_CONSTANT;
-		tok->u.constant = *yylval.y_val;
-		break;
-	case T_NAMED_CONSTANT:
-		tok->kind = TK_IDENTIFIER;
-		tok->u.identifier = xstrdup(yytext);
-		break;
-	case T_STRING:;
-		tok->kind = TK_STRING_LITERALS;
-		tok->u.string_literals.len = yylval.y_string->len;
-		tok->u.string_literals.cap = yylval.y_string->cap;
-		tok->u.string_literals.data = xstrdup(yylval.y_string->data);
-		break;
-	default:
-		tok->kind = TK_PUNCTUATOR;
-		tok->u.punctuator = xstrdup(yytext);
-	}
-}
-
-static void
-seq_reserve(balanced_token_sequence *seq)
-{
-	if (seq->len >= seq->cap) {
-		seq->cap = 16 + 2 * seq->cap;
-		const balanced_token *old_tokens = seq->tokens;
-		balanced_token *new_tokens = block_zero_alloc(
-		seq->cap * sizeof(*seq->tokens), "balanced_tokens");
-		memcpy(new_tokens, old_tokens, seq->len * sizeof(*seq->tokens));
-		seq->tokens = new_tokens;
-	}
-}
-
-static balanced_token_sequence
-read_balanced(int opening)
-{
-	debug_enter();
-	int closing = opening == T_LPAREN ? T_RPAREN
-	: opening == T_LBRACK ? T_RBRACK : T_RBRACE;
-	balanced_token_sequence seq = { NULL, 0, 0 };
-	debug_step("opening %d, closing %d", opening, closing);
-
-	while (yychar = yylex(), yychar > 0 && yychar != closing) {
-		debug_step("reading token %d", yychar);
-		seq_reserve();
-		if (yychar == T_LPAREN
-		|| yychar == T_LBRACK
-		|| yychar == T_LBRACE) {
-			seq.tokens[seq.len].kind = yychar == T_LPAREN ? '('
-			: yychar == T_LBRACK ? '[' : '{';
-			seq.tokens[seq.len++].u.tokens = read_balanced(yychar);
-		} else
-			fill_token([seq.len++].u.token);
-	}
-	debug_leave();
-	return seq;
-}
-
 static balanced_token_sequence
 read_balanced_token_sequence(void)
 {
 	lint_assert(yychar < 0);
-	balanced_token_sequence seq = read_balanced(T_LPAREN);
+	balanced_token_sequence seq = lex_balanced();
 	yyclearin;
 	return seq;
 }

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.226 src/usr.bin/xlint/lint1/externs1.h:1.227
--- src/usr.bin/xlint/lint1/externs1.h:1.226	Sat May 11 16:12:28 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Sun May 12 08:48:36 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.226 2024/05/11 16:12:28 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.227 2024/05/12 08:48:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -72,6 +72,7 @@ extern int yydebug;
 
 int yyerror(const char *);
 int yyparse(void);
+extern char *yytext;
 
 /*
  * lex.c
@@ -402,6 +403,7 @@ void lex_slash_slash_comment(void);
 void lex_unknown_character(int);
 int lex_input(void);
 bool quoted_next(const buffer *, quoted_iterator *);
+balanced_token_sequence lex_balanced(void);
 
 /*
  * ckbool.c

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.225 src/usr.bin/xlint/lint1/lex.c:1.226
--- src/usr.bin/xlint/lint1/lex.c:1.225	Thu May  9 11:08:07 2024
+++ src/usr.bin/xlint/lint1/lex.c	Sun May 12 08:48:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.225 2024/05/09 11:08:07 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.226 2024/05/12 08:48:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 

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

2024-05-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun May 12 08:48:36 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y externs1.h lex.c scan.l

Log Message:
lint: move code for parsing balanced token sequences to lex.c

To access yytext from lex.c, the lexer needs to be in %pointer mode,
which was specified in IEEE Std 1003.1, 2004 Edition and thus should be
old enough to be available on platforms other than NetBSD, for use in
tools/lint1 where lint1 is built before yacc and lex.


To generate a diff of this commit:
cvs rdiff -u -r1.501 -r1.502 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.141 -r1.142 src/usr.bin/xlint/lint1/scan.l

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



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

2024-05-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 11 16:58:59 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: clean up grammar rule name for 'type_specifier'


To generate a diff of this commit:
cvs rdiff -u -r1.500 -r1.501 src/usr.bin/xlint/lint1/cgram.y

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



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

2024-05-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 11 16:58:59 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: clean up grammar rule name for 'type_specifier'


To generate a diff of this commit:
cvs rdiff -u -r1.500 -r1.501 src/usr.bin/xlint/lint1/cgram.y

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.500 src/usr.bin/xlint/lint1/cgram.y:1.501
--- src/usr.bin/xlint/lint1/cgram.y:1.500	Sat May 11 16:12:28 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sat May 11 16:58:59 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.500 2024/05/11 16:12:28 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.501 2024/05/11 16:58:59 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.500 2024/05/11 16:12:28 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.501 2024/05/11 16:58:59 rillig Exp $");
 #endif
 
 #include 
@@ -375,7 +375,7 @@ new_attribute(const sbuf_t *prefix, cons
 /* No type for notype_init_declarator. */
 /* No type for type_init_declarator. */
 %type			storage_class_specifier
-%type		type_specifier
+%type		type_type_specifier
 %type		notype_type_specifier
 %type		struct_or_union_specifier
 %type		struct_or_union
@@ -947,7 +947,7 @@ begin_type_declaration_specifiers:	/* se
 	begin_type_typespec {
 		dcs_add_type($1);
 	}
-|	begin_type_declmods type_specifier {
+|	begin_type_declmods type_type_specifier {
 		dcs_add_type($2);
 	}
 |	type_attribute begin_type_declaration_specifiers
@@ -979,7 +979,7 @@ begin_type_specifier_qualifier_list_post
 	begin_type_typespec {
 		dcs_add_type($1);
 	}
-|	begin_type_qualifier_list type_specifier {
+|	begin_type_qualifier_list type_type_specifier {
 		dcs_add_type($2);
 	}
 |	begin_type_specifier_qualifier_list_postfix type_qualifier {
@@ -1039,7 +1039,7 @@ type_attribute_opt:
 
 type_attribute:			/* See C11 6.7 declaration-specifiers */
 	gcc_attribute_specifier
-|	T_ALIGNAS T_LPAREN type_specifier T_RPAREN {		/* C11 6.7.5 */
+|	T_ALIGNAS T_LPAREN type_type_specifier T_RPAREN {		/* C11 6.7.5 */
 		dcs_add_alignas(build_sizeof($3));
 	}
 |	T_ALIGNAS T_LPAREN constant_expression T_RPAREN {	/* C11 6.7.5 */
@@ -1122,7 +1122,9 @@ storage_class_specifier:
 ;
 
 /* C99 6.7.2, C23 6.7.3.1 */
-type_specifier:
+/* The rule 'type_specifier' is split into the 'notype' and 'type' variants. */
+
+type_type_specifier:
 	notype_type_specifier
 |	T_TYPENAME {
 		$$ = getsym($1)->s_type;
@@ -1213,8 +1215,8 @@ member_declaration_list:
 	}
 ;
 
-/* Was named struct_declaration until C11. */
 /* K ???, C90 ???, C99 6.7.2.1, C11 6.7.2.1, C23 6.7.3.2 */
+/* Was named struct_declaration until C11. */
 member_declaration:
 	begin_type_qualifier_list end_type {
 		/* ^^ There is no check for the missing type-specifier. */
@@ -1264,8 +1266,8 @@ member_declaration:
 
 /* C23 6.7.3.2 */
 /* The rule 'member_declarator_list' is split into the 'type' and 'notype' variants. */
-
 /* Was named struct_declarator_list until C11. */
+
 notype_member_declarator_list:
 	notype_member_declarator {
 		$$ = declare_member($1);
@@ -1277,7 +1279,6 @@ notype_member_declarator_list:
 	}
 ;
 
-/* Was named struct_declarator_list until C11. */
 type_member_declarator_list:
 	type_member_declarator {
 		$$ = declare_member($1);
@@ -1291,8 +1292,8 @@ type_member_declarator_list:
 
 /* C23 6.7.3.2 */
 /* The rule 'member_declarator' is split into the 'type' and 'notype' variants. */
-
 /* Was named struct_declarator until C11. */
+
 notype_member_declarator:
 	notype_declarator
 	/* C99 6.7.2.1 */
@@ -1307,7 +1308,6 @@ notype_member_declarator:
 	}
 ;
 
-/* Was named struct_declarator until C11. */
 type_member_declarator:
 	type_declarator
 |	type_declarator T_COLON constant_expression type_attribute_list_opt {



CVS commit: src

2024-05-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 11 16:12:28 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c
src/usr.bin/xlint/lint1: cgram.y debug.c externs1.h lint1.h scan.l

Log Message:
lint: parse but otherwise ignore C23 attributes

The C23 attributes are only parsed before an expression in an expression
statement, as a proof of concept.  Other places will follow later.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.499 -r1.500 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/xlint/lint1/scan.l

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



CVS commit: src

2024-05-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 11 16:12:28 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c
src/usr.bin/xlint/lint1: cgram.y debug.c externs1.h lint1.h scan.l

Log Message:
lint: parse but otherwise ignore C23 attributes

The C23 attributes are only parsed before an expression in an expression
statement, as a proof of concept.  Other places will follow later.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.499 -r1.500 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/xlint/lint1/scan.l

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.12 src/tests/usr.bin/xlint/lint1/c23.c:1.13
--- src/tests/usr.bin/xlint/lint1/c23.c:1.12	Thu May  9 20:56:41 2024
+++ src/tests/usr.bin/xlint/lint1/c23.c	Sat May 11 16:12:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c23.c,v 1.12 2024/05/09 20:56:41 rillig Exp $	*/
+/*	$NetBSD: c23.c,v 1.13 2024/05/11 16:12:28 rillig Exp $	*/
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
@@ -109,3 +109,57 @@ thread_local extern int extern_thread_lo
 static thread_local int static_thread_local_1;
 /* expect+1: warning: static variable 'static_thread_local_2' unused [226] */
 thread_local static int static_thread_local_2;
+
+
+int
+attributes(int i)
+{
+	// An attribute specifier list may be empty.
+	[[]]i++;
+
+	// There may be leading or trailing commas.
+	[[,]]i++;
+
+	// There may be arbitrary commas around or between the attributes.
+	[[,]]i++;
+
+	// An attribute may be a plain identifier without arguments.
+	[[identifier]]i++;
+
+	// The identifier may be prefixed with one additional identifier.
+	[[prefix::identifier]]i++;
+
+	// An attribute may have empty arguments.
+	[[identifier()]]i++;
+
+	// The arguments of an attribute may be arbitrary tokens.
+	[[identifier([])]]i++;
+
+	// The commas in this "argument list" are ordinary punctuator tokens,
+	// they do not separate any arguments.
+	// The structure of the attribute argument is:
+	//	1. empty balanced token sequence between '[' and ']'
+	//	2. token ','
+	//	3. empty balanced token sequence between '{' and '}'
+	//	4. token ','
+	//	5. empty balanced token sequence between '(' and ')'
+	[[identifier([], {}, ())]]i++;
+
+	// Inside an argument, parentheses may be nested.
+	[[identifier(())]]i++;
+	// Inside an argument, brackets may be nested.
+	[[identifier([])]]i++;
+	// Inside an argument, braces may be nested.
+	[[identifier({})]]i++;
+
+	// An attribute argument may contain arbitrary punctuation.
+	[[identifier( ? ? ? : : :: )]]i++;
+
+	// An attribute argument may contain constants and string literals.
+	[[identifier(0, 0.0, "hello" " " "world")]]i++;
+
+	// There may be multiple attribute specifier sequences in a row.
+	[[]][[]][[]]i++;
+
+	return i;
+}

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.499 src/usr.bin/xlint/lint1/cgram.y:1.500
--- src/usr.bin/xlint/lint1/cgram.y:1.499	Thu May  9 20:56:41 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sat May 11 16:12:28 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.499 2024/05/09 20:56:41 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.500 2024/05/11 16:12:28 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.499 2024/05/09 20:56:41 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.500 2024/05/11 16:12:28 rillig Exp $");
 #endif
 
 #include 
@@ -69,6 +69,7 @@ static int saved_lwarn = LWARN_NOTHING_S
 
 static void cgram_declare(sym_t *, bool, sbuf_t *);
 static void read_until_rparen(void);
+static balanced_token_sequence read_balanced_token_sequence(void);
 static sym_t *symbolrename(sym_t *, sbuf_t *);
 
 
@@ -110,6 +111,42 @@ is_either(const char *s, const char *a, 
 	return strcmp(s, a) == 0 || strcmp(s, b) == 0;
 }
 
+static void
+attribute_list_add(attribute_list *list, attribute attr)
+{
+	if (list->len >= list->cap) {
+		attribute *old_attrs = list->attrs;
+		list->cap = 16 + 2 * list->cap;
+		list->attrs = block_zero_alloc(
+		list->cap * sizeof(*list->attrs), "attribute_list.attrs");
+		memcpy(list->attrs, old_attrs,
+		list->len * sizeof(*list->attrs));
+	}
+	list->attrs[list->len++] = attr;
+}
+
+static void
+attribute_list_add_all(attribute_list *dst, attribute_list src)
+{
+	for (size_t i = 0, n = src.len; i < n; i++)
+		attribute_list_add(dst, src.attrs[i]);
+}
+
+static attribute
+new_attribute(const sbuf_t *prefix, const sbuf_t 

CVS commit: src

2024-05-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 11 15:53:38 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: msg_162.c t_usage.sh
src/usr.bin/xlint/lint1: err.c makeman tree.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_379.c

Log Message:
lint: warn when comparing an integer to a floating point constant


To generate a diff of this commit:
cvs rdiff -u -r1.1315 -r1.1316 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_162.c
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_379.c
cvs rdiff -u -r1.20 -r1.21 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.242 -r1.243 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/makeman
cvs rdiff -u -r1.641 -r1.642 src/usr.bin/xlint/lint1/tree.c

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1315 src/distrib/sets/lists/tests/mi:1.1316
--- src/distrib/sets/lists/tests/mi:1.1315	Sun May  5 02:53:01 2024
+++ src/distrib/sets/lists/tests/mi	Sat May 11 15:53:38 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1315 2024/05/05 02:53:01 riastradh Exp $
+# $NetBSD: mi,v 1.1316 2024/05/11 15:53:38 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -7509,6 +7509,7 @@
 ./usr/tests/usr.bin/xlint/lint1/msg_376.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_377.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/msg_378.c			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/msg_379.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/op_colon.exp			tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/xlint/lint1/op_shl_lp64.c			tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/msg_162.c
diff -u src/tests/usr.bin/xlint/lint1/msg_162.c:1.8 src/tests/usr.bin/xlint/lint1/msg_162.c:1.9
--- src/tests/usr.bin/xlint/lint1/msg_162.c:1.8	Tue Mar 28 14:44:35 2023
+++ src/tests/usr.bin/xlint/lint1/msg_162.c	Sat May 11 15:53:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_162.c,v 1.8 2023/03/28 14:44:35 rillig Exp $	*/
+/*	$NetBSD: msg_162.c,v 1.9 2024/05/11 15:53:38 rillig Exp $	*/
 # 3 "msg_162.c"
 
 // Test for message: operator '%s' compares '%s' with '%s' [162]
@@ -8,6 +8,7 @@
 void
 left_unsigned(unsigned int ui)
 {
+	/* expect+1: warning: comparing integer 'unsigned int' to floating point constant -5 [379] */
 	if (ui < -5.0) {
 	}
 

Index: src/tests/usr.bin/xlint/lint1/t_usage.sh
diff -u src/tests/usr.bin/xlint/lint1/t_usage.sh:1.20 src/tests/usr.bin/xlint/lint1/t_usage.sh:1.21
--- src/tests/usr.bin/xlint/lint1/t_usage.sh:1.20	Sat Apr 27 10:08:54 2024
+++ src/tests/usr.bin/xlint/lint1/t_usage.sh	Sat May 11 15:53:38 2024
@@ -1,4 +1,4 @@
-# $NetBSD: t_usage.sh,v 1.20 2024/04/27 10:08:54 rillig Exp $
+# $NetBSD: t_usage.sh,v 1.21 2024/05/11 15:53:38 rillig Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -39,13 +39,13 @@ suppress_messages_body()
 
 	# The largest known message.
 	atf_check \
-	"$lint1" -X 378 code.c /dev/null
+	"$lint1" -X 379 code.c /dev/null
 
 	# Larger than the largest known message.
 	atf_check \
 	-s 'exit:1' \
-	-e "inline:lint1: invalid message ID '379'\n" \
-	"$lint1" -X 379 code.c /dev/null
+	-e "inline:lint1: invalid message ID '380'\n" \
+	"$lint1" -X 380 code.c /dev/null
 
 	# Whitespace is not allowed before a message ID.
 	atf_check \

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.242 src/usr.bin/xlint/lint1/err.c:1.243
--- src/usr.bin/xlint/lint1/err.c:1.242	Thu May  9 20:53:13 2024
+++ src/usr.bin/xlint/lint1/err.c	Sat May 11 15:53:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.242 2024/05/09 20:53:13 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.243 2024/05/11 15:53:38 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.242 2024/05/09 20:53:13 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.243 2024/05/11 15:53:38 rillig Exp $");
 #endif
 
 #include 
@@ -434,6 +434,7 @@ static const char *const msgs[] = {
 	"'%.*s' overlaps earlier '%.*s' on bit %u",			// 376
 	"redundant '\\0' at the end of the format",			// 377
 	"conversion '%.*s' is unreachable by input value",		// 378
+	"comparing integer '%s' to floating point constant %Lg",	// 379
 };
 
 static bool is_suppressed[sizeof(msgs) / sizeof(msgs[0])];

Index: src/usr.bin/xlint/lint1/makeman
diff -u src/usr.bin/xlint/lint1/makeman:1.9 src/usr.bin/xlint/lint1/makeman:1.10
--- src/usr.bin/xlint/lint1/makeman:1.9	Tue Feb  6 22:47:21 2024
+++ 

CVS commit: src

2024-05-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May 11 15:53:38 UTC 2024

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/xlint/lint1: msg_162.c t_usage.sh
src/usr.bin/xlint/lint1: err.c makeman tree.c
Added Files:
src/tests/usr.bin/xlint/lint1: msg_379.c

Log Message:
lint: warn when comparing an integer to a floating point constant


To generate a diff of this commit:
cvs rdiff -u -r1.1315 -r1.1316 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/msg_162.c
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/msg_379.c
cvs rdiff -u -r1.20 -r1.21 src/tests/usr.bin/xlint/lint1/t_usage.sh
cvs rdiff -u -r1.242 -r1.243 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/makeman
cvs rdiff -u -r1.641 -r1.642 src/usr.bin/xlint/lint1/tree.c

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



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

2024-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 10 21:43:40 UTC 2024

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

Log Message:
lint: clean up conversion from floating point constant


To generate a diff of this commit:
cvs rdiff -u -r1.640 -r1.641 src/usr.bin/xlint/lint1/tree.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.640 src/usr.bin/xlint/lint1/tree.c:1.641
--- src/usr.bin/xlint/lint1/tree.c:1.640	Fri May  3 04:04:18 2024
+++ src/usr.bin/xlint/lint1/tree.c	Fri May 10 21:43:40 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.640 2024/05/03 04:04:18 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.641 2024/05/10 21:43:40 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.640 2024/05/03 04:04:18 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.641 2024/05/10 21:43:40 rillig Exp $");
 #endif
 
 #include 
@@ -3680,8 +3680,8 @@ convert(op_t op, int arg, type_t *tp, tn
 }
 
 static void
-convert_constant_floating(op_t op, int arg, tspec_t ot, const type_t *tp,
-			  tspec_t nt, val_t *v, val_t *nv)
+convert_constant_from_floating(op_t op, int arg, const type_t *ntp,
+			   tspec_t nt, val_t *nv, val_t *ov)
 {
 	long double max = 0.0, min = 0.0;
 
@@ -3715,36 +3715,34 @@ convert_constant_floating(op_t op, int a
 	case DOUBLE:
 	case DCOMPLEX:
 		max = DBL_MAX;		min = -DBL_MAX;		break;
-	case PTR:
-		/* Already got an error because of float --> ptr */
 	case LDOUBLE:
 	case LCOMPLEX:
-		/* LINTED 248 */
+		/* LINTED 248; see floating_error_value. */
 		max = LDBL_MAX;		min = -max;		break;
 	default:
 		lint_assert(/*CONSTCOND*/false);
 	}
-	if (v->u.floating > max || v->u.floating < min) {
+	if (ov->u.floating > max || ov->u.floating < min) {
 		lint_assert(nt != LDOUBLE);
-		if (op == FARG) {
+		const char *ot_name = type_name(gettyp(ov->v_tspec));
+		const char *nt_name = type_name(ntp);
+		if (op == FARG)
 			/* conversion of '%s' to '%s' is out of range, ... */
-			warning(295,
-			type_name(gettyp(ot)), type_name(tp), arg);
-		} else {
+			warning(295, ot_name, nt_name, arg);
+		else
 			/* conversion of '%s' to '%s' is out of range */
-			warning(119, type_name(gettyp(ot)), type_name(tp));
-		}
-		v->u.floating = v->u.floating > 0 ? max : min;
+			warning(119, ot_name, nt_name);
+		ov->u.floating = ov->u.floating > 0 ? max : min;
 	}
 
 	if (nt == FLOAT || nt == FCOMPLEX)
-		nv->u.floating = (float)v->u.floating;
+		nv->u.floating = (float)ov->u.floating;
 	else if (nt == DOUBLE || nt == DCOMPLEX)
-		nv->u.floating = (double)v->u.floating;
+		nv->u.floating = (double)ov->u.floating;
 	else if (nt == LDOUBLE || nt == LCOMPLEX)
-		nv->u.floating = v->u.floating;
+		nv->u.floating = ov->u.floating;
 	else
-		nv->u.integer = (int64_t)v->u.floating;
+		nv->u.integer = (int64_t)ov->u.floating;
 }
 
 static bool
@@ -3925,7 +3923,7 @@ convert_constant(op_t op, int arg, const
 	}
 
 	if (ot == FLOAT || ot == DOUBLE || ot == LDOUBLE)
-		convert_constant_floating(op, arg, ot, ntp, nt, ov, nv);
+		convert_constant_from_floating(op, arg, ntp, nt, nv, ov);
 	else if (!convert_constant_to_floating(nt, nv, ot, ov)) {
 		range_check = true;	/* Check for lost precision. */
 		nv->u.integer = ov->u.integer;



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

2024-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 10 21:43:40 UTC 2024

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

Log Message:
lint: clean up conversion from floating point constant


To generate a diff of this commit:
cvs rdiff -u -r1.640 -r1.641 src/usr.bin/xlint/lint1/tree.c

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



CVS commit: src/sys/sys

2024-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 10 09:30:47 UTC 2024

Modified Files:
src/sys/sys: ktrace.h

Log Message:
sys/ktrace.h: fix off-by-one error in snprintb for ktrace flags


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/sys/ktrace.h

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

Modified files:

Index: src/sys/sys/ktrace.h
diff -u src/sys/sys/ktrace.h:1.68 src/sys/sys/ktrace.h:1.69
--- src/sys/sys/ktrace.h:1.68	Wed Jun 29 22:10:43 2022
+++ src/sys/sys/ktrace.h	Fri May 10 09:30:47 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: ktrace.h,v 1.68 2022/06/29 22:10:43 riastradh Exp $	*/
+/*	$NetBSD: ktrace.h,v 1.69 2024/05/10 09:30:47 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -265,9 +265,9 @@ struct ktr_execfd {
 "b\16MIB\0" \
 "b\17EXEC_FD\0" \
 "f\30\4VERSION\0" \
-"b\36TRC_EMUL\0" \
-"b\37INHERIT\0" \
-"b\40PERSISTENT\0"
+"b\35TRC_EMUL\0" \
+"b\36INHERIT\0" \
+"b\37PERSISTENT\0"
 
 /*
  * trace flags (also in p_traceflags)



CVS commit: src/sys/sys

2024-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 10 09:30:47 UTC 2024

Modified Files:
src/sys/sys: ktrace.h

Log Message:
sys/ktrace.h: fix off-by-one error in snprintb for ktrace flags


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/sys/ktrace.h

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



CVS commit: src/usr.bin/error

2024-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 10 09:27:27 UTC 2024

Modified Files:
src/usr.bin/error: Makefile

Log Message:
error: disable lint's strict bool mode when building with Clang

The Clang preprocessor does not mark sections from system headers.
Lint's strict bool mode relies on these markers to allow the functions
from  to be used as 'bool', even though their declared return
type is 'int'. Without these markers, lint complains that the "right
operand of '&&' must be bool, not 'int'". Until this is fixed in lint,
disable strict bool mode.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/error/Makefile

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

Modified files:

Index: src/usr.bin/error/Makefile
diff -u src/usr.bin/error/Makefile:1.11 src/usr.bin/error/Makefile:1.12
--- src/usr.bin/error/Makefile:1.11	Sat Aug 26 14:50:53 2023
+++ src/usr.bin/error/Makefile	Fri May 10 09:27:27 2024
@@ -1,5 +1,5 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-#	$NetBSD: Makefile,v 1.11 2023/08/26 14:50:53 rillig Exp $
+#	$NetBSD: Makefile,v 1.12 2024/05/10 09:27:27 rillig Exp $
 
 PROG=	error
 SRCS=	main.c input.c pi.c subr.c filter.c touch.c
@@ -8,6 +8,6 @@ DPADD+=	${LIBUTIL}
 LDADD+=	-lutil
 
 LINTFLAGS+=	-w		# treat warnings as errors
-LINTFLAGS+=	-T		# strict bool mode
+LINTFLAGS+=	${HAVE_LLVM:U-T:D}	# strict bool mode
 
 .include 



CVS commit: src/usr.bin/error

2024-05-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May 10 09:27:27 UTC 2024

Modified Files:
src/usr.bin/error: Makefile

Log Message:
error: disable lint's strict bool mode when building with Clang

The Clang preprocessor does not mark sections from system headers.
Lint's strict bool mode relies on these markers to allow the functions
from  to be used as 'bool', even though their declared return
type is 'int'. Without these markers, lint complains that the "right
operand of '&&' must be bool, not 'int'". Until this is fixed in lint,
disable strict bool mode.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/error/Makefile

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



CVS commit: src

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:56:41 UTC 2024

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

Log Message:
lint: in C23 mode, allow storage classes in compound literals


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.498 -r1.499 src/usr.bin/xlint/lint1/cgram.y

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



CVS commit: src

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:56:41 UTC 2024

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

Log Message:
lint: in C23 mode, allow storage classes in compound literals


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.498 -r1.499 src/usr.bin/xlint/lint1/cgram.y

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.11 src/tests/usr.bin/xlint/lint1/c23.c:1.12
--- src/tests/usr.bin/xlint/lint1/c23.c:1.11	Thu May  9 11:08:07 2024
+++ src/tests/usr.bin/xlint/lint1/c23.c	Thu May  9 20:56:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c23.c,v 1.11 2024/05/09 11:08:07 rillig Exp $	*/
+/*	$NetBSD: c23.c,v 1.12 2024/05/09 20:56:41 rillig Exp $	*/
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
@@ -42,6 +42,29 @@ null_pointer_constant(const char *p, dou
 }
 
 
+void *
+storage_class_in_compound_literal(void)
+{
+	typedef struct node node;
+	struct node {
+		node *left;
+		int value;
+		node *right;
+	};
+
+	node *tree;
+	tree = &(static node){
+	&(static node){
+		nullptr,
+		3,
+		nullptr,
+	},
+	5,
+	nullptr,
+	};
+	return tree->left;
+}
+
 int
 empty_initializer_braces(void)
 {

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.498 src/usr.bin/xlint/lint1/cgram.y:1.499
--- src/usr.bin/xlint/lint1/cgram.y:1.498	Thu May  9 20:22:20 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu May  9 20:56:41 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.498 2024/05/09 20:22:20 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.499 2024/05/09 20:56:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.498 2024/05/09 20:22:20 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.499 2024/05/09 20:56:41 rillig Exp $");
 #endif
 
 #include 
@@ -306,6 +306,7 @@ is_either(const char *s, const char *a, 
 %type		gcc_statement_expr_item
 %type			point_or_arrow
 %type		argument_expression_list
+%type			storage_class_specifiers
 %type		unary_expression
 %type		cast_expression
 %type		expression_opt
@@ -332,6 +333,7 @@ is_either(const char *s, const char *a, 
 /* No type for type_init_declarator_list. */
 /* No type for notype_init_declarator. */
 /* No type for type_init_declarator. */
+%type			storage_class_specifier
 %type		type_specifier
 %type		notype_type_specifier
 %type		struct_or_union_specifier
@@ -606,6 +608,19 @@ postfix_expression:
 		$$ = build_name(current_initsym(), false);
 		end_initialization();
 	}
+	/* Rule 'compound_literal' with storage classes from C23 6.5.3.6. */
+|	T_LPAREN storage_class_specifiers type_name T_RPAREN {
+		sym_t *tmp = mktempsym($3);
+		tmp->s_scl = $2;
+		begin_initialization(tmp);
+		cgram_declare(tmp, true, NULL);
+	} braced_initializer {
+		if (!allow_c99)
+			 /* compound literals are a C99/GCC extension */
+			 gnuism(319);
+		$$ = build_name(current_initsym(), false);
+		end_initialization();
+	}
 |	T_LPAREN compound_statement_lbrace {
 		begin_statement_expr();
 	} gcc_statement_expr_list {
@@ -682,7 +697,14 @@ argument_expression_list:
 /* C23 6.5.3.6 */
 /* The rule 'compound_literal' is inlined into 'postfix_expression'. */
 
-/* TODO: Implement 'storage_class_specifiers' from C23 6.5.3.6. */
+/* C23 6.5.3.6 */
+storage_class_specifiers:
+	storage_class_specifier
+|	storage_class_specifiers storage_class_specifier {
+		// TODO C23: maybe merge multiple storage class specifiers
+		$$ = $1;
+	}
+;
 
 /* K 7.2, C90 ???, C99 6.5.3, C11 6.5.3, C23 6.5.4 */
 unary_expression:
@@ -1048,7 +1070,10 @@ type_init_declarator:
 
 /* TODO: Implement 'attribute_declaration' from C23 6.7.1. */
 
-/* TODO: Implement 'storage_class_specifier' from C23 6.7.2. */
+/* K ???, C90 ???, C99 ???, C11 ???, C23 6.7.2 */
+storage_class_specifier:
+	T_SCLASS
+;
 
 /* C99 6.7.2, C23 6.7.3.1 */
 type_specifier:



CVS commit: src

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:53:13 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c msg_174.c
src/usr.bin/xlint/lint1: err.c init.c

Log Message:
lint: add details to message about too many initializers


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_174.c
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.268 -r1.269 src/usr.bin/xlint/lint1/init.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_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.48 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.49
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.48	Sat Mar 30 16:47:45 2024
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Thu May  9 20:53:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_init.c,v 1.48 2024/03/30 16:47:45 rillig Exp $	*/
+/*	$NetBSD: d_c99_init.c,v 1.49 2024/05/09 20:53:13 rillig Exp $	*/
 # 3 "d_c99_init.c"
 
 /*
@@ -23,7 +23,7 @@ typedef struct any {
 int scalar_without_braces = 3;
 int scalar_with_optional_braces = { 3 };
 int scalar_with_too_many_braces = {{ 3 }};
-/* expect+1: error: too many initializers [174] */
+/* expect+1: error: too many initializers for 'int' [174] */
 int scalar_with_too_many_initializers = { 3, 5 };
 
 

Index: src/tests/usr.bin/xlint/lint1/msg_174.c
diff -u src/tests/usr.bin/xlint/lint1/msg_174.c:1.6 src/tests/usr.bin/xlint/lint1/msg_174.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_174.c:1.6	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_174.c	Thu May  9 20:53:13 2024
@@ -1,7 +1,7 @@
-/*	$NetBSD: msg_174.c,v 1.6 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_174.c,v 1.7 2024/05/09 20:53:13 rillig Exp $	*/
 # 3 "msg_174.c"
 
-// Test for message: too many initializers [174]
+// Test for message: too many initializers for '%s' [174]
 
 /* lint1-extra-flags: -X 351 */
 
@@ -11,7 +11,7 @@ example(void)
 	/* A single pair of braces is always allowed. */
 	int n = { 13 };
 
-	/* expect+1: error: too many initializers [174] */
+	/* expect+1: error: too many initializers for 'int' [174] */
 	int too_many = { 17, 19 };
 
 	/*

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.241 src/usr.bin/xlint/lint1/err.c:1.242
--- src/usr.bin/xlint/lint1/err.c:1.241	Sat Apr 27 10:08:54 2024
+++ src/usr.bin/xlint/lint1/err.c	Thu May  9 20:53:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.241 2024/04/27 10:08:54 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.242 2024/05/09 20:53:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.241 2024/04/27 10:08:54 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.242 2024/05/09 20:53:13 rillig Exp $");
 #endif
 
 #include 
@@ -229,7 +229,7 @@ static const char *const msgs[] = {
 	"cannot assign to '%s' from '%s'",// 171
 	"too many struct/union initializers",// 172
 	"too many array initializers, expected %d",			// 173
-	"too many initializers",	// 174
+	"too many initializers for '%s'",// 174
 	"initialization of incomplete type '%s'",			// 175
 	"",			/* no longer used */			// 176
 	"non-constant initializer",	// 177

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.268 src/usr.bin/xlint/lint1/init.c:1.269
--- src/usr.bin/xlint/lint1/init.c:1.268	Sat Mar 30 17:12:26 2024
+++ src/usr.bin/xlint/lint1/init.c	Thu May  9 20:53:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.268 2024/03/30 17:12:26 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.269 2024/05/09 20:53:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.268 2024/03/30 17:12:26 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.269 2024/05/09 20:53:13 rillig Exp $");
 #endif
 
 #include 
@@ -530,8 +530,8 @@ warn_too_many_initializers(designator_ki
 		/* too many array initializers, expected %d */
 		error(173, tp->u.dimension);
 	} else
-		/* too many initializers */
-		error(174);
+		/* too many initializers for '%s' */
+		error(174, type_name(tp));
 }
 
 static bool



CVS commit: src

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:53:13 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c msg_174.c
src/usr.bin/xlint/lint1: err.c init.c

Log Message:
lint: add details to message about too many initializers


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_174.c
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.268 -r1.269 src/usr.bin/xlint/lint1/init.c

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



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

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:22:20 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: sync grammar rule names with C11 and C23


To generate a diff of this commit:
cvs rdiff -u -r1.497 -r1.498 src/usr.bin/xlint/lint1/cgram.y

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



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

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:22:20 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: sync grammar rule names with C11 and C23


To generate a diff of this commit:
cvs rdiff -u -r1.497 -r1.498 src/usr.bin/xlint/lint1/cgram.y

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.497 src/usr.bin/xlint/lint1/cgram.y:1.498
--- src/usr.bin/xlint/lint1/cgram.y:1.497	Thu May  9 20:15:05 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu May  9 20:22:20 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.497 2024/05/09 20:15:05 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.498 2024/05/09 20:22:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.497 2024/05/09 20:15:05 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.498 2024/05/09 20:22:20 rillig Exp $");
 #endif
 
 #include 
@@ -328,8 +328,8 @@ is_either(const char *s, const char *a, 
 /* No type for type_attribute. */
 /* No type for begin_type. */
 /* No type for end_type. */
-/* No type for notype_init_declarators. */
-/* No type for type_init_declarators. */
+/* No type for notype_init_declarator_list. */
+/* No type for type_init_declarator_list. */
 /* No type for notype_init_declarator. */
 /* No type for type_init_declarator. */
 %type		type_specifier
@@ -340,8 +340,8 @@ is_either(const char *s, const char *a, 
 %type			member_declaration_list_with_rbrace
 %type			member_declaration_list
 %type			member_declaration
-%type			notype_member_declarators
-%type			type_member_declarators
+%type			notype_member_declarator_list
+%type			type_member_declarator_list
 %type			notype_member_declarator
 %type			type_member_declarator
 %type		enum_specifier
@@ -852,7 +852,7 @@ declaration:
 			/* empty declaration */
 			warning(2);
 	}
-|	begin_type_declmods end_type notype_init_declarators T_SEMI {
+|	begin_type_declmods end_type notype_init_declarator_list T_SEMI {
 		if (dcs->d_scl == TYPEDEF)
 			/* syntax error '%s' */
 			error(249, "missing base type for typedef");
@@ -869,7 +869,7 @@ declaration:
 			warning(2);
 	}
 |	begin_type_declaration_specifiers end_type
-	type_init_declarators T_SEMI
+	type_init_declarator_list T_SEMI
 |	static_assert_declaration
 ;
 
@@ -1004,14 +1004,14 @@ end_type:
 /* C23 6.7.1 */
 /* The rule 'init_declarator_list' is split into the 'notype' and 'type' variants. */
 
-notype_init_declarators:
+notype_init_declarator_list:
 	notype_init_declarator
-|	notype_init_declarators T_COMMA type_init_declarator
+|	notype_init_declarator_list T_COMMA type_init_declarator
 ;
 
-type_init_declarators:
+type_init_declarator_list:
 	type_init_declarator
-|	type_init_declarators T_COMMA type_init_declarator
+|	type_init_declarator_list T_COMMA type_init_declarator
 ;
 
 /* C23 6.7.1 */
@@ -1149,13 +1149,13 @@ member_declaration:
 		/* ^^ There is no check for the missing type-specifier. */
 		/* too late, i know, but getsym() compensates it */
 		set_sym_kind(SK_MEMBER);
-	} notype_member_declarators T_SEMI {
+	} notype_member_declarator_list T_SEMI {
 		set_sym_kind(SK_VCFT);
 		$$ = $4;
 	}
 |	begin_type_specifier_qualifier_list end_type {
 		set_sym_kind(SK_MEMBER);
-	} type_member_declarators T_SEMI {
+	} type_member_declarator_list T_SEMI {
 		set_sym_kind(SK_VCFT);
 		$$ = $4;
 	}
@@ -1194,24 +1194,24 @@ member_declaration:
 /* C23 6.7.3.2 */
 /* The rule 'member_declarator_list' is split into the 'type' and 'notype' variants. */
 
-/* Was named struct_declarators until C11. */
-notype_member_declarators:
+/* Was named struct_declarator_list until C11. */
+notype_member_declarator_list:
 	notype_member_declarator {
 		$$ = declare_member($1);
 	}
-|	notype_member_declarators {
+|	notype_member_declarator_list {
 		set_sym_kind(SK_MEMBER);
 	} T_COMMA type_member_declarator {
 		$$ = concat_symbols($1, declare_member($4));
 	}
 ;
 
-/* Was named struct_declarators until C11. */
-type_member_declarators:
+/* Was named struct_declarator_list until C11. */
+type_member_declarator_list:
 	type_member_declarator {
 		$$ = declare_member($1);
 	}
-|	type_member_declarators {
+|	type_member_declarator_list {
 		set_sym_kind(SK_MEMBER);
 	} T_COMMA type_member_declarator {
 		$$ = concat_symbols($1, declare_member($4));
@@ -2098,7 +2098,7 @@ for_start:			/* see C99 6.8.5 */
 for_exprs:			/* see C99 6.8.5 */
 	for_start
 	begin_type_declaration_specifiers end_type
-	notype_init_declarators T_SEMI
+	notype_init_declarator_list T_SEMI
 	expression_opt T_SEMI
 	expression_opt T_RPAREN {
 		/* variable declaration in for loop */
@@ -2200,7 +2200,7 @@ external_declaration:
  * See 'declaration' for all other declarations.
  */
 top_level_declaration:		/* C99 6.9 calls this 

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

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:15:05 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: sort grammar rules according to the order they appear in C23


To generate a diff of this commit:
cvs rdiff -u -r1.496 -r1.497 src/usr.bin/xlint/lint1/cgram.y

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



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

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 20:15:05 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: sort grammar rules according to the order they appear in C23


To generate a diff of this commit:
cvs rdiff -u -r1.496 -r1.497 src/usr.bin/xlint/lint1/cgram.y

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.496 src/usr.bin/xlint/lint1/cgram.y:1.497
--- src/usr.bin/xlint/lint1/cgram.y:1.496	Thu May  9 11:08:07 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu May  9 20:15:05 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.496 2024/05/09 11:08:07 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.497 2024/05/09 20:15:05 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.496 2024/05/09 11:08:07 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.497 2024/05/09 20:15:05 rillig Exp $");
 #endif
 
 #include 
@@ -328,9 +328,12 @@ is_either(const char *s, const char *a, 
 /* No type for type_attribute. */
 /* No type for begin_type. */
 /* No type for end_type. */
+/* No type for notype_init_declarators. */
+/* No type for type_init_declarators. */
+/* No type for notype_init_declarator. */
+/* No type for type_init_declarator. */
 %type		type_specifier
 %type		notype_type_specifier
-%type		atomic_type_specifier
 %type		struct_or_union_specifier
 %type		struct_or_union
 %type			braced_member_declaration_list
@@ -347,19 +350,17 @@ is_either(const char *s, const char *a, 
 %type			enums_with_opt_comma
 %type			enumerator_list
 %type			enumerator
-%type		type_qualifier
+%type		atomic_type_specifier
 /* No type for atomic. */
-%type		pointer
-%type		type_qualifier_list_opt
-%type		type_qualifier_list
-/* No type for notype_init_declarators. */
-/* No type for type_init_declarators. */
-/* No type for notype_init_declarator. */
-/* No type for type_init_declarator. */
+%type		type_qualifier
 %type			notype_declarator
 %type			type_declarator
 %type			notype_direct_declarator
 %type			type_direct_declarator
+%type		pointer
+%type		type_qualifier_list_opt
+%type		type_qualifier_list
+%type			parameter_declaration
 %type			type_param_declarator
 %type			notype_param_declarator
 %type			direct_param_declarator
@@ -369,13 +370,12 @@ is_either(const char *s, const char *a, 
 %type			identifier_list
 %type		type_name
 %type			abstract_declaration
-%type			abstract_declarator
-%type			direct_abstract_declarator
 %type		abstract_decl_param_list
 /* No type for abstract_decl_lparen. */
 %type		vararg_parameter_type_list
 %type		parameter_type_list
-%type			parameter_declaration
+%type			abstract_declarator
+%type			direct_abstract_declarator
 /* No type for braced_initializer. */
 /* No type for initializer. */
 /* No type for initializer_list. */
@@ -391,8 +391,8 @@ is_either(const char *s, const char *a, 
 /* No type for no_attr_statement. */
 /* No type for non_expr_statement. */
 /* No type for no_attr_non_expr_statement. */
-/* No type for labeled_statement. */
 /* No type for label. */
+/* No type for labeled_statement. */
 /* No type for compound_statement. */
 /* No type for compound_statement_lbrace. */
 /* No type for compound_statement_rbrace. */
@@ -472,7 +472,7 @@ string:
 	}
 ;
 
-/* K 7.1, C90 ???, C99 6.5.1, C11 6.5.1 */
+/* K 7.1, C90 ???, C99 6.5.1, C11 6.5.1, C23 6.5.2 */
 primary_expression:
 	T_NAME {
 		bool sys_name, sys_next;
@@ -541,7 +541,7 @@ member_designator:
 	}
 ;
 
-/* K ---, C90 ---, C99 ---, C11 6.5.1.1 */
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C23 6.5.2.1 */
 generic_selection:
 	T_GENERIC T_LPAREN assignment_expression T_COMMA
 	generic_assoc_list T_RPAREN {
@@ -551,7 +551,7 @@ generic_selection:
 	}
 ;
 
-/* K ---, C90 ---, C99 ---, C11 6.5.1.1 */
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C23 6.5.2.1 */
 generic_assoc_list:
 	generic_association
 |	generic_assoc_list T_COMMA generic_association {
@@ -560,7 +560,7 @@ generic_assoc_list:
 	}
 ;
 
-/* K ---, C90 ---, C99 ---, C11 6.5.1.1 */
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C23 6.5.2.1 */
 generic_association:
 	type_name T_COLON assignment_expression {
 		$$ = block_zero_alloc(sizeof(*$$), "generic");
@@ -574,7 +574,7 @@ generic_association:
 	}
 ;
 
-/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C23 6.5.2 */
+/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C23 6.5.3.1 */
 postfix_expression:
 	primary_expression
 |	postfix_expression T_LBRACK sys expression T_RBRACK {
@@ -594,7 +594,8 @@ postfix_expression:
 |	postfix_expression T_INCDEC sys {
 		$$ = build_unary($2 ? INCAFT : DECAFT, $3, $1);
 	}
-|	T_LPAREN type_name T_RPAREN {	/* C99 6.5.2.5 "Compound literals" */
+	/* Rule 'compound_literal' from C99 6.5.2.5. */
+|	T_LPAREN type_name T_RPAREN {
 		sym_t *tmp = mktempsym($2);
 		begin_initialization(tmp);
 		

CVS commit: src

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 11:08:07 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c
src/usr.bin/xlint/lint1: cgram.y debug.c externs1.h lex.c lint1.h

Log Message:
lint: in C23 mode, support the nullptr constant


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.495 -r1.496 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/externs1.h \
src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/lint1.h

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.10 src/tests/usr.bin/xlint/lint1/c23.c:1.11
--- src/tests/usr.bin/xlint/lint1/c23.c:1.10	Tue May  7 21:13:27 2024
+++ src/tests/usr.bin/xlint/lint1/c23.c	Thu May  9 11:08:07 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c23.c,v 1.10 2024/05/07 21:13:27 rillig Exp $	*/
+/*	$NetBSD: c23.c,v 1.11 2024/05/09 11:08:07 rillig Exp $	*/
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
@@ -28,6 +28,20 @@ c99_bool_is_still_valid_in_c23(void)
 }
 
 
+bool
+null_pointer_constant(const char *p, double dbl)
+{
+	/* expect+1: error: operands of '!=' have incompatible types 'double' and 'pointer to void' [107] */
+	if (dbl != nullptr)
+		p++;
+	if (dbl > 0.0)
+		p++;
+	if (*p == '\0')
+		p = nullptr;
+	return p == nullptr;
+}
+
+
 int
 empty_initializer_braces(void)
 {

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.495 src/usr.bin/xlint/lint1/cgram.y:1.496
--- src/usr.bin/xlint/lint1/cgram.y:1.495	Fri May  3 04:04:17 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu May  9 11:08:07 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.495 2024/05/03 04:04:17 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.496 2024/05/09 11:08:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.495 2024/05/03 04:04:17 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.496 2024/05/09 11:08:07 rillig Exp $");
 #endif
 
 #include 
@@ -140,6 +140,7 @@ is_either(const char *s, const char *a, 
 	array_size y_array_size;
 	bool	y_in_system_header;
 	designation y_designation;
+	named_constant y_named_constant;
 };
 
 /* for Bison:
@@ -199,6 +200,7 @@ is_either(const char *s, const char *a, 
 			fprintf(yyo, "");
 	}
 } 
+%printer { fprintf(yyo, "%s", named_constant_name($$)); } 
 */
 
 %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
@@ -287,6 +289,7 @@ is_either(const char *s, const char *a, 
 %token		T_NAME
 %token		T_TYPENAME
 %token			T_CON
+%token	 T_NAMED_CONSTANT
 %token		T_STRING
 
 /* No type for program. */
@@ -484,6 +487,25 @@ primary_expression:
 |	T_CON {
 		$$ = build_constant(gettyp($1->v_tspec), $1);
 	}
+|	T_NAMED_CONSTANT {
+		if ($1 == NC_NULLPTR) {
+			tnode_t *zero = expr_alloc_tnode();
+			zero->tn_op = CON;
+			zero->tn_type = gettyp(INT);
+			zero->u.value.v_tspec = INT;
+
+			type_t *void_ptr = block_derive_type(gettyp(VOID), PTR);
+			$$ = convert(CVT, 0, void_ptr, zero);
+			$$->tn_sys = zero->tn_sys;
+		} else {
+			tnode_t *nc = expr_alloc_tnode();
+			nc->tn_op = CON;
+			nc->tn_type = gettyp(BOOL);
+			nc->u.value.v_tspec = BOOL;
+			nc->u.value.u.integer = $1 == NC_TRUE ? 1 : 0;
+			$$ = nc;
+		}
+	}
 |	string {
 		$$ = build_string($1);
 	}

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.77 src/usr.bin/xlint/lint1/debug.c:1.78
--- src/usr.bin/xlint/lint1/debug.c:1.77	Fri May  3 04:04:17 2024
+++ src/usr.bin/xlint/lint1/debug.c	Thu May  9 11:08:07 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.77 2024/05/03 04:04:17 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.78 2024/05/09 11:08:07 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.77 2024/05/03 04:04:17 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.78 2024/05/09 11:08:07 rillig Exp $");
 #endif
 
 #include 
@@ -361,6 +361,18 @@ function_specifier_name(function_specifi
 	return name[spec];
 }
 
+const char *
+named_constant_name(named_constant nc)
+{
+	static const char *const name[] = {
+	"false",
+	"true",
+	"nullptr",
+	};
+
+	return name[nc];
+}
+
 static void
 debug_word(bool flag, const char *name)
 {

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.224 src/usr.bin/xlint/lint1/externs1.h:1.225
--- src/usr.bin/xlint/lint1/externs1.h:1.224	Fri May  3 04:04:18 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Thu May  9 11:08:07 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.224 2024/05/03 04:04:18 rillig Exp $	*/
+/*	

CVS commit: src

2024-05-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  9 11:08:07 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c
src/usr.bin/xlint/lint1: cgram.y debug.c externs1.h lex.c lint1.h

Log Message:
lint: in C23 mode, support the nullptr constant


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.495 -r1.496 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/externs1.h \
src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.225 -r1.226 src/usr.bin/xlint/lint1/lint1.h

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



CVS commit: src

2024-05-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May  7 21:13:27 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c
src/usr.bin/xlint/lint1: lex.c lint1.h
src/usr.bin/xlint/xlint: strict-bool-stdbool.h

Log Message:
lint: in C23 mode, support the keywords 'bool', 'false' and 'true'


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.223 -r1.224 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/xlint/strict-bool-stdbool.h

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.9 src/tests/usr.bin/xlint/lint1/c23.c:1.10
--- src/tests/usr.bin/xlint/lint1/c23.c:1.9	Tue May  7 19:32:35 2024
+++ src/tests/usr.bin/xlint/lint1/c23.c	Tue May  7 21:13:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c23.c,v 1.9 2024/05/07 19:32:35 rillig Exp $	*/
+/*	$NetBSD: c23.c,v 1.10 2024/05/07 21:13:27 rillig Exp $	*/
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
@@ -14,13 +14,8 @@
 int
 bool_is_predefined_in_c23(void)
 {
-	/* expect+1: error: syntax error 't' [249] */
 	bool t = true;
 	bool f = false;
-	/* expect+4: error: 't' undefined [99] */
-	/* expect+3: error: 'true' undefined [99] */
-	/* expect+2: error: 'f' undefined [99] */
-	/* expect+1: error: 'false' undefined [99] */
 	return (t == true ? 20 : 0) + (f == false ? 3 : 0);
 }
 

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.223 src/usr.bin/xlint/lint1/lex.c:1.224
--- src/usr.bin/xlint/lint1/lex.c:1.223	Fri Mar 29 08:35:32 2024
+++ src/usr.bin/xlint/lint1/lex.c	Tue May  7 21:13:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.223 2024/03/29 08:35:32 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.224 2024/05/07 21:13:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.223 2024/03/29 08:35:32 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.224 2024/05/07 21:13:26 rillig Exp $");
 #endif
 
 #include 
@@ -68,6 +68,8 @@ bool in_gcc_attribute;
 bool in_system_header;
 
 /*
+ * Define a keyword that cannot be overridden by identifiers.
+ *
  * Valid values for 'since' are 78, 90, 99, 11, 23.
  *
  * The C11 keywords are all taken from the reserved namespace.  They are added
@@ -95,6 +97,8 @@ bool in_system_header;
 	kwdef(name, T_TYPE, .u.kw_tspec = (tspec), since, 0, 1)
 #define kwdef_tqual(name, tqual,		since, gcc, deco) \
 	kwdef(name, T_QUAL, .u.kw_tqual = {.tqual = true}, since, gcc, deco)
+#define kwdef_const(name, constant,		since, gcc, deco) \
+	kwdef(name, T_CON, .u.kw_const = (constant), since, gcc, deco)
 #define kwdef_keyword(name, token) \
 	kwdef(name, token, {false},		78, 0, 1)
 
@@ -110,6 +114,7 @@ static const struct keyword {
 		type_qualifiers kw_tqual;	/* if kw_token is T_QUAL */
 		function_specifier kw_fs;	/* if kw_token is
 		 * T_FUNCTION_SPECIFIER */
+		named_constant kw_const;	/* if kw_token is T_CON */
 	} u;
 	bool	kw_added_in_c90:1;
 	bool	kw_added_in_c99_or_c11:1;
@@ -130,6 +135,7 @@ static const struct keyword {
 	kwdef_token(	"attribute",	T_ATTRIBUTE,		78,1,6),
 	kwdef_sclass(	"auto",		AUTO,			78,0,1),
 	kwdef_type(	"_Bool",	BOOL,			99),
+	kwdef_type(	"bool",		BOOL,			23),
 	kwdef_keyword(	"break",	T_BREAK),
 	kwdef_token(	"__builtin_offsetof", T_BUILTIN_OFFSETOF, 78,1,1),
 	kwdef_keyword(	"case",		T_CASE),
@@ -145,6 +151,7 @@ static const struct keyword {
 	kwdef_keyword(	"enum",		T_ENUM),
 	kwdef_token(	"__extension__",T_EXTENSION,		78,1,1),
 	kwdef_sclass(	"extern",	EXTERN,			78,0,1),
+	kwdef_const(	"false",	NC_FALSE,		23,0,1),
 	kwdef_type(	"float",	FLOAT,			78),
 	kwdef_keyword(	"for",		T_FOR),
 	kwdef_token(	"_Generic",	T_GENERIC,		11,0,1),
@@ -176,6 +183,7 @@ static const struct keyword {
 	kwdef_sclass(	"__thread",	THREAD_LOCAL,		78,1,1),
 	kwdef_sclass(	"_Thread_local", THREAD_LOCAL,		11,0,1),
 	kwdef_sclass(	"thread_local", THREAD_LOCAL,		23,0,1),
+	kwdef_const(	"true",		NC_TRUE,		23,0,1),
 	kwdef_sclass(	"typedef",	TYPEDEF,		78,0,1),
 	kwdef_token(	"typeof",	T_TYPEOF,		78,1,7),
 #ifdef INT128_SIZE
@@ -366,6 +374,8 @@ register_keyword(const struct keyword *k
 		sym->u.s_keyword.u.sk_type_qualifier = kw->u.kw_tqual;
 	if (tok == T_FUNCTION_SPECIFIER)
 		sym->u.s_keyword.u.function_specifier = kw->u.kw_fs;
+	if (tok == T_CON)
+		sym->u.s_keyword.u.constant = kw->u.kw_const;
 
 	symtab_add(sym);
 }
@@ -445,6 +455,12 @@ lex_keyword(sym_t *sym)
 	if (tok == T_FUNCTION_SPECIFIER)
 		yylval.y_function_specifier =
 		sym->u.s_keyword.u.function_specifier;
+	if (tok == T_CON) {
+		val_t *v = xcalloc(1, sizeof(*v));
+		v->v_tspec = BOOL;
+		v->u.integer = sym->u.s_keyword.u.constant == NC_TRUE ? 1 : 

CVS commit: src

2024-05-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May  7 21:13:27 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: c23.c
src/usr.bin/xlint/lint1: lex.c lint1.h
src/usr.bin/xlint/xlint: strict-bool-stdbool.h

Log Message:
lint: in C23 mode, support the keywords 'bool', 'false' and 'true'


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/c23.c
cvs rdiff -u -r1.223 -r1.224 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/xlint/strict-bool-stdbool.h

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-05-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May  7 19:32:35 UTC 2024

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

Log Message:
tests/lint: show that in C23 mode, bool is not yet defined

The tests in C11 and C23 mode look the same right now but will change
soon.

The warnings in the C11 test disappeared because after the first error,
warnings about unused variables are suppressed by check_variable_usage,
as they are often wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/c11.c
cvs rdiff -u -r1.8 -r1.9 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.6 src/tests/usr.bin/xlint/lint1/c11.c:1.7
--- src/tests/usr.bin/xlint/lint1/c11.c:1.6	Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/c11.c	Tue May  7 19:32:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c11.c,v 1.6 2024/01/28 08:17:27 rillig Exp $	*/
+/*	$NetBSD: c11.c,v 1.7 2024/05/07 19:32:35 rillig Exp $	*/
 # 3 "c11.c"
 
 /*
@@ -8,6 +8,29 @@
 
 /* lint1-flags: -Ac11 -w -X 192,231,236,351 */
 
+
+int
+bool_is_predefined_in_c23(void)
+{
+	/* expect+1: error: syntax error 't' [249] */
+	bool t = true;
+	bool f = false;
+	/* expect+4: error: 't' undefined [99] */
+	/* expect+3: error: 'true' undefined [99] */
+	/* expect+2: error: 'f' undefined [99] */
+	/* expect+1: error: 'false' undefined [99] */
+	return (t == true ? 20 : 0) + (f == false ? 3 : 0);
+}
+
+int
+c99_bool_is_still_valid_in_c23(void)
+{
+	_Bool t = 1;
+	_Bool f = 0;
+	return (t == 1 ? 20 : 0) + (f == 0 ? 3 : 0);
+}
+
+
 _Noreturn void exit(int);
 void _Noreturn exit(int);
 
@@ -73,11 +96,9 @@ void fcompat(void)
 	int (*p)[4][n+1];
 	int c[n][n][6][m];
 	int (*r)[n][n][n+1];
-	/* expect+2: 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] */
-	/* expect+1: 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: 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] */
-	/* expect+1: 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;
 }
 
@@ -101,8 +122,7 @@ void fvla(int m, int C[m][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] */
+	/* expect+1: warning: illegal combination of 'pointer to array[1] of int' and 'pointer to int', op 'init' [124] */
 	static int (*q)[m] = 
 }
 

Index: src/tests/usr.bin/xlint/lint1/c23.c
diff -u src/tests/usr.bin/xlint/lint1/c23.c:1.8 src/tests/usr.bin/xlint/lint1/c23.c:1.9
--- src/tests/usr.bin/xlint/lint1/c23.c:1.8	Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/c23.c	Tue May  7 19:32:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: c23.c,v 1.8 2024/01/28 08:17:27 rillig Exp $	*/
+/*	$NetBSD: c23.c,v 1.9 2024/05/07 19:32:35 rillig Exp $	*/
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
@@ -10,6 +10,29 @@
 
 /* lint1-flags: -Ac23 -w -X 351 */
 
+
+int
+bool_is_predefined_in_c23(void)
+{
+	/* expect+1: error: syntax error 't' [249] */
+	bool t = true;
+	bool f = false;
+	/* expect+4: error: 't' undefined [99] */
+	/* expect+3: error: 'true' undefined [99] */
+	/* expect+2: error: 'f' undefined [99] */
+	/* expect+1: error: 'false' undefined [99] */
+	return (t == true ? 20 : 0) + (f == false ? 3 : 0);
+}
+
+int
+c99_bool_is_still_valid_in_c23(void)
+{
+	_Bool t = 1;
+	_Bool f = 0;
+	return (t == 1 ? 20 : 0) + (f == 0 ? 3 : 0);
+}
+
+
 int
 empty_initializer_braces(void)
 {



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

2024-05-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May  7 19:32:35 UTC 2024

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

Log Message:
tests/lint: show that in C23 mode, bool is not yet defined

The tests in C11 and C23 mode look the same right now but will change
soon.

The warnings in the C11 test disappeared because after the first error,
warnings about unused variables are suppressed by check_variable_usage,
as they are often wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/c11.c
cvs rdiff -u -r1.8 -r1.9 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

2024-05-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May  4 06:52:17 UTC 2024

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

Log Message:
lint: increase debug logging for declarations

All changes to the global variable 'dcs' are tracked now, to help
identify the cause of the failing tests in expr_sizeof and
gcc_attribute_aligned.

While here, test more invalid type combinations in typedefs.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_004.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_005.c
cvs rdiff -u -r1.401 -r1.402 src/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

2024-05-04 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May  4 06:52:17 UTC 2024

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

Log Message:
lint: increase debug logging for declarations

All changes to the global variable 'dcs' are tracked now, to help
identify the cause of the failing tests in expr_sizeof and
gcc_attribute_aligned.

While here, test more invalid type combinations in typedefs.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_004.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_005.c
cvs rdiff -u -r1.401 -r1.402 src/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/msg_004.c
diff -u src/tests/usr.bin/xlint/lint1/msg_004.c:1.7 src/tests/usr.bin/xlint/lint1/msg_004.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_004.c:1.7	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/msg_004.c	Sat May  4 06:52:17 2024
@@ -1,7 +1,10 @@
-/*	$NetBSD: msg_004.c,v 1.7 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: msg_004.c,v 1.8 2024/05/04 06:52:17 rillig Exp $	*/
 # 3 "msg_004.c"
 
 // Test for message: illegal type combination [4]
+//
+// See also:
+//	msg_005.c
 
 /* lint1-extra-flags: -X 351 */
 

Index: src/tests/usr.bin/xlint/lint1/msg_005.c
diff -u src/tests/usr.bin/xlint/lint1/msg_005.c:1.5 src/tests/usr.bin/xlint/lint1/msg_005.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_005.c:1.5	Fri Jun 17 18:54:53 2022
+++ src/tests/usr.bin/xlint/lint1/msg_005.c	Sat May  4 06:52:17 2024
@@ -1,29 +1,146 @@
-/*	$NetBSD: msg_005.c,v 1.5 2022/06/17 18:54:53 rillig Exp $	*/
+/*	$NetBSD: msg_005.c,v 1.6 2024/05/04 06:52:17 rillig Exp $	*/
 # 3 "msg_005.c"
 
 // Test for message: modifying typedef with '%s'; only qualifiers allowed [5]
 
-typedef int number;
+typedef char char_alias;
+typedef signed char schar_alias;
+typedef unsigned char uchar_alias;
+typedef short short_alias;
+typedef unsigned short ushort_alias;
+typedef int int_alias;
+typedef unsigned int uint_alias;
+typedef long long_alias;
+typedef unsigned long ulong_alias;
+typedef long long llong_alias;
+typedef unsigned long long ullong_alias;
+typedef float float_alias;
+typedef double double_alias;
+typedef long double ldouble_alias;
+typedef float _Complex fcomplex_alias;
+typedef double _Complex dcomplex_alias;
+typedef long double _Complex lcomplex_alias;
 
 /* expect+1: warning: modifying typedef with 'signed'; only qualifiers allowed [5] */
-typedef number signed signed_number;
-
+typedef char_alias signed err_s_char;
+/* expect+1: warning: modifying typedef with 'unsigned'; only qualifiers allowed [5] */
+typedef char_alias unsigned err_u_char;
+/* expect+1: error: illegal type combination [4] */
+typedef schar_alias signed err_s_schar;
+/* expect+1: error: illegal type combination [4] */
+typedef schar_alias unsigned err_u_schar;
+/* expect+1: error: illegal type combination [4] */
+typedef uchar_alias signed err_s_uchar;
+/* expect+1: error: illegal type combination [4] */
+typedef uchar_alias unsigned err_u_uchar;
+/* expect+1: warning: modifying typedef with 'signed'; only qualifiers allowed [5] */
+typedef short_alias signed err_s_short;
+/* expect+1: warning: modifying typedef with 'unsigned'; only qualifiers allowed [5] */
+typedef short_alias unsigned err_u_short;
+/* expect+1: error: illegal type combination [4] */
+typedef ushort_alias signed err_s_ushort;
+/* expect+1: error: illegal type combination [4] */
+typedef ushort_alias unsigned err_u_ushort;
+/* expect+1: warning: modifying typedef with 'signed'; only qualifiers allowed [5] */
+typedef int_alias signed err_s_int;
+/* expect+1: warning: modifying typedef with 'unsigned'; only qualifiers allowed [5] */
+typedef int_alias unsigned err_u_int;
+/* expect+1: error: illegal type combination [4] */
+typedef uint_alias signed err_s_uint;
+/* expect+1: error: illegal type combination [4] */
+typedef uint_alias unsigned err_u_uint;
+/* expect+1: warning: modifying typedef with 'signed'; only qualifiers allowed [5] */
+typedef long_alias signed err_s_long;
+/* expect+1: warning: modifying typedef with 'unsigned'; only qualifiers allowed [5] */
+typedef long_alias unsigned err_u_long;
+/* expect+1: error: illegal type combination [4] */
+typedef ulong_alias signed err_s_ulong;
+/* expect+1: error: illegal type combination [4] */
+typedef ulong_alias unsigned err_u_ulong;
+/* expect+1: warning: modifying typedef with 'signed'; only qualifiers allowed [5] */
+typedef llong_alias signed err_s_llong;
 /* expect+1: warning: modifying typedef with 'unsigned'; only qualifiers allowed [5] */
-typedef number unsigned unsigned_number;
+typedef llong_alias unsigned err_u_llong;
+/* expect+1: error: illegal type combination [4] */
+typedef ullong_alias signed err_s_ullong;
+/* expect+1: error: illegal type combination 

CVS commit: src/lib/libc/stdio

2024-05-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May  4 05:50:49 UTC 2024

Modified Files:
src/lib/libc/stdio: mktemp.3

Log Message:
mktemp.3: mkdtemp is no longer nonstandard

Reported by Aleksey Cheusov on tech-userlevel.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/mktemp.3

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



CVS commit: src/lib/libc/stdio

2024-05-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat May  4 05:50:49 UTC 2024

Modified Files:
src/lib/libc/stdio: mktemp.3

Log Message:
mktemp.3: mkdtemp is no longer nonstandard

Reported by Aleksey Cheusov on tech-userlevel.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdio/mktemp.3

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

Modified files:

Index: src/lib/libc/stdio/mktemp.3
diff -u src/lib/libc/stdio/mktemp.3:1.32 src/lib/libc/stdio/mktemp.3:1.33
--- src/lib/libc/stdio/mktemp.3:1.32	Thu Oct 28 09:51:39 2021
+++ src/lib/libc/stdio/mktemp.3	Sat May  4 05:50:49 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mktemp.3,v 1.32 2021/10/28 09:51:39 kim Exp $
+.\"	$NetBSD: mktemp.3,v 1.33 2024/05/04 05:50:49 rillig Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)mktemp.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd July 25, 2021
+.Dd May 4, 2024
 .Dt MKTEMP 3
 .Os
 .Sh NAME
@@ -304,13 +304,12 @@ It was however removed from the specific
 revision.
 The
 .Fn mkstemp
-and
+function conforms to
+.St -p1003.1-2004 .
+The
 .Fn mkdtemp
-functions conform to
-.St -p1003.1-2004
-and
-.St -p1003.1-2008 ,
-respectively.
+function conforms to
+.St -p1003.1-2008 .
 .Sh HISTORY
 A
 .Fn mktemp
@@ -372,10 +371,6 @@ For this reason,
 .Xr ld 1
 will output a warning message whenever it links code that uses
 .Fn mktemp .
-.Pp
-The
-.Fn mkdtemp
-function is nonstandard and should not be used if portability is required.
 .Sh SECURITY CONSIDERATIONS
 The use of
 .Fn mktemp



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

2024-05-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  3 19:16:13 UTC 2024

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

Log Message:
tests/lint: fix supposedly platform-independent type definitions

No idea where I got the previous type definitions from.  The typedef
names looked just too convincing to actually check the underlying types.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.17 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.18
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.17	Fri May  3 15:32:37 2024
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c	Fri May  3 19:16:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_sizeof.c,v 1.17 2024/05/03 15:32:37 rillig Exp $	*/
+/*	$NetBSD: expr_sizeof.c,v 1.18 2024/05/03 19:16:13 rillig Exp $	*/
 # 3 "expr_sizeof.c"
 
 /*
@@ -7,8 +7,6 @@
  */
 
 /* lint1-extra-flags: -X 351 */
-// TODO: Remove the lp64 restriction when sequence_of_structs has been fixed.
-/* lint1-only-if: lp64 */
 
 /*
  * A sizeof expression can either take a type name or an expression.
@@ -221,9 +219,9 @@ void
 sequence_of_structs(void)
 {
 	typedef unsigned char uint8_t;
-	typedef short unsigned int uint16_t;
+	typedef unsigned short uint16_t;
 	typedef unsigned int uint32_t;
-	typedef long unsigned int uint64_t;
+	typedef unsigned long long uint64_t;
 
 	union fp_addr {
 		uint64_t fa_64;



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

2024-05-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  3 19:16:13 UTC 2024

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

Log Message:
tests/lint: fix supposedly platform-independent type definitions

No idea where I got the previous type definitions from.  The typedef
names looked just too convincing to actually check the underlying types.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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-05-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  3 15:32:37 UTC 2024

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

Log Message:
tests/lint: skip test for sizeof struct on 32-bit platforms

Even though the test only uses fixed-size types, lint's computed size of
the resulting struct differs between i386 (80) and x86_64 (112).  Both
are wrong, probably due to the unrelated struct declaration above, as
already mentioned in the comments.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.16 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.17
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.16	Thu May  2 20:03:33 2024
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c	Fri May  3 15:32:37 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_sizeof.c,v 1.16 2024/05/02 20:03:33 rillig Exp $	*/
+/*	$NetBSD: expr_sizeof.c,v 1.17 2024/05/03 15:32:37 rillig Exp $	*/
 # 3 "expr_sizeof.c"
 
 /*
@@ -7,6 +7,8 @@
  */
 
 /* lint1-extra-flags: -X 351 */
+// TODO: Remove the lp64 restriction when sequence_of_structs has been fixed.
+/* lint1-only-if: lp64 */
 
 /*
  * A sizeof expression can either take a type name or an expression.
@@ -222,7 +224,6 @@ sequence_of_structs(void)
 	typedef short unsigned int uint16_t;
 	typedef unsigned int uint32_t;
 	typedef long unsigned int uint64_t;
-	typedef unsigned long size_t;
 
 	union fp_addr {
 		uint64_t fa_64;
@@ -255,10 +256,10 @@ sequence_of_structs(void)
 	};
 
 	/* expect+1: error: negative array dimension (-20) [20] */
-	typedef int o1[-(int)((size_t)(unsigned long)(&(((struct save87 *)0)->s87_dp)))];
+	typedef int o1[-(int)((unsigned long)(&(((struct save87 *)0)->s87_dp)))];
 	// FIXME: must be 28.
 	/* expect+1: error: negative array dimension (-32) [20] */
-	typedef int o2[-(int)((size_t)(unsigned long)(&(((struct save87 *)0)->s87_ac)))];
+	typedef int o2[-(int)((unsigned long)(&(((struct save87 *)0)->s87_ac)))];
 	// FIXME: must be 108.
 	/* expect+1: error: negative array dimension (-112) [20] */
 	typedef int reveal[-(int)sizeof(struct save87)];



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

2024-05-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  3 15:32:37 UTC 2024

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

Log Message:
tests/lint: skip test for sizeof struct on 32-bit platforms

Even though the test only uses fixed-size types, lint's computed size of
the resulting struct differs between i386 (80) and x86_64 (112).  Both
are wrong, probably due to the unrelated struct declaration above, as
already mentioned in the comments.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.



Clang vs. lint's strict bool mode (was: Re: CVS commit: src/usr.bin/base64)

2024-05-03 Thread Roland Illig
Am 02.05.2024 um 22:44 schrieb Christos Zoulas:
> On 2024-05-02 3:04 pm, Christos Zoulas wrote:
>> This is with clang.
>>
> And I don't get it. Gcc produces:
>
>if (ignore &&
> # 139 "base64.c" 3 4
> ((int)((_ctype_tab_ + 1)[(
> # 139 "base64.c"
> c
> # 139 "base64.c" 3 4
> )] & 0x0040))
> # 139 "base64.c"
>   )
> continue;

Since the '&&' in the condition comes from a system header, lint is not
as strict as it could be, to allow user code to pass strict bool mode
even when the system headers don't comply.

> Clang produces:
>if (ignore && ((int)((_ctype_tab_ + 1)[(c)] & 0x0040)))
> continue;

Clang doesn't distinguish the system parts from the non-system parts,
and that's the crucial difference. I never tested the combination of
Clang with lint. I will do so now.

Roland



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

2024-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  3 04:04:18 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y debug.c decl.c externs1.h lint1.h
tree.c

Log Message:
lint: measure the alignment in bytes, not bits

While measuring the alignment in bits makes sense when building a struct
type with bit-fields, in all other places it is more confusing than
helpful.

The only visible change is that in debug mode, the format of type sizes
and alignment changed.  Since the size of all complete types is a
multiple of a byte (as defined in the C standard), sizes and alignments
are reported in bytes as well.  Only while a struct is being built, the
type size may include an additional '+x' for the bits of a bit-field.


To generate a diff of this commit:
cvs rdiff -u -r1.494 -r1.495 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.400 -r1.401 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.223 -r1.224 src/usr.bin/xlint/lint1/externs1.h \
src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.639 -r1.640 src/usr.bin/xlint/lint1/tree.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.494 src/usr.bin/xlint/lint1/cgram.y:1.495
--- src/usr.bin/xlint/lint1/cgram.y:1.494	Wed May  1 07:40:11 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Fri May  3 04:04:17 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.494 2024/05/01 07:40:11 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.495 2024/05/03 04:04:17 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.494 2024/05/01 07:40:11 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.495 2024/05/03 04:04:17 rillig Exp $");
 #endif
 
 #include 
@@ -1026,7 +1026,7 @@ struct_or_union:
 		set_sym_kind(SK_TAG);
 		begin_declaration_level($1 == STRUCT ? DLK_STRUCT : DLK_UNION);
 		dcs->d_sou_size_in_bits = 0;
-		dcs->d_sou_align_in_bits = CHAR_SIZE;
+		dcs->d_sou_align = 1;
 		$$ = $1;
 	}
 |	struct_or_union type_attribute

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.76 src/usr.bin/xlint/lint1/debug.c:1.77
--- src/usr.bin/xlint/lint1/debug.c:1.76	Wed May  1 07:40:11 2024
+++ src/usr.bin/xlint/lint1/debug.c	Fri May  3 04:04:17 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.76 2024/05/01 07:40:11 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.77 2024/05/03 04:04:17 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.76 2024/05/01 07:40:11 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.77 2024/05/03 04:04:17 rillig Exp $");
 #endif
 
 #include 
@@ -155,8 +155,12 @@ debug_type_details(const type_t *tp)
 
 	if (is_struct_or_union(tp->t_tspec)) {
 		debug_indent_inc();
-		debug_step("size %u bits, align %u bits, %s",
-		tp->u.sou->sou_size_in_bits, tp->u.sou->sou_align_in_bits,
+		unsigned int size_in_bits = tp->u.sou->sou_size_in_bits;
+		debug_printf("size %u", size_in_bits / CHAR_SIZE);
+		if (size_in_bits % CHAR_SIZE > 0)
+			debug_printf("+%u", size_in_bits % CHAR_SIZE);
+		debug_step(", align %u, %s",
+		tp->u.sou->sou_align,
 		tp->u.sou->sou_incomplete ? "incomplete" : "complete");
 
 		for (const sym_t *mem = tp->u.sou->sou_first_member;
@@ -458,12 +462,14 @@ debug_decl_level(const decl_level *dl)
 	}
 	if (dl->d_redeclared_symbol != NULL)
 		debug_sym(" redeclared=(", dl->d_redeclared_symbol, ")");
-	if (dl->d_sou_size_in_bits != 0)
-		debug_printf(" size=%u", dl->d_sou_size_in_bits);
-	if (dl->d_sou_align_in_bits != 0)
-		debug_printf(" sou_align=%u", dl->d_sou_align_in_bits);
-	if (dl->d_mem_align_in_bits != 0)
-		debug_printf(" mem_align=%u", dl->d_mem_align_in_bits);
+	if (dl->d_sou_size_in_bits > 0)
+		debug_printf(" size=%u", dl->d_sou_size_in_bits / CHAR_SIZE);
+	if (dl->d_sou_size_in_bits % CHAR_SIZE > 0)
+		debug_printf("+%u", dl->d_sou_size_in_bits % CHAR_SIZE);
+	if (dl->d_sou_align > 0)
+		debug_printf(" sou_align=%u", dl->d_sou_align);
+	if (dl->d_mem_align > 0)
+		debug_printf(" mem_align=%u", dl->d_mem_align);
 
 	debug_word(dl->d_qual.tq_const, "const");
 	debug_word(dl->d_qual.tq_restrict, "restrict");

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.400 src/usr.bin/xlint/lint1/decl.c:1.401
--- src/usr.bin/xlint/lint1/decl.c:1.400	Wed May  1 10:30:56 2024
+++ src/usr.bin/xlint/lint1/decl.c	Fri May  3 04:04:17 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.400 2024/05/01 10:30:56 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.401 2024/05/03 04:04:17 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.400 

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

2024-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri May  3 04:04:18 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y debug.c decl.c externs1.h lint1.h
tree.c

Log Message:
lint: measure the alignment in bytes, not bits

While measuring the alignment in bits makes sense when building a struct
type with bit-fields, in all other places it is more confusing than
helpful.

The only visible change is that in debug mode, the format of type sizes
and alignment changed.  Since the size of all complete types is a
multiple of a byte (as defined in the C standard), sizes and alignments
are reported in bytes as well.  Only while a struct is being built, the
type size may include an additional '+x' for the bits of a bit-field.


To generate a diff of this commit:
cvs rdiff -u -r1.494 -r1.495 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.400 -r1.401 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.223 -r1.224 src/usr.bin/xlint/lint1/externs1.h \
src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.639 -r1.640 src/usr.bin/xlint/lint1/tree.c

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



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

2024-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  2 20:03:33 UTC 2024

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

Log Message:
tests/lint: demonstrate wrong struct size calculation


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 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.15 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.16
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.15	Wed Mar 13 06:56:24 2024
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c	Thu May  2 20:03:33 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_sizeof.c,v 1.15 2024/03/13 06:56:24 rillig Exp $	*/
+/*	$NetBSD: expr_sizeof.c,v 1.16 2024/05/02 20:03:33 rillig Exp $	*/
 # 3 "expr_sizeof.c"
 
 /*
@@ -213,3 +213,53 @@ sizeof_array_parameter(short arr[12345])
 	/* expect+1: error: negative array dimension (-2) [20] */
 	typedef int sizeof_arr_elem[-(int)(sizeof *arr)];
 }
+
+
+void
+sequence_of_structs(void)
+{
+	typedef unsigned char uint8_t;
+	typedef short unsigned int uint16_t;
+	typedef unsigned int uint32_t;
+	typedef long unsigned int uint64_t;
+	typedef unsigned long size_t;
+
+	union fp_addr {
+		uint64_t fa_64;
+		struct {
+			uint32_t fa_off;
+			uint16_t fa_seg;
+			uint16_t fa_opcode;
+		} fa_32;
+	} __packed _Alignas(4);
+
+	struct fpacc87 {
+		uint64_t f87_mantissa;
+		uint16_t f87_exp_sign;
+	} __packed _Alignas(2);
+
+	// FIXME: This otherwise unused struct declaration influences the
+	// offsets checked below. Without this struct, sizeof(struct save87)
+	// is calculated correctly as 108 below.
+	struct fpaccfx {
+		struct fpacc87 r _Alignas(16);
+	};
+
+	struct save87 {
+		uint16_t s87_cw _Alignas(4);
+		uint16_t s87_sw _Alignas(4);
+		uint16_t s87_tw _Alignas(4);
+		union fp_addr s87_ip;
+		union fp_addr s87_dp;
+		struct fpacc87 s87_ac[8];
+	};
+
+	/* expect+1: error: negative array dimension (-20) [20] */
+	typedef int o1[-(int)((size_t)(unsigned long)(&(((struct save87 *)0)->s87_dp)))];
+	// FIXME: must be 28.
+	/* expect+1: error: negative array dimension (-32) [20] */
+	typedef int o2[-(int)((size_t)(unsigned long)(&(((struct save87 *)0)->s87_ac)))];
+	// FIXME: must be 108.
+	/* expect+1: error: negative array dimension (-112) [20] */
+	typedef int reveal[-(int)sizeof(struct save87)];
+}



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

2024-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  2 20:03:33 UTC 2024

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

Log Message:
tests/lint: demonstrate wrong struct size calculation


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 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.



Re: CVS commit: src/tests/lib/libm

2024-05-02 Thread Roland Illig
Am 02.05.2024 um 05:30 schrieb Robert Elz:
> Module Name:  src
> Committed By: kre
> Date: Thu May  2 03:30:07 UTC 2024
>
> Modified Files:
>   src/tests/lib/libm: t_fe_round.c
>
> Log Message:
> Use intmax_t instead of long int when trying to represent very large
> integers (10^50 or so), so we don't exceed the capacity of systems where
> long int is only 32 bits.

In the lint tests (which don't have a C preprocessor available), I use
the following typedefs to get fixed-width integer types:

typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;

These types are the same on all platforms supported by lint, and I guess
by NetBSD as a whole.

I particularly avoid the types 'long' and 'long double', as they vary
between the platforms.

Curiously, intmax_t is a 64-bit type even on amd64, where __int128_t is
also available, but I don't use that because that type is not predefined.

Roland



Re: CVS commit: src/usr.bin/base64

2024-05-02 Thread Roland Illig
Am 02.05.2024 um 17:45 schrieb Christos Zoulas:
> Module Name:  src
> Committed By: christos
> Date: Thu May  2 15:45:36 UTC 2024
>
> Modified Files:
>   src/usr.bin/base64: Makefile
>
> Log Message:
> comment out strict boolean lint check because isspace() returns int and lint
> complains.

In which exact environment did you experience this?

Lint's strict bool mode accepts 'a & b' as having either integer or
boolean type, so the macro version of isspace should definitely work.

The function variant of isspace doesn't work, though. So maybe you are
running outside _NETBSD_SOURCE mode or you have defined _CTYPE_NOINLINE.

Any idea how lint can accept isspace as returning int/bool while not
assuming int/bool for strcmp? One idea is to explicitly list the
"bool-like" functions from the C standard library internally in lint,
another more flexible approach is to have a function attribute
__declared_int_but_actually_bool.

Roland


CVS commit: src/lib/libutil

2024-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  2 18:34:01 UTC 2024

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
parsedate.3: resolve contradictory values for 'next'


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libutil/parsedate.3

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



CVS commit: src/lib/libutil

2024-05-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu May  2 18:34:01 UTC 2024

Modified Files:
src/lib/libutil: parsedate.3

Log Message:
parsedate.3: resolve contradictory values for 'next'


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libutil/parsedate.3

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

Modified files:

Index: src/lib/libutil/parsedate.3
diff -u src/lib/libutil/parsedate.3:1.26 src/lib/libutil/parsedate.3:1.27
--- src/lib/libutil/parsedate.3:1.26	Sun May 16 19:42:35 2021
+++ src/lib/libutil/parsedate.3	Thu May  2 18:34:01 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: parsedate.3,v 1.26 2021/05/16 19:42:35 kre Exp $
+.\" $NetBSD: parsedate.3,v 1.27 2024/05/02 18:34:01 rillig Exp $
 .\"
 .\" Copyright (c) 2006 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -96,7 +96,8 @@ The following words have the indicated n
 .Dv first , next ,
 or
 .Dv one =
-1,
+1
+.Pq but see the BUGS section below ,
 .Dv second
 is unused so that it is not confused with
 .Dq seconds ,



Re: CVS commit: src/lib/libutil

2024-05-01 Thread Roland Illig
Am 01.05.2024 um 21:59 schrieb Christos Zoulas:
> Module Name:  src
> Committed By: christos
> Date: Wed May  1 19:59:08 UTC 2024
>
> Modified Files:
>   src/lib/libutil: parsedate.y
>
> Log Message:
> next should increement by 1 not 2.

Are you sure? I get these test results:

> t_parsedate (2/5): 7 test cases
> atsecs: [0.006548s] Passed.
> dates: [0.007241s] Passed.
> dsttimes: [0.007517s] Passed.
> gibberish: [0.007637s] Passed.
> relative: [0.287375s] Failed: 2258 checks failed; see output for more 
> details
> times: [0.008402s] Passed.
> zones: [0.007586s] Passed.

After your change, "next sunday" goes backward in time, for example:

> From 28110552 (Sun Nov 22 08:29:12 1970) using "next sunday",
> obtained 2808 (Sun Nov 22 00:00:00 1970);
> expected 28684800 (Sun Nov 29 00:00:00 1970)



CVS commit: src

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 17:42:58 UTC 2024

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

Log Message:
lint: make 'offsetof(t, array-member)' a constant expression

The macro 'offsetof(t, m)' already expanded to a constant expression for
scalar members but not for arrays.  This was because the macro expanded
to '(size_t)(((t *)0)->m)', which lint internally represents as
'addr(indir(ptr(0) + offset(m)))', and build_address simplifies
'addr(indir(x))' to 'x' if the types match.  The types only match for
scalar types though, but not for arrays.

When build_address happens, the type information is incomplete,
therefore 'offsetof(t, array)' has to be simplified at a later point.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.638 -r1.639 src/usr.bin/xlint/lint1/tree.c

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/decl.c
diff -u src/tests/usr.bin/xlint/lint1/decl.c:1.29 src/tests/usr.bin/xlint/lint1/decl.c:1.30
--- src/tests/usr.bin/xlint/lint1/decl.c:1.29	Wed May  1 12:36:56 2024
+++ src/tests/usr.bin/xlint/lint1/decl.c	Wed May  1 17:42:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl.c,v 1.29 2024/05/01 12:36:56 rillig Exp $	*/
+/*	$NetBSD: decl.c,v 1.30 2024/05/01 17:42:57 rillig Exp $	*/
 # 3 "decl.c"
 
 /*
@@ -243,22 +243,29 @@ get_x(struct point3d { struct point3d_nu
 }
 
 // Expressions of the form '(size_t)_ptr->member' are used by several
-// C implementations to implement the offsetof macro.  Dereferencing a null
-// pointer invokes undefined behavior, though, even in this form.
+// C implementations to implement the offsetof macro.
 void
 offsetof_on_array_member(void)
 {
-	struct s1 {
+	typedef struct {
 		int padding, plain, arr[2];
-	};
+	} s1;
 
+	// Bit-fields must have a constant number of bits.
 	struct s2 {
-		unsigned int off_plain:(unsigned long)&((struct s1 *)0)->plain;
-		// FIXME: offsetof must work for array members as well.
-		/* expect+1: error: integral constant expression expected [55] */
-		unsigned int off_arr:(unsigned long)&((struct s1 *)0)->arr;
-		// FIXME: offsetof must work for array members as well.
-		/* expect+1: error: integral constant expression expected [55] */
-		unsigned int off_arr_element:(unsigned long)&((struct s1 *)0)->arr[0];
+		unsigned int off_plain:(unsigned long)&((s1 *)0)->plain;
+		unsigned int off_arr:(unsigned long)&((s1 *)0)->arr;
+		unsigned int off_arr_0:(unsigned long)&((s1 *)0)->arr[0];
+		unsigned int off_arr_3:(unsigned long)&((s1 *)0)->arr[3];
 	};
+
+	// Arrays may be variable-width, but the diagnostic reveals the size.
+	/* expect+1: error: negative array dimension (-4) [20] */
+	typedef int off_plain[-(int)(unsigned long)&((s1 *)0)->plain];
+	/* expect+1: error: negative array dimension (-8) [20] */
+	typedef int off_arr[-(int)(unsigned long)&((s1 *)0)->arr];
+	/* expect+1: error: negative array dimension (-8) [20] */
+	typedef int off_arr_0[-(int)(unsigned long)&((s1 *)0)->arr[0]];
+	/* expect+1: error: negative array dimension (-20) [20] */
+	typedef int off_arr_3[-(int)(unsigned long)&((s1 *)0)->arr[3]];
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.638 src/usr.bin/xlint/lint1/tree.c:1.639
--- src/usr.bin/xlint/lint1/tree.c:1.638	Wed May  1 05:49:33 2024
+++ src/usr.bin/xlint/lint1/tree.c	Wed May  1 17:42:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.638 2024/05/01 05:49:33 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.639 2024/05/01 17:42:57 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.638 2024/05/01 05:49:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.639 2024/05/01 17:42:57 rillig Exp $");
 #endif
 
 #include 
@@ -4112,6 +4112,28 @@ cast_to_union(tnode_t *otn, bool sys, ty
 	return NULL;
 }
 
+// In GCC mode, allow 'nullptr + offset' as a constant expression.
+static tnode_t *
+null_pointer_offset(tnode_t *tn)
+{
+	uint64_t off = 0;
+	const tnode_t *n = tn;
+	while ((n->tn_op == PLUS || n->tn_op == MINUS)
+	&& is_integer(n->u.ops.right->tn_type->t_tspec)) {
+		off += (uint64_t)n->u.ops.right->u.value.u.integer;
+		n = n->u.ops.left;
+	}
+	if (n->tn_type->t_tspec == PTR
+	&& n->tn_op == ADDR
+	&& n->u.ops.left->tn_op == INDIR
+	&& n->u.ops.left->u.ops.left->tn_op == CON
+	&& n->u.ops.left->u.ops.left->tn_type->t_tspec == PTR) {
+		off += (uint64_t)n->u.ops.left->u.ops.left->u.value.u.integer;
+		return build_integer_constant(SIZEOF_TSPEC, (int64_t)off);
+	}
+	return tn;
+}
+
 tnode_t *
 cast(tnode_t *tn, bool sys, type_t *tp)
 {
@@ -4144,7 +4166,7 @@ cast(tnode_t *tn, bool sys, type_t *tp)
 		error(148);
 		return NULL;
 	} else if (is_integer(nt) && is_scalar(ot)) {
-		/* ok */
+		tn = 

CVS commit: src

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 17:42:58 UTC 2024

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

Log Message:
lint: make 'offsetof(t, array-member)' a constant expression

The macro 'offsetof(t, m)' already expanded to a constant expression for
scalar members but not for arrays.  This was because the macro expanded
to '(size_t)(((t *)0)->m)', which lint internally represents as
'addr(indir(ptr(0) + offset(m)))', and build_address simplifies
'addr(indir(x))' to 'x' if the types match.  The types only match for
scalar types though, but not for arrays.

When build_address happens, the type information is incomplete,
therefore 'offsetof(t, array)' has to be simplified at a later point.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.638 -r1.639 src/usr.bin/xlint/lint1/tree.c

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



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

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 12:36:56 UTC 2024

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

Log Message:
tests/lint: test large enum constants and offsetof with array members


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl_enum.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-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 12:36:56 UTC 2024

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

Log Message:
tests/lint: test large enum constants and offsetof with array members


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl_enum.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.28 src/tests/usr.bin/xlint/lint1/decl.c:1.29
--- src/tests/usr.bin/xlint/lint1/decl.c:1.28	Sun Jan 28 08:17:27 2024
+++ src/tests/usr.bin/xlint/lint1/decl.c	Wed May  1 12:36:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl.c,v 1.28 2024/01/28 08:17:27 rillig Exp $	*/
+/*	$NetBSD: decl.c,v 1.29 2024/05/01 12:36:56 rillig Exp $	*/
 # 3 "decl.c"
 
 /*
@@ -241,3 +241,24 @@ get_x(struct point3d { struct point3d_nu
 	static struct point3d_number z;
 	return arg.x.v + local.x.v + z.v;
 }
+
+// Expressions of the form '(size_t)_ptr->member' are used by several
+// C implementations to implement the offsetof macro.  Dereferencing a null
+// pointer invokes undefined behavior, though, even in this form.
+void
+offsetof_on_array_member(void)
+{
+	struct s1 {
+		int padding, plain, arr[2];
+	};
+
+	struct s2 {
+		unsigned int off_plain:(unsigned long)&((struct s1 *)0)->plain;
+		// FIXME: offsetof must work for array members as well.
+		/* expect+1: error: integral constant expression expected [55] */
+		unsigned int off_arr:(unsigned long)&((struct s1 *)0)->arr;
+		// FIXME: offsetof must work for array members as well.
+		/* expect+1: error: integral constant expression expected [55] */
+		unsigned int off_arr_element:(unsigned long)&((struct s1 *)0)->arr[0];
+	};
+}

Index: src/tests/usr.bin/xlint/lint1/decl_enum.c
diff -u src/tests/usr.bin/xlint/lint1/decl_enum.c:1.4 src/tests/usr.bin/xlint/lint1/decl_enum.c:1.5
--- src/tests/usr.bin/xlint/lint1/decl_enum.c:1.4	Fri Jun 30 21:39:54 2023
+++ src/tests/usr.bin/xlint/lint1/decl_enum.c	Wed May  1 12:36:56 2024
@@ -1,10 +1,22 @@
-/*	$NetBSD: decl_enum.c,v 1.4 2023/06/30 21:39:54 rillig Exp $	*/
+/*	$NetBSD: decl_enum.c,v 1.5 2024/05/01 12:36:56 rillig Exp $	*/
 # 3 "decl_enum.c"
 
 /*
  * Tests for enum declarations.
  */
 
+
+// Initializing an enum from a 64-bit value cuts off the upper bits.
+// TIME_MIN thus gets truncated from 0x8000___ to 0.
+// TIME_MAX thus gets truncated from 0x7fff___ to -1.
+enum {
+	/* expect+1: warning: integral constant too large [56] */
+	TIME_MIN = (long long)(1ULL << 63),
+	/* expect+1: warning: integral constant too large [56] */
+	TIME_MAX = (long long)~(1ULL << 63),
+};
+
+
 /* cover 'enumerator_list: error' */
 enum {
 	/* expect+1: error: syntax error 'goto' [249] */



CVS commit: src

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 10:30:56 UTC 2024

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

Log Message:
lint: fix size of struct with large alignment

Lint now successfully passes all compile-time assertions in the amd64
kernel that deal with struct sizes.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 \
src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c
cvs rdiff -u -r1.399 -r1.400 src/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/gcc_attribute_aligned.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c:1.7 src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c:1.8
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c:1.7	Wed May  1 07:40:11 2024
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c	Wed May  1 10:30:56 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_attribute_aligned.c,v 1.7 2024/05/01 07:40:11 rillig Exp $	*/
+/*	$NetBSD: gcc_attribute_aligned.c,v 1.8 2024/05/01 10:30:56 rillig Exp $	*/
 # 3 "gcc_attribute_aligned.c"
 
 /*
@@ -72,3 +72,13 @@ aligned_struct_member(void)
 	/* expect+1: error: negative array dimension (-32) [20] */
 	typedef int ctassert[-(int)sizeof(struct aligned)];
 }
+
+void
+alignment_larger_than_size(void)
+{
+	struct s {
+		unsigned u32 __attribute__((__aligned__(32)));
+	} _Alignas(4096);
+	/* expect+1: error: negative array dimension (-4096) [20] */
+	typedef int size[-(int)sizeof(struct s)];
+}

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.399 src/usr.bin/xlint/lint1/decl.c:1.400
--- src/usr.bin/xlint/lint1/decl.c:1.399	Wed May  1 07:40:11 2024
+++ src/usr.bin/xlint/lint1/decl.c	Wed May  1 10:30:56 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.399 2024/05/01 07:40:11 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.400 2024/05/01 10:30:56 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.399 2024/05/01 07:40:11 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.400 2024/05/01 10:30:56 rillig Exp $");
 #endif
 
 #include 
@@ -463,6 +463,9 @@ void
 dcs_add_alignas(tnode_t *tn)
 {
 	dcs->d_mem_align_in_bits = to_int_constant(tn, true) * CHAR_SIZE;
+	if (dcs->d_type != NULL && is_struct_or_union(dcs->d_type->t_tspec))
+		dcs->d_type->u.sou->sou_align_in_bits =
+		dcs->d_mem_align_in_bits;
 }
 
 void
@@ -606,6 +609,7 @@ dcs_begin_type(void)
 	dcs->d_redeclared_symbol = NULL;
 	// keep d_sou_size_in_bits
 	// keep d_sou_align_in_bits
+	dcs->d_mem_align_in_bits = 0;
 	dcs->d_qual = (type_qualifiers) { .tq_const = false };
 	dcs->d_inline = false;
 	dcs->d_multiple_storage_classes = false;
@@ -707,6 +711,8 @@ dcs_merge_declaration_specifiers(void)
 	debug_dcs();
 }
 
+static void dcs_align(unsigned int, unsigned int);
+
 /* Create a type in 'dcs->d_type' from the information gathered in 'dcs'. */
 void
 dcs_end_type(void)
@@ -741,6 +747,14 @@ dcs_end_type(void)
 		dcs->d_type->t_const |= dcs->d_qual.tq_const;
 		dcs->d_type->t_volatile |= dcs->d_qual.tq_volatile;
 	}
+	unsigned align = dcs->d_mem_align_in_bits;
+	if (align > 0 && dcs->d_type->t_tspec == STRUCT) {
+		dcs_align(align, 0);
+		dcs->d_type->u.sou->sou_align_in_bits = align;
+		dcs->d_type->u.sou->sou_size_in_bits =
+		(dcs->d_type->u.sou->sou_size_in_bits + align - 1)
+		& -align;
+	}
 
 	debug_dcs();
 	debug_leave();
@@ -814,7 +828,6 @@ alignment_in_bits(const type_t *tp)
 			a = worst_align_in_bits;
 	}
 	lint_assert(a >= CHAR_SIZE);
-	lint_assert(a <= worst_align_in_bits);
 	return a;
 }
 



CVS commit: src

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 10:30:56 UTC 2024

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

Log Message:
lint: fix size of struct with large alignment

Lint now successfully passes all compile-time assertions in the amd64
kernel that deal with struct sizes.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 \
src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c
cvs rdiff -u -r1.399 -r1.400 src/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/sys/sys

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 07:43:42 UTC 2024

Modified Files:
src/sys/sys: cdefs.h

Log Message:
sys/cdefs.h: pass __aligned to lint

Lint could parse _Alignas and __attribute__((__aligned__(4))) previously
but simply ignored them. Since today, they affect the layout of struct
and union.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/sys/cdefs.h

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



CVS commit: src/sys/sys

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 07:43:42 UTC 2024

Modified Files:
src/sys/sys: cdefs.h

Log Message:
sys/cdefs.h: pass __aligned to lint

Lint could parse _Alignas and __attribute__((__aligned__(4))) previously
but simply ignored them. Since today, they affect the layout of struct
and union.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/sys/cdefs.h

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

Modified files:

Index: src/sys/sys/cdefs.h
diff -u src/sys/sys/cdefs.h:1.160 src/sys/sys/cdefs.h:1.161
--- src/sys/sys/cdefs.h:1.160	Sun Apr 30 08:45:48 2023
+++ src/sys/sys/cdefs.h	Wed May  1 07:43:41 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cdefs.h,v 1.160 2023/04/30 08:45:48 riastradh Exp $	*/
+/*	$NetBSD: cdefs.h,v 1.161 2024/05/01 07:43:41 rillig Exp $	*/
 
 /* * Copyright (c) 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -451,7 +451,7 @@
 #if defined(__lint__)
 #define __thread	/* delete */
 #define	__packed	__packed
-#define	__aligned(x)	/* delete */
+#define	__aligned(x)	_Alignas((x))
 #define	__section(x)	/* delete */
 #elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) || defined(__lint__)
 #define	__packed	__attribute__((__packed__))



CVS commit: src

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 07:40:11 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_precedence.c
gcc_attribute_aligned.c
src/usr.bin/xlint/lint1: cgram.y debug.c decl.c externs1.h lint1.h

Log Message:
lint: support _Alignas and __attribute__((__aligned(4)))


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/expr_precedence.c
cvs rdiff -u -r1.6 -r1.7 \
src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c
cvs rdiff -u -r1.493 -r1.494 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.398 -r1.399 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.222 -r1.223 src/usr.bin/xlint/lint1/externs1.h \
src/usr.bin/xlint/lint1/lint1.h

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_precedence.c
diff -u src/tests/usr.bin/xlint/lint1/expr_precedence.c:1.11 src/tests/usr.bin/xlint/lint1/expr_precedence.c:1.12
--- src/tests/usr.bin/xlint/lint1/expr_precedence.c:1.11	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/expr_precedence.c	Wed May  1 07:40:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_precedence.c,v 1.11 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: expr_precedence.c,v 1.12 2024/05/01 07:40:11 rillig Exp $	*/
 # 3 "expr_precedence.c"
 
 /*
@@ -20,8 +20,9 @@ int init_error = 3, 4;
 int init_syntactically_ok = var = 1 ? 2 : 3;
 
 /*
- * The arguments of __attribute__ must be constant-expression, as assignments
- * don't make sense at that point.
+ * The arguments of __attribute__ must be constant-expression, but for
+ * simplicity of implementation, they are parsed just like function arguments,
+ * even though this allows assignment-expression.
  */
 void __attribute__((format(printf,
 /*
@@ -32,7 +33,6 @@ void __attribute__((format(printf,
  *
  * See lex.c, function 'search', keyword 'in_gcc_attribute'.
  */
-/* expect+1: error: syntax error '=' [249] */
 var = 1,
 /* Syntactically ok, must be a constant expression though. */
 var > 0 ? 2 : 1)))

Index: src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c:1.6 src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c:1.7
--- src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c:1.6	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c	Wed May  1 07:40:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_attribute_aligned.c,v 1.6 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: gcc_attribute_aligned.c,v 1.7 2024/05/01 07:40:11 rillig Exp $	*/
 # 3 "gcc_attribute_aligned.c"
 
 /*
@@ -47,8 +47,8 @@ struct save87 {
 	struct fpacc87 s87_ac[8];
 };
 
-/* FIXME: @4 2 + @4 2 + @4 2 + @4 8 + @4 8 + @2 (8 * 10) == 108 */
-/* expect+1: error: negative array dimension (-104) [20] */
+/* @4 2 + @4 2 + @4 2 + @4 8 + @4 8 + @2 (8 * 10) == 108 */
+/* expect+1: error: negative array dimension (-108) [20] */
 typedef int sizeof_save87[-(int)sizeof(struct save87)];
 
 
@@ -69,7 +69,6 @@ aligned_struct_member(void)
 	 *
 	 * https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
 	 */
-	/* TODO: should be -32 instead of -8. */
-	/* expect+1: error: negative array dimension (-8) [20] */
+	/* expect+1: error: negative array dimension (-32) [20] */
 	typedef int ctassert[-(int)sizeof(struct aligned)];
 }

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.493 src/usr.bin/xlint/lint1/cgram.y:1.494
--- src/usr.bin/xlint/lint1/cgram.y:1.493	Fri Mar 29 08:35:32 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Wed May  1 07:40:11 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.493 2024/03/29 08:35:32 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.494 2024/05/01 07:40:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.493 2024/03/29 08:35:32 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.494 2024/05/01 07:40:11 rillig Exp $");
 #endif
 
 #include 
@@ -423,7 +423,6 @@ is_either(const char *s, const char *a, 
 /* No type for gcc_attribute_specifier. */
 /* No type for gcc_attribute_list. */
 /* No type for gcc_attribute. */
-/* No type for gcc_attribute_parameters. */
 %type	 sys
 
 %%
@@ -937,8 +936,12 @@ type_attribute_opt:
 
 type_attribute:			/* See C11 6.7 declaration-specifiers */
 	gcc_attribute_specifier
-|	T_ALIGNAS T_LPAREN type_specifier T_RPAREN	/* C11 6.7.5 */
-|	T_ALIGNAS T_LPAREN constant_expression T_RPAREN	/* C11 6.7.5 */
+|	T_ALIGNAS T_LPAREN type_specifier T_RPAREN {		/* C11 6.7.5 */
+		dcs_add_alignas(build_sizeof($3));
+	}
+|	T_ALIGNAS T_LPAREN constant_expression T_RPAREN {	/* C11 6.7.5 */
+		dcs_add_alignas($3);
+	}
 |	T_PACKED {
 		dcs_add_packed();
 	}
@@ -2197,18 +2200,18 @@ gcc_attribute:
 	

CVS commit: src

2024-05-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 07:40:11 UTC 2024

Modified Files:
src/tests/usr.bin/xlint/lint1: expr_precedence.c
gcc_attribute_aligned.c
src/usr.bin/xlint/lint1: cgram.y debug.c decl.c externs1.h lint1.h

Log Message:
lint: support _Alignas and __attribute__((__aligned(4)))


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/expr_precedence.c
cvs rdiff -u -r1.6 -r1.7 \
src/tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c
cvs rdiff -u -r1.493 -r1.494 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.398 -r1.399 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.222 -r1.223 src/usr.bin/xlint/lint1/externs1.h \
src/usr.bin/xlint/lint1/lint1.h

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



CVS commit: src

2024-04-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 05:49:33 UTC 2024

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

Log Message:
lint: fix warning about out-of-bounds bit-field value


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.637 -r1.638 src/usr.bin/xlint/lint1/tree.c

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



CVS commit: src

2024-04-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 05:49:33 UTC 2024

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

Log Message:
lint: fix warning about out-of-bounds bit-field value


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.637 -r1.638 src/usr.bin/xlint/lint1/tree.c

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.39 src/tests/usr.bin/xlint/lint1/msg_132.c:1.40
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.39	Wed May  1 05:38:11 2024
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Wed May  1 05:49:33 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.39 2024/05/01 05:38:11 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.40 2024/05/01 05:49:33 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -265,13 +265,13 @@ test_ic_shr(u64_t x)
 unsigned char
 test_bit_fields(unsigned long long m)
 {
-	/* expect+1: warning: conversion from 'unsigned long long:32' to 'unsigned int:3' may lose accuracy [132] */
+	/* expect+1: warning: conversion from 'unsigned long long' to 'unsigned int:3' may lose accuracy [132] */
 	bits.u3 = bits.u32 & m;
 
 	bits.u5 = bits.u3 & m;
 	bits.u32 = bits.u5 & m;
 
-	/* expect+1: warning: conversion from 'unsigned long long:32' to 'unsigned char' may lose accuracy [132] */
+	/* expect+1: warning: conversion from 'unsigned long long' to 'unsigned char' may lose accuracy [132] */
 	return bits.u32 & m;
 }
 
@@ -450,6 +450,7 @@ binary_operators_on_bit_fields(void)
 	cond = (s.u15 | s.u48 | s.u64) != 0;
 	cond = (s.u64 | s.u48 | s.u15) != 0;
 
-	/* expect+1: warning: conversion of 'int' to 'int:4' is out of range [119] */
+	// Before tree.c from 1.638 from 2024-05-01, lint wrongly warned:
+	// warning: conversion of 'int' to 'int:4' is out of range [119]
 	s32 = 8 - bits.u3;
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.637 src/usr.bin/xlint/lint1/tree.c:1.638
--- src/usr.bin/xlint/lint1/tree.c:1.637	Sat Apr 27 12:46:37 2024
+++ src/usr.bin/xlint/lint1/tree.c	Wed May  1 05:49:33 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.637 2024/04/27 12:46:37 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.638 2024/05/01 05:49:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.637 2024/04/27 12:46:37 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.638 2024/05/01 05:49:33 rillig Exp $");
 #endif
 
 #include 
@@ -763,12 +763,14 @@ balance(op_t op, tnode_t **lnp, tnode_t 
 	if (t != rt)
 		*rnp = apply_usual_arithmetic_conversions(op, *rnp, t);
 
-	unsigned lw = (*lnp)->tn_type->t_bit_field_width;
-	unsigned rw = (*rnp)->tn_type->t_bit_field_width;
-	if (lw < rw)
-		*lnp = convert(NOOP, 0, (*rnp)->tn_type, *lnp);
-	if (rw < lw)
-		*rnp = convert(NOOP, 0, (*lnp)->tn_type, *rnp);
+	if (is_integer(t)) {
+		unsigned lw = width_in_bits((*lnp)->tn_type);
+		unsigned rw = width_in_bits((*rnp)->tn_type);
+		if (lw < rw)
+			*lnp = convert(NOOP, 0, (*rnp)->tn_type, *lnp);
+		if (rw < lw)
+			*rnp = convert(NOOP, 0, (*lnp)->tn_type, *rnp);
+	}
 }
 
 static tnode_t *



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

2024-04-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 05:38:11 UTC 2024

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

Log Message:
lint: demonstrate wrong warning about out-of-range bit-field


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 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.38 src/tests/usr.bin/xlint/lint1/msg_132.c:1.39
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.38	Mon Mar 25 23:39:14 2024
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Wed May  1 05:38:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.38 2024/03/25 23:39:14 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.39 2024/05/01 05:38:11 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -449,4 +449,7 @@ binary_operators_on_bit_fields(void)
 	u64 = s.u64 | s.u48 | s.u15;
 	cond = (s.u15 | s.u48 | s.u64) != 0;
 	cond = (s.u64 | s.u48 | s.u15) != 0;
+
+	/* expect+1: warning: conversion of 'int' to 'int:4' is out of range [119] */
+	s32 = 8 - bits.u3;
 }



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

2024-04-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed May  1 05:38:11 UTC 2024

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

Log Message:
lint: demonstrate wrong warning about out-of-range bit-field


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 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.



Re: CVS commit: src/sys/arch/hp300/dev

2024-04-30 Thread Roland Illig
Am 30.04.2024 um 11:55 schrieb Izumi Tsutsui:
> Module Name:  src
> Committed By: tsutsui
> Date: Tue Apr 30 09:55:46 UTC 2024
>
> Modified Files:
>   src/sys/arch/hp300/dev: dma.c
>
> Log Message:
> Fix another fatal typo that prevents dma(4) interrupts.

The buggy code was:
>   if ((sc->sc_ipl == ipl) == 0) {

The typo in the first '==' can be found by treating bool as a data type
incompatible with any other scalar type, and this is what lint does in
its "strict bool mode".

Lint is not yet ready for the whole kernel source, as it errors out on
232 of the 3223 source files. But it can check hp300/dma.c, and running
it with the extra flag -T finds the bug, among several false positives.

If you want to play around a bit, the attached patch allows you to
suppress the uninteresting lint warnings in the kernel source, and to
configure per-file lint flags. To detect the above bug in dma.c 1.47, run:

cd OBJDIR/sys/arch/hp300/compile/GENERIC
make dma.ln KERNLINTFLAGS.dma.c=-T

Roland
Index: sys/conf/lint.mk
===
RCS file: /cvsroot/src/sys/conf/lint.mk,v
retrieving revision 1.5
diff -u -r1.5 lint.mk
--- sys/conf/lint.mk27 Aug 2022 21:49:33 -  1.5
+++ sys/conf/lint.mk30 Apr 2024 22:50:59 -
@@ -5,11 +5,25 @@
 ##
 
 .if !target(lint)
+DEFKERNLINTFLAGS=  -bceghnxzFS
+DEFKERNLINTFLAGS+= -X 0# empty declaration
+DEFKERNLINTFLAGS+= -X 2# empty declaration
+DEFKERNLINTFLAGS+= -X 56   # integral constant too large
+DEFKERNLINTFLAGS+= -X 129  # expression with null effect
+DEFKERNLINTFLAGS+= -X 161  # constant in conditional context
+DEFKERNLINTFLAGS+= -X 226  # static variable unused
+DEFKERNLINTFLAGS+= -X 231  # unused parameter
+DEFKERNLINTFLAGS+= -X 236  # unused static function
+DEFKERNLINTFLAGS+= -X 247  # pointer cast may be troublesome
+DEFKERNLINTFLAGS+= -X 309  # lossy bitwise '&'
+DEFKERNLINTFLAGS+= -X 351  # missing header declaration
+DEFKERNLINTFLAGS+= -X 352  # nested 'extern' declaration
+
 .PATH: $S
 ALLSFILES?=${MD_SFILES} ${SFILES}
 LINTSTUBS?=${ALLSFILES:T:R:%=LintStub_%.c}
-KERNLINTFLAGS?=-bceghnxzFS
-NORMAL_LN?=${LINT} ${KERNLINTFLAGS} ${CPPFLAGS:M-[IDU]*} -o $@ -i $<
+KERNLINTFLAGS?=${DEFKERNLINTFLAGS}
+NORMAL_LN?=${LINT} ${KERNLINTFLAGS} ${KERNLINTFLAGS.${.IMPSRC:T}} 
${CPPFLAGS:M-[IDU]*} -o $@ -i $<
 
 _lsrc= ${CFILES} ${LINTSTUBS} ${MI_CFILES} ${MD_CFILES}
 LOBJS?=${_lsrc:T:.c=.ln} ${LIBKERNLN} ${SYSLIBCOMPATLN}


CVS commit: src/lib/libc/gen

2024-04-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 28 22:57:16 UTC 2024

Modified Files:
src/lib/libc/gen: time.3

Log Message:
time.3: clarify that *tloc is always set if tloc != NULL


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/gen/time.3

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

Modified files:

Index: src/lib/libc/gen/time.3
diff -u src/lib/libc/gen/time.3:1.16 src/lib/libc/gen/time.3:1.17
--- src/lib/libc/gen/time.3:1.16	Sat Nov  5 18:17:29 2011
+++ src/lib/libc/gen/time.3	Sun Apr 28 22:57:16 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: time.3,v 1.16 2011/11/05 18:17:29 christos Exp $
+.\"	$NetBSD: time.3,v 1.17 2024/04/28 22:57:16 rillig Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" @(#)time.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd November 5, 2011
+.Dd April 29, 2024
 .Dt TIME 3
 .Os
 .Sh NAME
@@ -52,21 +52,17 @@ function
 returns the value of time in seconds since 0 hours, 0 minutes,
 0 seconds, January 1, 1970, Coordinated Universal Time.
 .Pp
-A copy of the time value may be saved to the area indicated by the
-pointer
-.Fa tloc .
 If
 .Fa tloc
-is a
-.Dv NULL
-pointer, no value is stored.
+is not a null pointer, a copy of the time value is saved in
+.Fa *tloc .
 .Pp
 Upon successful completion,
 .Fn time
 returns the value of time.
 Otherwise a value of
 .Po
-.Po Fa time_t Pc \-1
+.Po Fa time_t Pc Ns \-1
 .Pc
 is returned and the global variable
 .Va errno



CVS commit: src/lib/libc/gen

2024-04-28 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Apr 28 22:57:16 UTC 2024

Modified Files:
src/lib/libc/gen: time.3

Log Message:
time.3: clarify that *tloc is always set if tloc != NULL


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libc/gen/time.3

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



  1   2   3   4   5   6   7   8   9   10   >