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

2024-06-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jun  8 20:47:00 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: makeman

Log Message:
lint.7: abbreviate %lld to %d in the list of messages


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

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/makeman
diff -u src/usr.bin/xlint/lint1/makeman:1.10 src/usr.bin/xlint/lint1/makeman:1.11
--- src/usr.bin/xlint/lint1/makeman:1.10	Sat May 11 15:53:38 2024
+++ src/usr.bin/xlint/lint1/makeman	Sat Jun  8 20:47:00 2024
@@ -1,5 +1,5 @@
 #!/bin/sh
-#	$NetBSD: makeman,v 1.10 2024/05/11 15:53:38 rillig Exp $
+#	$NetBSD: makeman,v 1.11 2024/06/08 20:47:00 rillig Exp $
 #
 # Copyright (c) 2000 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -38,7 +38,7 @@ list_messages() {
 	-e 's|^'"$tab"'"",.*// '"$2"'[0-9]+$|---'"$tab"'(no longer used)|p' \
 	"$1" \
 	| ${SED} -E \
-	-e 's,%ld|%jd,%d,g' \
+	-e 's,%ld|%lld|%jd,%d,g' \
 	-e 's,%lu|%llu|%ju,%u,g' \
 	-e 's,%Lg,%g,g' \
 	-e 's|%.\*s|%s|g' \
@@ -49,7 +49,7 @@ list_messages() {
 }
 
 # shellcheck disable=SC2016
-cvsid='$NetBSD: makeman,v 1.10 2024/05/11 15:53:38 rillig Exp $'
+cvsid='$NetBSD: makeman,v 1.11 2024/06/08 20:47:00 rillig Exp $'
 date="$1"
 year="${date##* }"
 messages="$(list_messages "$2" "")"



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

2024-06-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jun  8 20:47:00 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: makeman

Log Message:
lint.7: abbreviate %lld to %d in the list of messages


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

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/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/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/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/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/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/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/usr.bin/xlint/lint1

2024-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 12 05:44:38 UTC 2024

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

Log Message:
lint: clean up and speed up the check for snprintb


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.634 -r1.635 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/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.13 src/usr.bin/xlint/lint1/cksnprintb.c:1.14
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.13	Fri Apr 12 05:17:48 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Fri Apr 12 05:44:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.13 2024/04/12 05:17:48 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.13 2024/04/12 05:17:48 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.14 2024/04/12 05:44:38 rillig Exp $");
 #endif
 
 #include 
@@ -46,7 +46,7 @@ __RCSID("$NetBSD: cksnprintb.c,v 1.13 20
 typedef struct {
 	bool new_style;
 	const buffer *fmt;
-	const tnode_t *value;
+	uint64_t possible_value_bits;
 
 	quoted_iterator it;
 	uint64_t field_width;
@@ -128,7 +128,7 @@ check_bit(checker *ck, uint64_t dir_lsb,
 		}
 	}
 
-	if (!(possible_bits(ck->value) & field_mask))
+	if (!(ck->possible_value_bits & field_mask))
 		/* conversion '%.*s' is unreachable by input value */
 		warning(378, len, start);
 }
@@ -265,9 +265,8 @@ check_conversion(checker *ck)
 }
 
 void
-check_snprintb(const tnode_t *expr)
+check_snprintb(const function_call *call)
 {
-	const function_call *call = expr->u.call;
 	const char *name;
 	const buffer *fmt;
 	const tnode_t *value;
@@ -287,7 +286,7 @@ check_snprintb(const tnode_t *expr)
 
 	checker ck = {
 		.fmt = fmt,
-		.value = value,
+		.possible_value_bits = possible_bits(value),
 		.field_width = 64,
 	};
 

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.221 src/usr.bin/xlint/lint1/externs1.h:1.222
--- src/usr.bin/xlint/lint1/externs1.h:1.221	Fri Mar 29 08:35:32 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Fri Apr 12 05:44:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.221 2024/03/29 08:35:32 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.222 2024/04/12 05:44:38 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -422,4 +422,4 @@ void check_getopt_end_switch(void);
 void check_getopt_end_while(void);
 
 /* cksnprintb.c */
-void check_snprintb(const tnode_t *);
+void check_snprintb(const function_call *);

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.634 src/usr.bin/xlint/lint1/tree.c:1.635
--- src/usr.bin/xlint/lint1/tree.c:1.634	Sun Mar 31 20:28:45 2024
+++ src/usr.bin/xlint/lint1/tree.c	Fri Apr 12 05:44:38 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.634 2024/03/31 20:28:45 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.634 2024/03/31 20:28:45 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.635 2024/04/12 05:44:38 rillig Exp $");
 #endif
 
 #include 
@@ -4507,7 +4507,10 @@ check_expr_call(const tnode_t *tn, const
 	lint_assert(ln->u.ops.left->tn_op == NAME);
 	if (!szof && !is_compiler_builtin(ln->u.ops.left->u.sym->s_name))
 		outcall(tn, vctx || cond, retval_discarded);
-	check_snprintb(tn);
+
+	const function_call *call = tn->u.call;
+	if (call->args_len == 4 || call->args_len == 5)
+		check_snprintb(call);
 }
 
 static void



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

2024-04-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Apr 12 05:44:38 UTC 2024

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

Log Message:
lint: clean up and speed up the check for snprintb


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.634 -r1.635 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-03-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 31 20:28:45 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md debug.c lint1.h op.h oper.c tree.c

Log Message:
lint: merge function call operators 'CALL' and 'ICALL'


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/README.md
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/oper.c
cvs rdiff -u -r1.633 -r1.634 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/README.md
diff -u src/usr.bin/xlint/lint1/README.md:1.17 src/usr.bin/xlint/lint1/README.md:1.18
--- src/usr.bin/xlint/lint1/README.md:1.17	Thu Mar 28 21:04:48 2024
+++ src/usr.bin/xlint/lint1/README.md	Sun Mar 31 20:28:45 2024
@@ -1,4 +1,4 @@
-[//]: # ($NetBSD: README.md,v 1.17 2024/03/28 21:04:48 rillig Exp $)
+[//]: # ($NetBSD: README.md,v 1.18 2024/03/31 20:28:45 rillig Exp $)
 
 # Introduction
 
@@ -115,8 +115,7 @@ Some examples for operators:
 | NAME | references the identifier in `u.sym`   |
 | UPLUS| the unary operator `+u.ops.left`   |
 | PLUS | the binary operator `u.ops.left + u.ops.right` |
-| CALL | a direct function call |
-| ICALL| an indirect function call  |
+| CALL | a function call|
 | CVT  | an implicit conversion or an explicit cast |
 
 As an example, the expression `strcmp(names[i], "name")` has this internal

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.74 src/usr.bin/xlint/lint1/debug.c:1.75
--- src/usr.bin/xlint/lint1/debug.c:1.74	Tue Mar 19 23:19:03 2024
+++ src/usr.bin/xlint/lint1/debug.c	Sun Mar 31 20:28:45 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.75 2024/03/31 20:28:45 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.75 2024/03/31 20:28:45 rillig Exp $");
 #endif
 
 #include 
@@ -241,7 +241,6 @@ debug_node(const tnode_t *tn) // NOLINT(
 			debug_printf(", length %zu\n", tn->u.str_literals->len);
 		break;
 	case CALL:
-	case ICALL:
 		debug_printf("\n");
 
 		debug_indent_inc();
@@ -259,8 +258,7 @@ debug_node(const tnode_t *tn) // NOLINT(
 		lint_assert(tn->u.ops.left != NULL);
 		debug_node(tn->u.ops.left);
 		if (op != INCBEF && op != INCAFT
-		&& op != DECBEF && op != DECAFT
-		&& op != CALL && op != ICALL)
+		&& op != DECBEF && op != DECAFT)
 			lint_assert(is_binary(tn) == (tn->u.ops.right != NULL));
 		if (tn->u.ops.right != NULL)
 			debug_node(tn->u.ops.right);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.221 src/usr.bin/xlint/lint1/lint1.h:1.222
--- src/usr.bin/xlint/lint1/lint1.h:1.221	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sun Mar 31 20:28:45 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.221 2024/03/09 13:54:47 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.222 2024/03/31 20:28:45 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -290,7 +290,7 @@ struct tnode {
 	 * wide strings, 'data' is NULL and
 	 * 'len' is the number of resulting
 	 * characters */
-		function_call *call;	/* if CALL or ICALL */
+		function_call *call;	/* if CALL */
 	} u;
 };
 

Index: src/usr.bin/xlint/lint1/op.h
diff -u src/usr.bin/xlint/lint1/op.h:1.27 src/usr.bin/xlint/lint1/op.h:1.28
--- src/usr.bin/xlint/lint1/op.h:1.27	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/op.h	Sun Mar 31 20:28:45 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: op.h,v 1.27 2024/02/05 23:11:22 rillig Exp $	*/
+/*	$NetBSD: op.h,v 1.28 2024/03/31 20:28:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -117,7 +117,6 @@ typedef enum {
 	CALL,
 	COMMA,
 	CVT,
-	ICALL,
 	LOAD,
 	RETURN,
 	REAL,

Index: src/usr.bin/xlint/lint1/oper.c
diff -u src/usr.bin/xlint/lint1/oper.c:1.15 src/usr.bin/xlint/lint1/oper.c:1.16
--- src/usr.bin/xlint/lint1/oper.c:1.15	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/oper.c	Sun Mar 31 20:28:45 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: oper.c,v 1.15 2024/02/05 23:11:22 rillig Exp $	*/
+/*	$NetBSD: oper.c,v 1.16 2024/03/31 20:28:45 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -124,7 +124,6 @@ const mod_t modtab[NOPS] = {
 	{_,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_, "call" },
 	{X,_,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,X,X, "," },
 	{_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_,_,X, "convert" },
-	{_,_,_,_,_,_,_,_,_,_,_,X,_,_,_,_,_,_,_,_, "icall" },
 	

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

2024-03-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 31 20:28:45 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md debug.c lint1.h op.h oper.c tree.c

Log Message:
lint: merge function call operators 'CALL' and 'ICALL'


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/README.md
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.221 -r1.222 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/oper.c
cvs rdiff -u -r1.633 -r1.634 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-03-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar 30 19:51:00 UTC 2024

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

Log Message:
lint: document which fields are not reset when starting a new type

Setting all visible fields to their null value seemed as if the whole
object were reset.


To generate a diff of this commit:
cvs rdiff -u -r1.397 -r1.398 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/usr.bin/xlint/lint1

2024-03-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar 30 19:51:00 UTC 2024

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

Log Message:
lint: document which fields are not reset when starting a new type

Setting all visible fields to their null value seemed as if the whole
object were reset.


To generate a diff of this commit:
cvs rdiff -u -r1.397 -r1.398 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/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.397 src/usr.bin/xlint/lint1/decl.c:1.398
--- src/usr.bin/xlint/lint1/decl.c:1.397	Fri Mar 29 08:35:32 2024
+++ src/usr.bin/xlint/lint1/decl.c	Sat Mar 30 19:51:00 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.397 2024/03/29 08:35:32 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.398 2024/03/30 19:51:00 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.397 2024/03/29 08:35:32 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.398 2024/03/30 19:51:00 rillig Exp $");
 #endif
 
 #include 
@@ -589,6 +589,8 @@ dcs_begin_type(void)
 {
 
 	debug_enter();
+
+	// keep d_kind
 	dcs->d_abstract_type = NO_TSPEC;
 	dcs->d_complex_mod = NO_TSPEC;
 	dcs->d_sign_mod = NO_TSPEC;
@@ -596,17 +598,24 @@ dcs_begin_type(void)
 	dcs->d_scl = NO_SCL;
 	dcs->d_type = NULL;
 	dcs->d_redeclared_symbol = NULL;
+	// keep d_sou_size_in_bits
+	// keep d_sou_align_in_bits
 	dcs->d_qual = (type_qualifiers) { .tq_const = false };
 	dcs->d_inline = false;
 	dcs->d_multiple_storage_classes = false;
 	dcs->d_invalid_type_combination = false;
 	dcs->d_nonempty_decl = false;
 	dcs->d_no_type_specifier = false;
+	// keep d_asm
 	dcs->d_packed = false;
 	dcs->d_used = false;
+	// keep d_tag_type
 	dcs->d_func_params = NULL;
 	dcs->d_func_def_pos = (pos_t){ NULL, 0, 0 };
+	// keep d_first_dlsym
+	// keep d_last_dlsym
 	dcs->d_func_proto_syms = NULL;
+	// keep d_enclosing
 }
 
 static void



CVS commit: src/usr.bin/xlint

2024-03-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 29 08:35:32 UTC 2024

Modified Files:
src/usr.bin/xlint: Makefile.inc
src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h func.c init.c lex.c
tree.c

Log Message:
lint: clean up


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/Makefile.inc
cvs rdiff -u -r1.492 -r1.493 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.396 -r1.397 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.185 -r1.186 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.265 -r1.266 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.222 -r1.223 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.628 -r1.629 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

2024-03-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar 29 08:35:32 UTC 2024

Modified Files:
src/usr.bin/xlint: Makefile.inc
src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h func.c init.c lex.c
tree.c

Log Message:
lint: clean up


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/Makefile.inc
cvs rdiff -u -r1.492 -r1.493 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.396 -r1.397 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.185 -r1.186 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.265 -r1.266 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.222 -r1.223 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.628 -r1.629 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/Makefile.inc
diff -u src/usr.bin/xlint/Makefile.inc:1.28 src/usr.bin/xlint/Makefile.inc:1.29
--- src/usr.bin/xlint/Makefile.inc:1.28	Tue Jan 23 19:44:28 2024
+++ src/usr.bin/xlint/Makefile.inc	Fri Mar 29 08:35:31 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.28 2024/01/23 19:44:28 rillig Exp $
+#	$NetBSD: Makefile.inc,v 1.29 2024/03/29 08:35:31 rillig Exp $
 
 .include 
 
@@ -23,9 +23,7 @@ CLEANFILES+=	*.gcno *.gcda *.gcov
 CFLAGS+=	${ACTIVE_CC:Mgcc:%=-ftrapv}
 .endif
 
-.if exists(${.CURDIR}/../../Makefile.inc)
 .include "${.CURDIR}/../../Makefile.inc"
-.endif
 
 LINTFLAGS+=	-aa	# warn about all lossy conversions
 LINTFLAGS+=	-e	# strict enum mode

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.492 src/usr.bin/xlint/lint1/cgram.y:1.493
--- src/usr.bin/xlint/lint1/cgram.y:1.492	Wed Mar 27 21:14:09 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Mar 29 08:35:32 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.492 2024/03/27 21:14:09 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.493 2024/03/29 08:35:32 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.492 2024/03/27 21:14:09 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.493 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include 
@@ -77,7 +77,7 @@ static void
 clear_warning_flags_loc(const char *file, size_t line)
 {
 	debug_step("%s:%zu: clearing flags", file, line);
-	clear_warn_flags();
+	reset_suppressions();
 	saved_lwarn = LWARN_NOTHING_SAVED;
 }
 

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.396 src/usr.bin/xlint/lint1/decl.c:1.397
--- src/usr.bin/xlint/lint1/decl.c:1.396	Sat Mar  9 13:20:55 2024
+++ src/usr.bin/xlint/lint1/decl.c	Fri Mar 29 08:35:32 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.396 2024/03/09 13:20:55 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.397 2024/03/29 08:35:32 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.396 2024/03/09 13:20:55 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.397 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include 
@@ -1072,7 +1072,7 @@ declare_member(sym_t *dsym)
 		rdsym->u.s_member.sm_containing_type) {
 			/* duplicate member name '%s' */
 			error(33, dsym->s_name);
-			rmsym(rdsym);
+			symtab_remove_forever(rdsym);
 		}
 	}
 
@@ -1169,14 +1169,6 @@ block_derive_pointer(type_t *stp, bool i
 	return tp;
 }
 
-/*
- * The following 3 functions extend the type of a declarator with
- * pointer, function and array types.
- *
- * The current type is the type built by dcs_end_type (dcs->d_type) and
- * pointer, function and array types already added for this
- * declarator. The new type extension is inserted between both.
- */
 sym_t *
 add_pointer(sym_t *decl, qual_ptr *p)
 {
@@ -1205,23 +1197,19 @@ add_pointer(sym_t *decl, qual_ptr *p)
 }
 
 static type_t *
-block_derive_array(type_t *stp, bool dim, int len)
+block_derive_array(type_t *stp, bool has_dim, int dim)
 {
 
 	type_t *tp = block_derive_type(stp, ARRAY);
-	tp->u.dimension = len;
+	tp->u.dimension = dim;
 
 #if 0
 	/*
-	 * As of 2022-04-03, the implementation of the type parser (see
-	 * add_function, add_array, add_pointer) is strange.  When it sees the
-	 * type 'void *b[4]', it first creates 'void b[4]' and only later
-	 * inserts the '*' in the middle of the type.  Late modifications like
-	 * these should not be done at all, instead the parser should be fixed
-	 * to process the type names in the proper syntactical order.
-	 *
-	 * Since the intermediate type would be an array of void, but the final
-	 * type is valid, this check cannot be enabled yet.
+	 * When the type of the declaration 'void *b[4]' is constructed (see
+	 * add_function, add_array, add_pointer), the intermediate type
+	 * 'void[4]' is invalid and only later gets the '*' inserted in the
+	 * middle of the type.  Due to the invalid 

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

2024-03-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Mar 27 21:14:09 UTC 2024

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

Log Message:
lint: add missing assignment to $$ in grammar

Byacc and Bison both provide this assignment for all actions, whether
default or not, but the wording in POSIX doesn't guarantee this.


To generate a diff of this commit:
cvs rdiff -u -r1.491 -r1.492 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.491 src/usr.bin/xlint/lint1/cgram.y:1.492
--- src/usr.bin/xlint/lint1/cgram.y:1.491	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Wed Mar 27 21:14:09 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.492 2024/03/27 21:14:09 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.491 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.492 2024/03/27 21:14:09 rillig Exp $");
 #endif
 
 #include 
@@ -651,6 +651,7 @@ argument_expression_list:
 		add_function_argument($$, $1);
 	}
 |	argument_expression_list T_COMMA assignment_expression {
+		$$ = $1;
 		add_function_argument($1, $3);
 	}
 ;



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

2024-03-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Mar 27 21:14:09 UTC 2024

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

Log Message:
lint: add missing assignment to $$ in grammar

Byacc and Bison both provide this assignment for all actions, whether
default or not, but the wording in POSIX doesn't guarantee this.


To generate a diff of this commit:
cvs rdiff -u -r1.491 -r1.492 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-03-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 19 23:19:04 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckctype.c ckgetopt.c debug.c emit1.c tree.c

Log Message:
lint: keep invalid arguments in function calls

Previously, arguments of incomplete type or 'void' cleared all arguments
of the function call expression, requiring extra checks in later checks.

Invalid function calls are now exported to the .ln files, but that's
irrelevant in practice as these invalid function calls make lint1 fail,
after which xlint removes the .ln file.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.624 -r1.625 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/ckctype.c
diff -u src/usr.bin/xlint/lint1/ckctype.c:1.11 src/usr.bin/xlint/lint1/ckctype.c:1.12
--- src/usr.bin/xlint/lint1/ckctype.c:1.11	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/ckctype.c	Tue Mar 19 23:19:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckctype.c,v 1.11 2024/03/09 13:54:47 rillig Exp $ */
+/* $NetBSD: ckctype.c,v 1.12 2024/03/19 23:19:03 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckctype.c,v 1.11 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: ckctype.c,v 1.12 2024/03/19 23:19:03 rillig Exp $");
 #endif
 
 #include 
@@ -123,7 +123,7 @@ void
 check_ctype_function_call(const function_call *call)
 {
 
-	if (call->args_len == 1 && call->args != NULL &&
+	if (call->args_len == 1 &&
 	call->func->tn_op == NAME &&
 	is_ctype_function(call->func->u.sym->s_name))
 		check_ctype_arg(call->func->u.sym->s_name, call->args[0]);

Index: src/usr.bin/xlint/lint1/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.26 src/usr.bin/xlint/lint1/ckgetopt.c:1.27
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.26	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Tue Mar 19 23:19:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.26 2024/03/09 13:54:47 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.27 2024/03/19 23:19:03 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.26 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.27 2024/03/19 23:19:03 rillig Exp $");
 #endif
 
 #include 
@@ -96,8 +96,6 @@ is_getopt_condition(const tnode_t *tn, c
 	&& call->func->u.ops.left->tn_op == NAME
 	&& strcmp(call->func->u.ops.left->u.sym->s_name, "getopt") == 0
 	&& call->args_len == 3
-	&& call->args != NULL
-
 	&& (last_arg = call->args[2]) != NULL
 	&& last_arg->tn_op == CVT
 	&& last_arg->u.ops.left->tn_op == ADDR

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.73 src/usr.bin/xlint/lint1/debug.c:1.74
--- src/usr.bin/xlint/lint1/debug.c:1.73	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/debug.c	Tue Mar 19 23:19:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.73 2024/03/09 13:54:47 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.73 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.74 2024/03/19 23:19:03 rillig Exp $");
 #endif
 
 #include 
@@ -247,11 +247,8 @@ debug_node(const tnode_t *tn) // NOLINT(
 		debug_indent_inc();
 		const function_call *call = tn->u.call;
 		debug_node(call->func);
-		if (call->args != NULL) {
-			for (size_t i = 0; i < call->args_len; i++)
-debug_node(call->args[i]);
-		} else
-			debug_step("error in arguments");
+		for (size_t i = 0, n = call->args_len; i < n; i++)
+			debug_node(call->args[i]);
 		debug_indent_dec();
 		break;
 	default:

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.92 src/usr.bin/xlint/lint1/emit1.c:1.93
--- src/usr.bin/xlint/lint1/emit1.c:1.92	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Tue Mar 19 23:19:03 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.92 2024/03/09 13:54:47 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.93 2024/03/19 23:19:03 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.92 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.93 2024/03/19 23:19:03 rillig Exp $");
 #endif
 
 #include 
@@ -337,9 +337,8 @@ outcall(const tnode_t *tn, bool retval_u
 	 */
 	const function_call *call = tn->u.call;
 
-	/* 

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

2024-03-19 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 19 23:19:04 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckctype.c ckgetopt.c debug.c emit1.c tree.c

Log Message:
lint: keep invalid arguments in function calls

Previously, arguments of incomplete type or 'void' cleared all arguments
of the function call expression, requiring extra checks in later checks.

Invalid function calls are now exported to the .ln files, but that's
irrelevant in practice as these invalid function calls make lint1 fail,
after which xlint removes the .ln file.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.624 -r1.625 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-03-13 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Mar 13 06:48:49 UTC 2024

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

Log Message:
lint: trim down the check for snprintb formats


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/cksnprintb.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/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.10 src/usr.bin/xlint/lint1/cksnprintb.c:1.11
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.10	Sun Mar 10 16:27:16 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Wed Mar 13 06:48:49 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.11 2024/03/13 06:48:49 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.11 2024/03/13 06:48:49 rillig Exp $");
 #endif
 
 #include 
@@ -51,35 +51,10 @@ typedef struct {
 	quoted_iterator it;
 	uint64_t field_width;
 	uint64_t covered;
-	unsigned covered_start[64];
-	unsigned covered_end[64];
+	const char *covered_start[64];
+	int covered_len[64];
 } checker;
 
-static bool
-match_string_literal(const tnode_t *tn, const buffer **str)
-{
-	while (tn->tn_op == CVT)
-		tn = tn->u.ops.left;
-	return tn->tn_op == ADDR
-	&& tn->u.ops.left->tn_op == STRING
-	&& (*str = tn->u.ops.left->u.str_literals, (*str)->data != NULL);
-}
-
-static bool
-match_snprintb_call(const function_call *call,
-const buffer **fmt, const tnode_t **val)
-{
-	const char *func;
-
-	return call->func->tn_op == ADDR
-	&& call->func->u.ops.left->tn_op == NAME
-	&& (func = call->func->u.ops.left->u.sym->s_name, true)
-	&& ((strcmp(func, "snprintb") == 0 && call->args_len == 4)
-		|| (strcmp(func, "snprintb_m") == 0 && call->args_len == 5))
-	&& match_string_literal(call->args[2], fmt)
-	&& (*val = call->args[3], true);
-}
-
 static int
 len(quoted_iterator it)
 {
@@ -126,52 +101,36 @@ check_hex_escape(const buffer *buf, quot
 }
 
 static void
-check_overlap(checker *ck, uint64_t dir_lsb, uint64_t width,
-	  size_t start, size_t end)
+check_bit(checker *ck, uint64_t dir_lsb, uint64_t width,
+	  const char *start, int len)
 {
 	unsigned lsb = (unsigned)(ck->new_style ? dir_lsb : dir_lsb - 1);
 	if (lsb >= 64 || width == 0 || width > 64)
 		return;
 
 	uint64_t field_mask = value_bits((unsigned)width) << lsb;
-	uint64_t overlap = ck->covered & field_mask;
-	if (overlap == 0)
-		goto update_covered;
-
 	for (unsigned i = lsb; i < 64; i++) {
-		if (!(overlap & bit(i)))
-			continue;
-		/* '%.*s' overlaps earlier '%.*s' on bit %u */
-		warning(376,
-		(int)(end - start), ck->fmt->data + start,
-		(int)(ck->covered_end[i] - ck->covered_start[i]),
-		ck->fmt->data + ck->covered_start[i],
-		ck->new_style ? i : i + 1);
-		break;
+		if (ck->covered & field_mask & bit(i)) {
+			/* '%.*s' overlaps earlier '%.*s' on bit %u */
+			warning(376,
+			len, start, ck->covered_len[i],
+			ck->covered_start[i],
+			ck->new_style ? i : i + 1);
+			break;
+		}
 	}
 
-update_covered:
 	ck->covered |= field_mask;
 	for (unsigned i = lsb; i < 64; i++) {
 		if (field_mask & bit(i)) {
-			ck->covered_start[i] = (unsigned)start;
-			ck->covered_end[i] = (unsigned)end;
+			ck->covered_start[i] = start;
+			ck->covered_len[i] = len;
 		}
 	}
-}
-
-static void
-check_reachable(checker *ck, uint64_t dir_lsb, uint64_t width,
-		size_t start, size_t end)
-{
-	unsigned lsb = (unsigned)(ck->new_style ? dir_lsb : dir_lsb - 1);
-	if (lsb >= 64 || width == 0 || width > 64)
-		return;
 
-	uint64_t field_mask = value_bits((unsigned)width) << lsb;
 	if (!(possible_bits(ck->value) & field_mask))
 		/* directive '%.*s' is unreachable by input value */
-		warning(378, (int)(end - start), ck->fmt->data + start);
+		warning(378, len, start);
 }
 
 static bool
@@ -266,45 +225,37 @@ check_directive(checker *ck)
 		check_hex_escape(fmt, bit);
 	if (has_width)
 		check_hex_escape(fmt, width);
-	if (has_bit && bit.octal_digits == 0 && bit.hex_digits == 0) {
+	if (has_bit && bit.octal_digits == 0 && bit.hex_digits == 0)
 		/* bit position '%.*s' in '%.*s' should be escaped as ... */
 		warning(369, len(bit), start(bit, fmt),
 		range(dir, *it), start(dir, fmt));
-	}
-	if (has_width && width.octal_digits == 0 && width.hex_digits == 0) {
+	if (has_width && width.octal_digits == 0 && width.hex_digits == 0)
 		/* field width '%.*s' in '%.*s' should be escaped as ... */
 		warning(370, len(width), start(width, fmt),
 		range(dir, *it), start(dir, fmt));
-	}
-	if (has_bit && (new_style ? bit.value > 63 : bit.value - 1 > 31)) {
+	if (has_bit && (new_style ? bit.value > 63 : bit.value - 1 > 31))
 		/* bit position '%.*s' (%ju) in 

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

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

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

Log Message:
lint: trim down the check for snprintb formats


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/cksnprintb.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-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 16:27:16 UTC 2024

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

Log Message:
lint: clean up tree matcher for snprintb calls


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/cksnprintb.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/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.9 src/usr.bin/xlint/lint1/cksnprintb.c:1.10
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.9	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Sun Mar 10 16:27:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.9 2024/03/09 13:54:47 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.9 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.10 2024/03/10 16:27:16 rillig Exp $");
 #endif
 
 #include 
@@ -67,24 +67,17 @@ match_string_literal(const tnode_t *tn, 
 
 static bool
 match_snprintb_call(const function_call *call,
-const buffer **out_fmt, const tnode_t **out_val)
+const buffer **fmt, const tnode_t **val)
 {
 	const char *func;
-	const tnode_t *val;
-	const buffer *str;
 
-	if (call->func->tn_op == ADDR
+	return call->func->tn_op == ADDR
 	&& call->func->u.ops.left->tn_op == NAME
 	&& (func = call->func->u.ops.left->u.sym->s_name, true)
 	&& ((strcmp(func, "snprintb") == 0 && call->args_len == 4)
 		|| (strcmp(func, "snprintb_m") == 0 && call->args_len == 5))
-	&& match_string_literal(call->args[2], )
-	&& (val = call->args[3], true)) {
-		*out_fmt = str;
-		*out_val = val;
-		return true;
-	}
-	return false;
+	&& match_string_literal(call->args[2], fmt)
+	&& (*val = call->args[3], true);
 }
 
 static int



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

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

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

Log Message:
lint: clean up tree matcher for snprintb calls


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/cksnprintb.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-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 14:42:04 UTC 2024

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

Log Message:
lint: clean up check for overflow in integer constants


To generate a diff of this commit:
cvs rdiff -u -r1.619 -r1.620 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-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 14:42:04 UTC 2024

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

Log Message:
lint: clean up check for overflow in integer constants


To generate a diff of this commit:
cvs rdiff -u -r1.619 -r1.620 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.619 src/usr.bin/xlint/lint1/tree.c:1.620
--- src/usr.bin/xlint/lint1/tree.c:1.619	Sun Mar 10 14:32:30 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sun Mar 10 14:42:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.619 2024/03/10 14:32:30 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.620 2024/03/10 14:42:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.619 2024/03/10 14:32:30 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.620 2024/03/10 14:42:04 rillig Exp $");
 #endif
 
 #include 
@@ -795,30 +795,26 @@ fold_unsigned_integer(op_t op, uint64_t 
 	case COMPL:
 		return ~l;
 	case UPLUS:
-		return l;
+		return +l;
 	case UMINUS:
 		return -l;
-	case MULT:;
-		uint64_t mult_result = l * r;
-		if (mult_result != (mult_result & max_value))
-			*overflow = true;
-		else if (l != 0 && mult_result / l != r)
-			*overflow = true;
-		return mult_result;
+	case MULT:
+		*overflow = r > 0 && l > max_value / r;
+		return l * r;
 	case DIV:
 		if (r == 0) {
 			/* division by 0 */
 			error(139);
 			return max_value;
-		} else
-			return l / r;
+		}
+		return l / r;
 	case MOD:
 		if (r == 0) {
 			/* modulus by 0 */
 			error(140);
 			return 0;
-		} else
-			return l % r;
+		}
+		return l % r;
 	case PLUS:
 		*overflow = l > max_value - r;
 		return l + r;
@@ -827,6 +823,7 @@ fold_unsigned_integer(op_t op, uint64_t 
 		return l - r;
 	case SHL:
 		/* TODO: warn about out-of-bounds 'sr'. */
+		/* TODO: warn about overflow. */
 		return l << (r & 63);
 	case SHR:
 		/* TODO: warn about out-of-bounds 'sr'. */
@@ -851,8 +848,8 @@ fold_unsigned_integer(op_t op, uint64_t 
 		return l | r;
 	default:
 		lint_assert(/*CONSTCOND*/false);
+		/* NOTREACHED */
 	}
-	/* NOTREACHED */
 }
 
 static int64_t
@@ -863,7 +860,7 @@ fold_signed_integer(op_t op, int64_t l, 
 	case COMPL:
 		return ~l;
 	case UPLUS:
-		return l;
+		return +l;
 	case UMINUS:
 		*overflow = l == min_value;
 		return *overflow ? l : -l;
@@ -876,12 +873,7 @@ fold_signed_integer(op_t op, int64_t l, 
 			*overflow = true;
 			return (int64_t)(al * ar);
 		}
-		uint64_t mult_result = l * r;
-		uint64_t hi = (uint64_t)max_value + 1;
-		// FIXME: Overflow can also happen in other bits.
-		if ((mult_result & hi) != ((l & hi) ^ (r & hi)))
-			*overflow = true;
-		return (int64_t)mult_result;
+		return l * r;
 	case DIV:
 		if (r == 0) {
 			/* division by 0 */
@@ -926,9 +918,10 @@ fold_signed_integer(op_t op, int64_t l, 
 		return l - r;
 	case SHL:
 		/* TODO: warn about out-of-bounds 'sr'. */
-		/* TODO: warn about overflow in signed '<<'. */
+		/* TODO: warn about overflow. */
 		return l << (r & 63);
 	case SHR:;
+		/* TODO: warn about out-of-bounds 'sr'. */
 		uint64_t shr_result = (uint64_t)l >> (r & 63);
 		if (shr_result & min_value)
 			shr_result |= min_value;
@@ -953,8 +946,8 @@ fold_signed_integer(op_t op, int64_t l, 
 		return l | r;
 	default:
 		lint_assert(/*CONSTCOND*/false);
+		/* NOTREACHED */
 	}
-	/* NOTREACHED */
 }
 
 /*



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

2024-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 12:50:46 UTC 2024

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

Log Message:
lint: split integer overflow check into separate functions

The checks for unsigned and signed integers differ for each operator, so
there's no point having both parts in the same function.


To generate a diff of this commit:
cvs rdiff -u -r1.617 -r1.618 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-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 12:50:46 UTC 2024

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

Log Message:
lint: split integer overflow check into separate functions

The checks for unsigned and signed integers differ for each operator, so
there's no point having both parts in the same function.


To generate a diff of this commit:
cvs rdiff -u -r1.617 -r1.618 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.617 src/usr.bin/xlint/lint1/tree.c:1.618
--- src/usr.bin/xlint/lint1/tree.c:1.617	Sun Mar 10 10:31:29 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sun Mar 10 12:50:45 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.617 2024/03/10 10:31:29 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.618 2024/03/10 12:50:45 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.617 2024/03/10 10:31:29 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.618 2024/03/10 12:50:45 rillig Exp $");
 #endif
 
 #include 
@@ -787,147 +787,206 @@ build_address(bool sys, tnode_t *tn, boo
 	tn, NULL);
 }
 
-/*
- * XXX
- * Note: There appear to be a number of bugs in detecting overflow in
- * this function. An audit and a set of proper regression tests are needed.
- * --Perry Metzger, Nov. 16, 2001
- */
-static tnode_t *
-fold_constant_integer(tnode_t *tn)
+static uint64_t
+fold_unsigned_integer(op_t op, uint64_t l, uint64_t r,
+		  uint64_t max_value, bool *overflow)
 {
-
-	lint_assert(has_operands(tn));
-	tspec_t t = tn->u.ops.left->tn_type->t_tspec;
-	bool utyp = !is_integer(t) || is_uinteger(t);
-	int64_t sl = tn->u.ops.left->u.value.u.integer, sr = 0;
-	uint64_t ul = sl, ur = 0;
-	if (is_binary(tn))
-		ur = sr = tn->u.ops.right->u.value.u.integer;
-
-	uint64_t mask = value_bits(size_in_bits(t));
-	int64_t max_value = (int64_t)(mask >> 1);
-	int64_t min_value = -max_value - 1;
-	bool ovfl = false;
-
-	int64_t si;
-	switch (tn->tn_op) {
+	switch (op) {
 	case COMPL:
-		si = ~sl;
-		break;
+		return ~l;
 	case UPLUS:
-		si = sl;
-		break;
+		return l;
 	case UMINUS:
-		if (utyp)
-			si = (int64_t)-ul;
-		else {
-			ovfl = sl == min_value;
-			si = ovfl ? sl : -sl;
-		}
-		break;
-	case MULT:
-		if (utyp) {
-			si = (int64_t)(ul * ur);
-			if (si != (si & (int64_t)mask))
-ovfl = true;
-			else if (ul != 0 && si / ul != ur)
-ovfl = true;
-		} else {
-			uint64_t al = sl >= 0 ? ul : -ul;
-			uint64_t ar = sr >= 0 ? ur : -ur;
-			bool neg = (sl >= 0) != (sr >= 0);
-			uint64_t max_prod = (uint64_t)max_value
-			+ (neg ? 1 : 0);
-			if (al > 0 && ar > max_prod / al) {
-si = (int64_t)(al * ar);
-ovfl = true;
-			} else
-si = sl * sr;
-			if (msb(si, t) != (msb(sl, t) ^ msb(sr, t)))
-ovfl = true;
-		}
-		break;
+		return -l;
+	case MULT:;
+		uint64_t mult_result = l * r;
+		if (mult_result != (mult_result & max_value))
+			*overflow = true;
+		else if (l != 0 && mult_result / l != r)
+			*overflow = true;
+		return mult_result;
 	case DIV:
-		if (sr == 0) {
+		if (r == 0) {
 			/* division by 0 */
 			error(139);
-			si = utyp ? -1 : max_value;
-		} else if (!utyp && sl == min_value && sr == -1) {
-			ovfl = true;
-			si = sl;
+			return max_value;
 		} else
-			si = utyp ? (int64_t)(ul / ur) : sl / sr;
-		break;
+			return l / r;
 	case MOD:
-		if (sr == 0) {
+		if (r == 0) {
 			/* modulus by 0 */
 			error(140);
-			si = 0;
-		} else if (!utyp && sl == min_value && sr == -1) {
-			ovfl = true;
-			si = 0;
+			return 0;
 		} else
-			si = utyp ? (int64_t)(ul % ur) : sl % sr;
-		break;
-	case PLUS:
-		si = (int64_t)(ul + ur);
-		if (msb(sl, t) && msb(sr, t) && !msb(si, t))
-			ovfl = true;
-		if (!utyp && !msb(sl, t) && !msb(sr, t) && msb(si, t))
-			ovfl = true;
-		break;
-	case MINUS:
-		si = (int64_t)(ul - ur);
-		if (!utyp && msb(sl, t) && !msb(sr, t) && !msb(si, t))
-			ovfl = true;
-		if (!msb(sl, t) && msb(sr, t) && msb(si, t))
-			ovfl = true;
-		break;
+			return l % r;
+	case PLUS:;
+		uint64_t plus_result = l + r;
+		uint64_t hi = max_value ^ (max_value >> 1);
+		if (l & hi && r & hi && !(plus_result & hi))
+			*overflow = true;
+		return plus_result;
+	case MINUS:;
+		uint64_t minus_result = l - r;
+		hi = max_value ^ (max_value >> 1);
+		if (!(l & hi) && r & hi && minus_result & hi)
+			*overflow = true;
+		return minus_result;
 	case SHL:
 		/* TODO: warn about out-of-bounds 'sr'. */
-		/* TODO: warn about overflow in signed '<<'. */
-		si = utyp ? (int64_t)(ul << (sr & 63)) : sl << (sr & 63);
-		break;
+		return l << (r & 63);
 	case SHR:
-		/*
-		 * The sign must be explicitly extended because shifts of
-		 * signed values are implementation dependent.
-		 */
 		/* TODO: warn about out-of-bounds 'sr'. */
-		si = (int64_t)(ul >> (sr & 63));
-		si = convert_integer(si, t, 

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

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

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

Log Message:
lint: in check for integer overflow, sort operators


To generate a diff of this commit:
cvs rdiff -u -r1.614 -r1.615 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-03-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Mar 10 09:24:54 UTC 2024

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

Log Message:
lint: in check for integer overflow, sort operators


To generate a diff of this commit:
cvs rdiff -u -r1.614 -r1.615 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.614 src/usr.bin/xlint/lint1/tree.c:1.615
--- src/usr.bin/xlint/lint1/tree.c:1.614	Sat Mar  9 23:55:11 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sun Mar 10 09:24:54 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.615 2024/03/10 09:24:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.614 2024/03/09 23:55:11 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.615 2024/03/10 09:24:54 rillig Exp $");
 #endif
 
 #include 
@@ -815,6 +815,9 @@ fold_constant_integer(tnode_t *tn)
 
 	int64_t si;
 	switch (tn->tn_op) {
+	case COMPL:
+		si = ~sl;
+		break;
 	case UPLUS:
 		si = sl;
 		break;
@@ -823,9 +826,6 @@ fold_constant_integer(tnode_t *tn)
 		if (sl != 0 && msb(si, t) == msb(sl, t))
 			ovfl = true;
 		break;
-	case COMPL:
-		si = ~sl;
-		break;
 	case MULT:
 		if (utyp) {
 			si = (int64_t)(ul * ur);
@@ -892,12 +892,12 @@ fold_constant_integer(tnode_t *tn)
 	case LE:
 		si = (utyp ? ul <= ur : sl <= sr) ? 1 : 0;
 		break;
-	case GE:
-		si = (utyp ? ul >= ur : sl >= sr) ? 1 : 0;
-		break;
 	case GT:
 		si = (utyp ? ul > ur : sl > sr) ? 1 : 0;
 		break;
+	case GE:
+		si = (utyp ? ul >= ur : sl >= sr) ? 1 : 0;
+		break;
 	case EQ:
 		si = (utyp ? ul == ur : sl == sr) ? 1 : 0;
 		break;



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

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 14:54:14 UTC 2024

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

Log Message:
lint: merge duplicate code for checking array index


To generate a diff of this commit:
cvs rdiff -u -r1.612 -r1.613 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.612 src/usr.bin/xlint/lint1/tree.c:1.613
--- src/usr.bin/xlint/lint1/tree.c:1.612	Sat Mar  9 13:54:47 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sat Mar  9 14:54:14 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.612 2024/03/09 13:54:47 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.612 2024/03/09 13:54:47 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.613 2024/03/09 14:54:14 rillig Exp $");
 #endif
 
 #include 
@@ -4327,52 +4327,37 @@ expr(tnode_t *tn, bool vctx, bool cond, 
 		expr_free_all();
 }
 
-/*
- * Checks the range of array indices, if possible.
- * amper is set if only the address of the element is used. This
- * means that the index is allowed to refer to the first element
- * after the array.
- */
+/* If the expression has the form '*(arr + idx)', check the array index. */
 static void
-check_array_index(tnode_t *tn, bool amper)
+check_array_index(const tnode_t *indir, bool taking_address)
 {
-	lint_assert(has_operands(tn));
-	const tnode_t *ln = tn->u.ops.left;
-	const tnode_t *rn = tn->u.ops.right;
-
-	/* We can only check constant indices. */
-	if (rn->tn_op != CON)
-		return;
-
-	/* Return if the left node does not stem from an array. */
-	if (ln->tn_op != ADDR)
-		return;
-	if (ln->u.ops.left->tn_op != STRING && ln->u.ops.left->tn_op != NAME)
-		return;
-	if (ln->u.ops.left->tn_type->t_tspec != ARRAY)
-		return;
+	const tnode_t *plus, *arr, *idx;
 
-	/*
-	 * For incomplete array types, we can print a warning only if the index
-	 * is negative.
-	 */
-	if (is_incomplete(ln->u.ops.left->tn_type)
-	&& rn->u.value.u.integer >= 0)
-		return;
+	if (indir->tn_op == INDIR
+	&& (plus = indir->u.ops.left, plus->tn_op == PLUS)
+	&& plus->u.ops.left->tn_op == ADDR
+	&& (arr = plus->u.ops.left->u.ops.left, true)
+	&& (arr->tn_op == STRING || arr->tn_op == NAME)
+	&& arr->tn_type->t_tspec == ARRAY
+	&& (idx = plus->u.ops.right, idx->tn_op == CON)
+	&& (!is_incomplete(arr->tn_type) || idx->u.value.u.integer < 0))
+		goto proceed;
+	return;
 
-	int elsz = length_in_bits(ln->tn_type->t_subt, NULL);
+proceed:;
+	int elsz = length_in_bits(arr->tn_type->t_subt, NULL);
 	if (elsz == 0)
 		return;
 	elsz /= CHAR_SIZE;
 
 	/* Change the unit of the index from bytes to element size. */
-	int64_t con = is_uinteger(rn->tn_type->t_tspec)
-	? (int64_t)((uint64_t)rn->u.value.u.integer / elsz)
-	: rn->u.value.u.integer / elsz;
+	int64_t con = is_uinteger(idx->tn_type->t_tspec)
+	? (int64_t)((uint64_t)idx->u.value.u.integer / elsz)
+	: idx->u.value.u.integer / elsz;
 
-	int dim = ln->u.ops.left->tn_type->u.dimension + (amper ? 1 : 0);
+	int dim = arr->tn_type->u.dimension + (taking_address ? 1 : 0);
 
-	if (!is_uinteger(rn->tn_type->t_tspec) && con < 0)
+	if (!is_uinteger(idx->tn_type->t_tspec) && con < 0)
 		/* array subscript cannot be negative: %ld */
 		warning(167, (long)con);
 	else if (dim > 0 && (uint64_t)con >= (uint64_t)dim)
@@ -4389,15 +4374,7 @@ check_expr_addr(const tnode_t *ln, bool 
 			mark_as_set(ln->u.sym);
 		mark_as_used(ln->u.sym, fcall, szof);
 	}
-	if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS)
-		check_array_index(ln->u.ops.left, true);
-}
-
-static void
-check_expr_load(const tnode_t *ln)
-{
-	if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS)
-		check_array_index(ln->u.ops.left, false);
+	check_array_index(ln, true);
 }
 
 /*
@@ -4439,9 +4416,7 @@ check_expr_assign(const tnode_t *ln, boo
 		if (ln->u.sym->s_scl == EXTERN)
 			outusg(ln->u.sym);
 	}
-	if (ln->tn_op == INDIR && ln->u.ops.left->tn_op == PLUS)
-		/* check the range of array indices */
-		check_array_index(ln->u.ops.left, false);
+	check_array_index(ln, false);
 }
 
 static void
@@ -4463,7 +4438,7 @@ check_expr_op(op_t op, const tnode_t *ln
 		check_expr_addr(ln, szof, fcall);
 		break;
 	case LOAD:
-		check_expr_load(ln);
+		check_array_index(ln, false);
 		/* FALLTHROUGH */
 	case INCBEF:
 	case DECBEF:



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

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 14:54:14 UTC 2024

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

Log Message:
lint: merge duplicate code for checking array index


To generate a diff of this commit:
cvs rdiff -u -r1.612 -r1.613 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-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:54:47 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md cgram.y ckbool.c ckctype.c
ckgetopt.c cksnprintb.c debug.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for tnode_t


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/README.md
cvs rdiff -u -r1.490 -r1.491 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.183 -r1.184 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.262 -r1.263 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.611 -r1.612 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-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:54:47 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md cgram.y ckbool.c ckctype.c
ckgetopt.c cksnprintb.c debug.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for tnode_t


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/README.md
cvs rdiff -u -r1.490 -r1.491 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.183 -r1.184 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.262 -r1.263 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.611 -r1.612 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/README.md
diff -u src/usr.bin/xlint/lint1/README.md:1.15 src/usr.bin/xlint/lint1/README.md:1.16
--- src/usr.bin/xlint/lint1/README.md:1.15	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/README.md	Sat Mar  9 13:54:47 2024
@@ -1,4 +1,4 @@
-[//]: # ($NetBSD: README.md,v 1.15 2024/02/05 23:11:22 rillig Exp $)
+[//]: # ($NetBSD: README.md,v 1.16 2024/03/09 13:54:47 rillig Exp $)
 
 # Introduction
 
@@ -108,15 +108,15 @@ Each node has an operator that defines w
 The operators and their properties are defined in `oper.c`.
 Some examples for operators:
 
-| Operator | Meaning|
-|--||
-| CON  | compile-time constant in `tn_val`  |
-| NAME | references the identifier in `tn_sym`  |
-| UPLUS| the unary operator `+tn_left`  |
-| PLUS | the binary operator `tn_left + tn_right`   |
-| CALL | a direct function call |
-| ICALL| an indirect function call  |
-| CVT  | an implicit conversion or an explicit cast |
+| Operator | Meaning|
+|--||
+| CON  | compile-time constant in `u.value` |
+| NAME | references the identifier in `u.sym`   |
+| UPLUS| the unary operator `+u.ops.left`   |
+| PLUS | the binary operator `u.ops.left + u.ops.right` |
+| CALL | a direct function call |
+| ICALL| an indirect function call  |
+| CVT  | an implicit conversion or an explicit cast |
 
 As an example, the expression `strcmp(names[i], "name")` has this internal
 structure:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.490 src/usr.bin/xlint/lint1/cgram.y:1.491
--- src/usr.bin/xlint/lint1/cgram.y:1.490	Sat Mar  9 10:41:11 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Mar  9 13:54:47 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 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.490 2024/03/09 10:41:11 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.491 2024/03/09 13:54:47 rillig Exp $");
 #endif
 
 #include 
@@ -625,7 +625,7 @@ gcc_statement_expr_item:
 		} else {
 			/* XXX: do that only on the last name */
 			if ($1->tn_op == NAME)
-$1->tn_sym->s_used = true;
+$1->u.sym->s_used = true;
 			expr($1, false, false, false, false);
 			suppress_fallthrough = false;
 			$$ = $1;

Index: src/usr.bin/xlint/lint1/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.29 src/usr.bin/xlint/lint1/ckbool.c:1.30
--- src/usr.bin/xlint/lint1/ckbool.c:1.29	Sat Feb  3 12:57:12 2024
+++ src/usr.bin/xlint/lint1/ckbool.c	Sat Mar  9 13:54:47 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.30 2024/03/09 13:54:47 rillig Exp $");
 #endif
 
 #include 
@@ -73,7 +73,7 @@ is_symmetric_bool_or_other(op_t op)
 static bool
 is_int_constant_zero(const tnode_t *tn, tspec_t t)
 {
-	return t == INT && tn->tn_op == CON && tn->tn_val.u.integer == 0;
+	return t == INT && tn->tn_op == CON && tn->u.value.u.integer == 0;
 }
 
 static bool
@@ -201,7 +201,7 @@ bool
 is_typeok_bool_compares_with_zero(const tnode_t 

CVS commit: src/usr.bin/xlint

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:20:55 UTC 2024

Modified Files:
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: debug.c decl.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for type_t


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.395 -r1.396 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.182 -r1.183 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.610 -r1.611 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/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.61 src/usr.bin/xlint/common/tyname.c:1.62
--- src/usr.bin/xlint/common/tyname.c:1.61	Fri Feb  2 16:25:58 2024
+++ src/usr.bin/xlint/common/tyname.c	Sat Mar  9 13:20:55 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tyname.c,v 1.61 2024/02/02 16:25:58 rillig Exp $	*/
+/*	$NetBSD: tyname.c,v 1.62 2024/03/09 13:20:55 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tyname.c,v 1.61 2024/02/02 16:25:58 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.62 2024/03/09 13:20:55 rillig Exp $");
 #endif
 
 #include 
@@ -165,7 +165,7 @@ type_name_of_function(buffer *buf, const
 	buf_add(buf, "(");
 	if (tp->t_proto) {
 #if IS_LINT1
-		const sym_t *param = tp->t_params;
+		const sym_t *param = tp->u.params;
 		if (param == NULL)
 			buf_add(buf, "void");
 		for (; param != NULL; param = param->s_next) {
@@ -197,12 +197,12 @@ type_name_of_struct_or_union(buffer *buf
 {
 	buf_add(buf, " ");
 #if IS_LINT1
-	if (tp->t_sou->sou_tag->s_name == unnamed &&
-	tp->t_sou->sou_first_typedef != NULL) {
+	if (tp->u.sou->sou_tag->s_name == unnamed &&
+	tp->u.sou->sou_first_typedef != NULL) {
 		buf_add(buf, "typedef ");
-		buf_add(buf, tp->t_sou->sou_first_typedef->s_name);
+		buf_add(buf, tp->u.sou->sou_first_typedef->s_name);
 	} else {
-		buf_add(buf, tp->t_sou->sou_tag->s_name);
+		buf_add(buf, tp->u.sou->sou_tag->s_name);
 	}
 #else
 	buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
@@ -214,12 +214,12 @@ type_name_of_enum(buffer *buf, const typ
 {
 	buf_add(buf, " ");
 #if IS_LINT1
-	if (tp->t_enum->en_tag->s_name == unnamed &&
-	tp->t_enum->en_first_typedef != NULL) {
+	if (tp->u.enumer->en_tag->s_name == unnamed &&
+	tp->u.enumer->en_first_typedef != NULL) {
 		buf_add(buf, "typedef ");
-		buf_add(buf, tp->t_enum->en_first_typedef->s_name);
+		buf_add(buf, tp->u.enumer->en_first_typedef->s_name);
 	} else {
-		buf_add(buf, tp->t_enum->en_tag->s_name);
+		buf_add(buf, tp->u.enumer->en_tag->s_name);
 	}
 #else
 	buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
@@ -234,7 +234,7 @@ type_name_of_array(buffer *buf, const ty
 	if (tp->t_incomplete_array)
 		buf_add(buf, "unknown_size");
 	else
-		buf_add_int(buf, tp->t_dim);
+		buf_add_int(buf, tp->u.dimension);
 #else
 	buf_add_int(buf, tp->t_dim);
 #endif
@@ -263,7 +263,7 @@ type_name(const type_t *tp)
 		buf_add(, "volatile ");
 
 #if IS_LINT1
-	if (is_struct_or_union(t) && tp->t_sou->sou_incomplete)
+	if (is_struct_or_union(t) && tp->u.sou->sou_incomplete)
 		buf_add(, "incomplete ");
 #endif
 	buf_add(, tspec_name(t));

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.71 src/usr.bin/xlint/lint1/debug.c:1.72
--- src/usr.bin/xlint/lint1/debug.c:1.71	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/debug.c	Sat Mar  9 13:20:55 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.71 2024/02/05 23:11:22 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.72 2024/03/09 13:20:55 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.71 2024/02/05 23:11:22 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.72 2024/03/09 13:20:55 rillig Exp $");
 #endif
 
 #include 
@@ -156,10 +156,10 @@ 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->t_sou->sou_size_in_bits, tp->t_sou->sou_align_in_bits,
-		tp->t_sou->sou_incomplete ? "incomplete" : "complete");
+		tp->u.sou->sou_size_in_bits, tp->u.sou->sou_align_in_bits,
+		tp->u.sou->sou_incomplete ? "incomplete" : "complete");
 
-		for (const sym_t *mem = tp->t_sou->sou_first_member;
+		for (const sym_t *mem = tp->u.sou->sou_first_member;
 		mem != NULL; mem = mem->s_next) {
 			debug_sym("", mem, "\n");
 			debug_type_details(mem->s_type);
@@ -168,7 +168,7 @@ 

CVS commit: src/usr.bin/xlint

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 13:20:55 UTC 2024

Modified Files:
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: debug.c decl.c emit1.c func.c init.c lint1.h
tree.c

Log Message:
lint: inline accessor macros for type_t


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.395 -r1.396 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.182 -r1.183 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.610 -r1.611 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-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 11:05:05 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lint1.h

Log Message:
lint: clean up comments, use typedefs


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 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/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.218 src/usr.bin/xlint/lint1/lint1.h:1.219
--- src/usr.bin/xlint/lint1/lint1.h:1.218	Sat Mar  9 10:54:12 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Mar  9 11:05:05 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.218 2024/03/09 10:54:12 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.219 2024/03/09 11:05:05 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -71,19 +71,6 @@ typedef struct {
 	int	p_uniq;			/* uniquifier */
 } pos_t;
 
-// TODO: Use bit-fields instead of plain bool, but keep an eye on arm and
-// powerpc, on which NetBSD's GCC 10.5.0 (but not the upstream GCC) generates
-// code that leads to extra 327 warnings, even in msg_327.c, which does not
-// contain any type qualifier at all.
-//
-// A possible starting point for continuing the investigation is that
-// type_qualifiers is a very small struct that contains only bool bit-fields,
-// and this struct is a member of the parser's union.
-//
-// Instead of using plain bool instead of bit-fields, an alternative workaround
-// is to compile cgram.c with -Os or -O1 instead of -O2.  The generated code
-// between -Os and -O2 differs too much though to give a hint at the root
-// cause.
 typedef struct {
 	bool tq_const;
 	bool tq_restrict;
@@ -128,9 +115,7 @@ typedef struct {
 	sym_t	*sou_first_typedef;
 } struct_or_union;
 
-/*
- * same as above for enums
- */
+/* The same as in struct_or_union, only for enums. */
 typedef struct {
 	bool	en_incomplete:1;
 	sym_t	*en_first_enumerator;
@@ -138,28 +123,21 @@ typedef struct {
 	sym_t	*en_first_typedef;
 } enumeration;
 
-/*
- * The type of an expression or object. Complex types are formed via t_subt
- * (for arrays, pointers and functions), as well as t_sou.
- */
+/* The type of an expression, object or function. */
 struct lint1_type {
 	tspec_t	t_tspec;	/* type specifier */
 	bool	t_incomplete_array:1;
-	bool	t_const:1;	/* const modifier */
-	bool	t_volatile:1;	/* volatile modifier */
+	bool	t_const:1;
+	bool	t_volatile:1;
 	bool	t_proto:1;	/* function prototype (t_params valid) */
 	bool	t_vararg:1;	/* prototype with '...' */
 	bool	t_typedef:1;	/* type defined with typedef */
 	bool	t_typeof:1;	/* type defined with GCC's __typeof__ */
 	bool	t_bitfield:1;
 	/*
-	 * Either the type is currently an enum (having t_tspec ENUM), or it is
-	 * an integer type (typically INT) that has been implicitly converted
-	 * from an enum type.  In both cases, t_enum is valid.
-	 *
-	 * The information about a former enum type is retained to allow type
-	 * checks in expressions such as ((var1 & 0x0001) == var2), to detect
-	 * when var1 and var2 are from incompatible enum types.
+	 * Either the type is currently an enum (having t_tspec ENUM), or it
+	 * is an integer type (typically INT) that has been implicitly
+	 * converted from an enum type.  In both cases, t_enum is valid.
 	 */
 	bool	t_is_enum:1;
 	bool	t_packed:1;
@@ -179,7 +157,7 @@ struct lint1_type {
 #define	t_dim	t_u._t_dim
 #define	t_sou	t_u._t_sou
 #define	t_enum	t_u._t_enum
-#define	t_params	t_u._t_params
+#define	t_params t_u._t_params
 
 
 typedef enum {
@@ -189,16 +167,14 @@ typedef enum {
 	SK_LABEL
 } symbol_kind;
 
-/*
- * storage classes and related things
- */
+/* storage classes and related things */
 typedef enum {
 	NO_SCL,
 	EXTERN,			/* external symbols (independent of decl_t) */
 	STATIC,			/* static symbols (local and global) */
 	AUTO,			/* automatic symbols (except register) */
 	REG,			/* register */
-	TYPEDEF,		/* typedef */
+	TYPEDEF,
 	THREAD_LOCAL,
 	STRUCT_TAG,
 	UNION_TAG,
@@ -217,9 +193,7 @@ typedef enum {
 	FS_NORETURN,		/* since C11 */
 } function_specifier;
 
-/*
- * symbol table entry
- */
+/* A type, variable, keyword; basically anything that has a name. */
 struct sym {
 	const char *s_name;
 	const char *s_rename;	/* renamed symbol's given name */
@@ -232,26 +206,26 @@ struct sym {
 	symbol_kind s_kind;
 	const struct keyword *s_keyword;
 	bool	s_bitfield:1;
-	bool	s_set:1;	/* variable set, label defined */
-	bool	s_used:1;	/* variable/label used */
-	bool	s_param:1;	/* symbol is function parameter */
-	bool	s_register:1;	/* symbol is register variable */
+	bool	s_set:1;
+	bool	s_used:1;
+	bool	s_param:1;
+	bool	s_register:1;
 	bool	s_defparam:1;	/* undefined symbol in old-style function
  * definition */
 	bool	s_return_type_implicit_int:1;
 	bool	s_osdef:1;	/* symbol stems from old-style function def. */
-	bool	s_inline:1;	/* true if this is an inline function */
-	struct 

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

2024-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 11:05:05 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: lint1.h

Log Message:
lint: clean up comments, use typedefs


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 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/usr.bin/xlint/lint1

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

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

Log Message:
lint: internally store case label values in order of appearance


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.217 -r1.218 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/usr.bin/xlint/lint1

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

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

Log Message:
lint: internally store case label values in order of appearance


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.217 -r1.218 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/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.181 src/usr.bin/xlint/lint1/func.c:1.182
--- src/usr.bin/xlint/lint1/func.c:1.181	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/func.c	Sat Mar  9 10:54:12 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.181 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $");
 #endif
 
 #include 
@@ -162,12 +162,7 @@ end_control_statement(control_statement_
 	control_statement *cs = cstmt;
 	cstmt = cs->c_surrounding;
 
-	case_label_t *cl, *next;
-	for (cl = cs->c_case_labels; cl != NULL; cl = next) {
-		next = cl->cl_next;
-		free(cl);
-	}
-
+	free(cs->c_case_labels.vals);
 	free(cs->c_switch_type);
 	free(cs);
 }
@@ -436,6 +431,34 @@ check_case_label_enum(const tnode_t *tn,
 #endif
 }
 
+static bool
+check_duplicate_case_label(control_statement *cs, const val_t *nv)
+{
+	case_labels *labels = >c_case_labels;
+	size_t i = 0, n = labels->len;
+
+	while (i < n && labels->vals[i].u.integer != nv->u.integer)
+		i++;
+
+	if (i < n) {
+		if (is_uinteger(nv->v_tspec))
+			/* duplicate case '%lu' in switch */
+			error(200, (unsigned long)nv->u.integer);
+		else
+			/* duplicate case '%ld' in switch */
+			error(199, (long)nv->u.integer);
+		return false;
+	}
+
+	if (labels->len >= labels->cap) {
+		labels->cap = 16 + 2 * labels->cap;
+		labels->vals = xrealloc(labels->vals,
+		sizeof(*labels->vals) * labels->cap);
+	}
+	labels->vals[labels->len++] = *nv;
+	return true;
+}
+
 static void
 check_case_label(tnode_t *tn)
 {
@@ -487,27 +510,8 @@ check_case_label(tnode_t *tn)
 	convert_constant(CASE, 0, cs->c_switch_type, , v);
 	free(v);
 
-	/* look if we had this value already */
-	case_label_t *cl;
-	for (cl = cs->c_case_labels; cl != NULL; cl = cl->cl_next) {
-		if (cl->cl_val.u.integer == nv.u.integer)
-			break;
-	}
-	if (cl != NULL && is_uinteger(nv.v_tspec))
-		/* duplicate case '%lu' in switch */
-		error(200, (unsigned long)nv.u.integer);
-	else if (cl != NULL)
-		/* duplicate case '%ld' in switch */
-		error(199, (long)nv.u.integer);
-	else {
+	if (check_duplicate_case_label(cs, ))
 		check_getopt_case_label(nv.u.integer);
-
-		/* Prepend the value to the list of case values. */
-		cl = xcalloc(1, sizeof(*cl));
-		cl->cl_val = nv;
-		cl->cl_next = cs->c_case_labels;
-		cs->c_case_labels = cl;
-	}
 }
 
 void
@@ -660,7 +664,6 @@ stmt_switch_expr_stmt(void)
 {
 	int nenum = 0, nclab = 0;
 	sym_t *esym;
-	case_label_t *cl;
 
 	lint_assert(cstmt->c_switch_type != NULL);
 
@@ -675,8 +678,7 @@ stmt_switch_expr_stmt(void)
 		esym != NULL; esym = esym->s_next) {
 			nenum++;
 		}
-		for (cl = cstmt->c_case_labels; cl != NULL; cl = cl->cl_next)
-			nclab++;
+		nclab = (int)cstmt->c_case_labels.len;
 		if (hflag && eflag && nclab < nenum && !cstmt->c_default)
 			/* enumeration value(s) not handled in switch */
 			warning(206);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.217 src/usr.bin/xlint/lint1/lint1.h:1.218
--- src/usr.bin/xlint/lint1/lint1.h:1.217	Sat Mar  9 10:47:16 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Mar  9 10:54:12 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.217 2024/03/09 10:47:16 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.218 2024/03/09 10:54:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -425,14 +425,12 @@ typedef struct qual_ptr {
 	struct qual_ptr *p_next;
 } qual_ptr;
 
-/*
- * The values of the 'case' labels, linked via cl_next in reverse order of
- * appearance in the code, that is from bottom to top.
- */
-typedef struct case_label {
-	val_t	cl_val;
-	struct case_label *cl_next;
-} case_label_t;
+/* The values of the 'case' labels. */
+typedef struct {
+	val_t	*vals;
+	size_t	len;
+	size_t	cap;
+} case_labels;
 
 typedef enum {
 	CS_DO_WHILE,
@@ -466,7 +464,7 @@ typedef struct control_statement {
 
 	type_t	*c_switch_type;	/* type of switch expression */
 	tnode_t	*c_switch_expr;
-	case_label_t *c_case_labels;	/* list of case values */
+	case_labels c_case_labels;	/* list of case values */
 
 	memory_pool c_for_expr3_mem;	/* saved memory for end of loop
 	 * expression in for() */



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

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

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

Log Message:
lint: remove unneeded checks for left and right operands


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.609 -r1.610 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/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.7 src/usr.bin/xlint/lint1/cksnprintb.c:1.8
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.7	Sun Mar  3 16:09:01 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Sat Mar  9 10:47:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.8 2024/03/09 10:47:16 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.7 2024/03/03 16:09:01 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.8 2024/03/09 10:47:16 rillig Exp $");
 #endif
 
 #include 
@@ -59,7 +59,7 @@ static bool
 match_string_literal(const tnode_t *tn, const buffer **str)
 {
 	while (tn->tn_op == CVT)
-		tn = tn_ck_left(tn);
+		tn = tn->tn_left;
 	return tn->tn_op == ADDR
 	&& tn->tn_left->tn_op == STRING
 	&& (*str = tn->tn_left->tn_string, (*str)->data != NULL);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.216 src/usr.bin/xlint/lint1/lint1.h:1.217
--- src/usr.bin/xlint/lint1/lint1.h:1.216	Sat Mar  9 10:41:11 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Mar  9 10:47:16 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.216 2024/03/09 10:41:11 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.217 2024/03/09 10:47:16 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -555,20 +555,6 @@ typedef struct {
 			assert_failed(__FILE__, __LINE__, __func__, #cond); \
 	} while (false)
 
-static inline tnode_t *
-tn_ck_left(const tnode_t *tn)
-{
-	lint_assert(has_operands(tn));
-	return tn->tn_left;
-}
-
-static inline tnode_t *
-tn_ck_right(const tnode_t *tn)
-{
-	lint_assert(has_operands(tn));
-	return tn->tn_right;
-}
-
 #ifdef DEBUG
 #  include "err-msgs.h"
 

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.609 src/usr.bin/xlint/lint1/tree.c:1.610
--- src/usr.bin/xlint/lint1/tree.c:1.609	Sun Mar  3 16:09:01 2024
+++ src/usr.bin/xlint/lint1/tree.c	Sat Mar  9 10:47:16 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.609 2024/03/03 16:09:01 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.610 2024/03/09 10:47:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.609 2024/03/03 16:09:01 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.610 2024/03/09 10:47:16 rillig Exp $");
 #endif
 
 #include 
@@ -1236,7 +1236,7 @@ build_colon(bool sys, tnode_t *ln, tnode
 static bool
 is_cast_redundant(const tnode_t *tn)
 {
-	const type_t *ntp = tn->tn_type, *otp = tn_ck_left(tn)->tn_type;
+	const type_t *ntp = tn->tn_type, *otp = tn->tn_left->tn_type;
 	tspec_t nt = ntp->t_tspec, ot = otp->t_tspec;
 
 	if (nt == BOOL || ot == BOOL)



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

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

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

Log Message:
lint: remove unneeded checks for left and right operands


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.609 -r1.610 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-03-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  9 10:41:11 UTC 2024

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

Log Message:
lint: use fewer struct keywords


To generate a diff of this commit:
cvs rdiff -u -r1.489 -r1.490 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.394 -r1.395 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.215 -r1.216 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/usr.bin/xlint/lint1

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

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

Log Message:
lint: use fewer struct keywords


To generate a diff of this commit:
cvs rdiff -u -r1.489 -r1.490 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.394 -r1.395 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.215 -r1.216 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/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.489 src/usr.bin/xlint/lint1/cgram.y:1.490
--- src/usr.bin/xlint/lint1/cgram.y:1.489	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Mar  9 10:41:11 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.490 2024/03/09 10:41: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.489 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.490 2024/03/09 10:41:11 rillig Exp $");
 #endif
 
 #include 
@@ -128,7 +128,7 @@ is_either(const char *s, const char *a, 
 	tspec_t	y_tspec;
 	type_qualifiers y_type_qualifiers;
 	function_specifier y_function_specifier;
-	struct parameter_list y_parameter_list;
+	parameter_list y_parameter_list;
 	function_call *y_arguments;
 	type_t	*y_type;
 	tnode_t	*y_tnode;
@@ -137,7 +137,7 @@ is_either(const char *s, const char *a, 
 	qual_ptr *y_qual_ptr;
 	bool	y_seen_statement;
 	struct generic_association *y_generic;
-	struct array_size y_array_size;
+	array_size y_array_size;
 	bool	y_in_system_header;
 	designation y_designation;
 };
@@ -1421,7 +1421,7 @@ param_list:
 		block_level++;
 		begin_declaration_level(DLK_PROTO_PARAMS);
 	} identifier_list T_RPAREN {
-		$$ = (struct parameter_list){ .first = $3 };
+		$$ = (parameter_list){ .first = $3 };
 	}
 |	abstract_decl_param_list
 ;
@@ -1541,7 +1541,7 @@ direct_abstract_declarator:
 
 abstract_decl_param_list:	/* specific to lint */
 	abstract_decl_lparen T_RPAREN type_attribute_opt {
-		$$ = (struct parameter_list){ .first = NULL };
+		$$ = (parameter_list){ .first = NULL };
 	}
 |	abstract_decl_lparen vararg_parameter_type_list T_RPAREN
 	type_attribute_opt {
@@ -1549,7 +1549,7 @@ abstract_decl_param_list:	/* specific to
 		$$.prototype = true;
 	}
 |	abstract_decl_lparen error T_RPAREN type_attribute_opt {
-		$$ = (struct parameter_list){ .first = NULL };
+		$$ = (parameter_list){ .first = NULL };
 	}
 ;
 
@@ -1574,14 +1574,14 @@ vararg_parameter_type_list:	/* specific 
 		else if (allow_c90)
 			/* C90 to C17 require formal parameter before '...' */
 			warning(84);
-		$$ = (struct parameter_list){ .vararg = true };
+		$$ = (parameter_list){ .vararg = true };
 	}
 ;
 
 /* XXX: C99 6.7.5 defines the same name, but it looks different. */
 parameter_type_list:
 	parameter_declaration {
-		$$ = (struct parameter_list){ .first = $1 };
+		$$ = (parameter_list){ .first = $1 };
 	}
 |	parameter_type_list T_COMMA parameter_declaration {
 		$$ = $1;

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.394 src/usr.bin/xlint/lint1/decl.c:1.395
--- src/usr.bin/xlint/lint1/decl.c:1.394	Sat Mar  2 09:32:18 2024
+++ src/usr.bin/xlint/lint1/decl.c	Sat Mar  9 10:41:11 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.395 2024/03/09 10:41:11 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.394 2024/03/02 09:32:18 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.395 2024/03/09 10:41:11 rillig Exp $");
 #endif
 
 #include 
@@ -1334,7 +1334,7 @@ old_style_function(sym_t *decl, sym_t *p
 }
 
 sym_t *
-add_function(sym_t *decl, struct parameter_list params)
+add_function(sym_t *decl, parameter_list params)
 {
 
 	debug_enter();

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.218 src/usr.bin/xlint/lint1/externs1.h:1.219
--- src/usr.bin/xlint/lint1/externs1.h:1.218	Sun Mar  3 00:50:41 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Mar  9 10:41:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.218 2024/03/03 00:50:41 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.219 2024/03/09 10:41:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -233,7 +233,7 @@ void add_type_qualifiers(type_qualifiers
 qual_ptr *append_qualified_pointer(qual_ptr *, qual_ptr *);
 sym_t *add_pointer(sym_t *, qual_ptr *);
 sym_t *add_array(sym_t *, bool, int);
-sym_t *add_function(sym_t *, struct parameter_list);
+sym_t *add_function(sym_t *, parameter_list);
 void check_extern_declaration(const sym_t *);
 

CVS commit: src/usr.bin/xlint

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  2 09:32:19 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: 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: remove custom wrappers around  functions


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.393 -r1.394 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint2/read.c
cvs rdiff -u -r1.122 -r1.123 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.48 src/usr.bin/xlint/common/lint.h:1.49
--- src/usr.bin/xlint/common/lint.h:1.48	Thu Feb  1 18:37:06 2024
+++ src/usr.bin/xlint/common/lint.h	Sat Mar  2 09:32:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lint.h,v 1.48 2024/02/01 18:37:06 rillig Exp $	*/
+/*	$NetBSD: lint.h,v 1.49 2024/03/02 09:32:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -161,33 +161,3 @@ typedef struct lint2_type type_t;
 #endif
 
 #include "externs.h"
-
-static inline bool
-ch_isalnum(char ch)
-{
-	return isalnum((unsigned char)ch) != 0;
-}
-
-static inline bool
-ch_isdigit(char ch)
-{
-	return isdigit((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;
-}

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.393 src/usr.bin/xlint/lint1/decl.c:1.394
--- src/usr.bin/xlint/lint1/decl.c:1.393	Thu Feb  8 20:59:19 2024
+++ src/usr.bin/xlint/lint1/decl.c	Sat Mar  2 09:32:18 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.393 2024/02/08 20:59:19 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 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.393 2024/02/08 20:59:19 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.394 2024/03/02 09:32:18 rillig Exp $");
 #endif
 
 #include 
@@ -1776,7 +1776,7 @@ check_extern_declaration(const sym_t *sy
 	dcs->d_redeclared_symbol == NULL &&
 	ends_with(curr_pos.p_file, ".c") &&
 	allow_c90 &&
-	!ch_isdigit(sym->s_name[0]) &&	/* see mktempsym */
+	!isdigit((unsigned char)sym->s_name[0]) &&	/* see mktempsym */
 	strcmp(sym->s_name, "main") != 0) {
 		/* missing%s header declaration for '%s' */
 		warning(351, sym->s_type->t_tspec == FUNC ? "" : " 'extern'",
@@ -2873,7 +2873,7 @@ check_variable_usage(bool novar, const s
 	lint_assert(block_level != 0);
 
 	/* example at file scope: int c = ({ return 3; }); */
-	if (sym->s_block_level == 0 && ch_isdigit(sym->s_name[0]))
+	if (sym->s_block_level == 0 && isdigit((unsigned char)sym->s_name[0]))
 		return;
 
 	/* errors in expressions easily cause lots of these warnings */

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.88 src/usr.bin/xlint/lint1/emit1.c:1.89
--- src/usr.bin/xlint/lint1/emit1.c:1.88	Fri Mar  1 21:52:48 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Sat Mar  2 09:32:18 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.89 2024/03/02 09:32:18 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.89 2024/03/02 09:32:18 rillig Exp $");
 #endif
 
 #include 
@@ -185,7 +185,7 @@ outsym(const sym_t *sym, scl_t sc, def_t
 	 */
 	if (sc != EXTERN && !(sc == STATIC && sym->s_type->t_tspec == FUNC))
 		return;
-	if (ch_isdigit(sym->s_name[0]))	/* _tmp */
+	if (isdigit((unsigned char)sym->s_name[0]))	/* _tmp */
 		return;
 
 	outint(csrc_pos.p_line);
@@ -392,7 +392,7 @@ static void
 outqchar(char c)
 {
 
-	if (ch_isprint(c) && c != '\\' && c != '"' && c != '\'') {
+	if (isprint((unsigned char)c) && c != '\\' && c != '"' && c != '\'') {
 		outchar(c);
 		return;
 	}
@@ -466,7 +466,7 @@ outfstrg(const char *cp)
 		}
 
 		/* numeric field width */
-		while (ch_isdigit(c)) {
+		while (isdigit((unsigned char)c)) {
 			outchar(c);
 			c = *cp++;
 		}
@@ -479,7 +479,7 @@ outfstrg(const char *cp)
 outchar(c);
 c = 

CVS commit: src/usr.bin/xlint

2024-03-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Mar  2 09:32:19 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: 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: remove custom wrappers around  functions


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.393 -r1.394 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint2/read.c
cvs rdiff -u -r1.122 -r1.123 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/lint1

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 21:52:48 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c
tree.c

Log Message:
lint: fix misleading initializer for string iterator

The field 'start' marks the start of the previous matching character,
not the current iterator position.

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.259 -r1.260 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.606 -r1.607 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/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.23 src/usr.bin/xlint/lint1/ckgetopt.c:1.24
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.23	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.23 2024/02/05 23:11:22 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.23 2024/02/05 23:11:22 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.24 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -105,7 +105,7 @@ is_getopt_condition(const tnode_t *tn, c
 	&& (str = last_arg->tn_left->tn_left->tn_string)->data != NULL) {
 		buffer buf;
 		buf_init();
-		quoted_iterator it = { .start = 0 };
+		quoted_iterator it = { .i = 0 };
 		while (quoted_next(str, ))
 			buf_add_char(, (char)it.value);
 		*out_options = buf.data;

Index: src/usr.bin/xlint/lint1/cksnprintb.c
diff -u src/usr.bin/xlint/lint1/cksnprintb.c:1.1 src/usr.bin/xlint/lint1/cksnprintb.c:1.2
--- src/usr.bin/xlint/lint1/cksnprintb.c:1.1	Fri Mar  1 19:40:45 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $	*/
+/*	$NetBSD: cksnprintb.c,v 1.2 2024/03/01 21:52:48 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $");
+__RCSID("$NetBSD: cksnprintb.c,v 1.2 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -266,7 +266,7 @@ check_snprintb(const tnode_t *expr)
 	if (!match_snprintb_call(expr->tn_call, , ))
 		return;
 
-	quoted_iterator it = { .start = 0 };
+	quoted_iterator it = { .i = 0 };
 	if (!quoted_next(fmt, )) {
 		/* missing new-style '\177' or old-style number base */
 		warning(359);

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.87 src/usr.bin/xlint/lint1/emit1.c:1.88
--- src/usr.bin/xlint/lint1/emit1.c:1.87	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.87 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.88 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -362,7 +362,7 @@ outcall(const tnode_t *tn, bool retval_u
 		arg->tn_left->tn_string->data != NULL) {
 			buffer buf;
 			buf_init();
-			quoted_iterator it = { .start = 0 };
+			quoted_iterator it = { .i = 0 };
 			while (quoted_next(arg->tn_left->tn_string, ))
 buf_add_char(, (char)it.value);
 

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.259 src/usr.bin/xlint/lint1/init.c:1.260
--- src/usr.bin/xlint/lint1/init.c:1.259	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar  1 21:52:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.260 2024/03/01 21:52:48 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.259 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.260 2024/03/01 21:52:48 rillig Exp $");
 #endif
 
 #include 
@@ -886,7 +886,7 @@ initialization_init_array_from_string(in
 
 	size_t len = tn->tn_string->len;
 	if (tn->tn_string->data != NULL) {
-		quoted_iterator it = { .start = 0 };
+		quoted_iterator it = { .i = 0 };
 		for (len = 0; quoted_next(tn->tn_string, ); len++)
 			continue;
 	}

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.219 src/usr.bin/xlint/lint1/lex.c:1.220
--- 

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

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 21:52:48 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c cksnprintb.c emit1.c init.c lex.c
tree.c

Log Message:
lint: fix misleading initializer for string iterator

The field 'start' marks the start of the previous matching character,
not the current iterator position.

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/lint1/cksnprintb.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.259 -r1.260 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.606 -r1.607 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-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 19:40:45 UTC 2024

Added Files:
src/usr.bin/xlint/lint1: cksnprintb.c

Log Message:
lint: test format strings from snprintb calls

The functions snprintb and snprintb_m are specific to NetBSD, and their
format strings are tricky to get correct.  Provide some assistance in
catching the most common mistakes.


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

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

Added files:

Index: src/usr.bin/xlint/lint1/cksnprintb.c
diff -u /dev/null src/usr.bin/xlint/lint1/cksnprintb.c:1.1
--- /dev/null	Fri Mar  1 19:40:45 2024
+++ src/usr.bin/xlint/lint1/cksnprintb.c	Fri Mar  1 19:40:45 2024
@@ -0,0 +1,290 @@
+/*	$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $	*/
+
+/*-
+ * Copyright (c) 2024 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roland Illig .
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#endif
+
+#include 
+#if defined(__RCSID)
+__RCSID("$NetBSD: cksnprintb.c,v 1.1 2024/03/01 19:40:45 rillig Exp $");
+#endif
+
+#include 
+#include 
+
+#include "lint1.h"
+
+static bool
+match_string_literal(const tnode_t *tn, const buffer **str)
+{
+	while (tn->tn_op == CVT)
+		tn = tn_ck_left(tn);
+	return tn->tn_op == ADDR
+	&& tn->tn_left->tn_op == STRING
+	&& (*str = tn->tn_left->tn_string, (*str)->data != NULL);
+}
+
+static bool
+match_snprintb_call(const function_call *call,
+const buffer **out_fmt, const tnode_t **out_val)
+{
+	const char *func;
+	const tnode_t *val;
+	const buffer *str;
+
+	if (call->func->tn_op == ADDR
+	&& call->func->tn_left->tn_op == NAME
+	&& (func = call->func->tn_left->tn_sym->s_name, true)
+	&& ((strcmp(func, "snprintb") == 0 && call->args_len == 4)
+		|| (strcmp(func, "snprintb_m") == 0 && call->args_len == 5))
+	&& match_string_literal(call->args[2], )
+	&& (val = call->args[3], true)) {
+		*out_fmt = str;
+		*out_val = val;
+		return true;
+	}
+	return false;
+}
+
+static int
+len(quoted_iterator it)
+{
+	return (int)(it.i - it.start);
+}
+
+static int
+range(quoted_iterator start, quoted_iterator end)
+{
+	return (int)(end.i - start.start);
+}
+
+static const char *
+start(quoted_iterator it, const buffer *buf)
+{
+	return buf->data + it.start;
+}
+
+static uintmax_t
+val(quoted_iterator it)
+{
+	return it.value;
+}
+
+static void
+check_hex_escape(const buffer *buf, quoted_iterator it)
+{
+	if (it.hex_digits > 1) {
+		bool upper = false;
+		bool lower = false;
+		for (size_t i = it.start + 2; i < it.i; i++) {
+			if (isupper((unsigned char)buf->data[i]))
+upper = true;
+			if (islower((unsigned char)buf->data[i]))
+lower = true;
+		}
+		if (upper && lower)
+			/* hex escape '%.*s' mixes uppercase and lower... */
+			warning(357, len(it), start(it, buf));
+	}
+	if (it.hex_digits > 2)
+		/* hex escape '%.*s' has more than 2 digits */
+		warning(358, len(it), start(it, buf));
+}
+
+static bool
+check_directive(const buffer *fmt, quoted_iterator *it, bool new_style,
+		uint64_t *prev_field_width)
+{
+
+	if (!quoted_next(fmt, it))
+		return false;
+	quoted_iterator dir = *it;
+
+	bool has_bit = !new_style
+	|| dir.value == 'b' || dir.value == 'f' || dir.value == 'F';
+	if (has_bit && new_style && !quoted_next(fmt, it)) {
+		/* missing bit position after '%.*s' */
+		warning(364, len(dir), start(dir, fmt));
+		return false;
+	}
+	/* LINTED 86 "automatic 'bit' hides external declaration" */
+	

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

2024-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 19:40:45 UTC 2024

Added Files:
src/usr.bin/xlint/lint1: cksnprintb.c

Log Message:
lint: test format strings from snprintb calls

The functions snprintb and snprintb_m are specific to NetBSD, and their
format strings are tricky to get correct.  Provide some assistance in
catching the most common mistakes.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/cksnprintb.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-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:14:34 UTC 2024

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

Log Message:
lint: fix type error in strict bool mode (since yesterday)


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lex.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-03-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Mar  1 17:14:34 UTC 2024

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

Log Message:
lint: fix type error in strict bool mode (since yesterday)


To generate a diff of this commit:
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/lex.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/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.218 src/usr.bin/xlint/lint1/lex.c:1.219
--- src/usr.bin/xlint/lint1/lex.c:1.218	Thu Feb 29 21:37:10 2024
+++ src/usr.bin/xlint/lint1/lex.c	Fri Mar  1 17:14:34 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.219 2024/03/01 17:14:34 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.218 2024/02/29 21:37:10 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.219 2024/03/01 17:14:34 rillig Exp $");
 #endif
 
 #include 
@@ -597,7 +597,7 @@ lex_integer_constant(const char *yytext,
 	bool unsigned_since_c90 = allow_trad && allow_c90 && u_suffix == 0
 	&& is_unsigned_since_c90(l_suffix, ui, base);
 
-	tspec_t t = u_suffix
+	tspec_t t = u_suffix > 0
 	? integer_constant_type_unsigned(l_suffix, ui, warned)
 	: integer_constant_type_signed(l_suffix, ui, base, warned);
 	ui = (uint64_t)convert_integer((int64_t)ui, t, 0);



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

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 21:37:10 UTC 2024

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

Log Message:
lint1: remove redundant type table for integer constant suffixes


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lex.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/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.217 src/usr.bin/xlint/lint1/lex.c:1.218
--- src/usr.bin/xlint/lint1/lex.c:1.217	Thu Feb  8 20:59:19 2024
+++ src/usr.bin/xlint/lint1/lex.c	Thu Feb 29 21:37:10 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 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.217 2024/02/08 20:59:19 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.218 2024/02/29 21:37:10 rillig Exp $");
 #endif
 
 #include 
@@ -481,84 +481,72 @@ lex_name(const char *yytext, size_t yyle
 // Determines whether the constant is signed in traditional C but unsigned in
 // C90 and later.
 static bool
-is_unsigned_since_c90(tspec_t t, uint64_t ui, int base)
+is_unsigned_since_c90(unsigned ls, uint64_t ui, int base)
 {
-	if (!(allow_trad && allow_c90))
+	if (ui <= TARG_INT_MAX)
 		return false;
-	if (t == INT) {
-		if (ui > TARG_INT_MAX && ui <= TARG_UINT_MAX && base != 10)
-			return true;
-		return ui > TARG_LONG_MAX;
-	}
-	return t == LONG && ui > TARG_LONG_MAX;
+	if (ls == 0 && ui <= TARG_UINT_MAX && base != 10)
+		return true;
+	return ls <= 1 && ui > TARG_LONG_MAX;
 }
 
 static tspec_t
-integer_constant_type(tspec_t t, uint64_t ui, int base, bool warned)
+integer_constant_type_signed(unsigned ls, uint64_t ui, int base, bool warned)
 {
-	switch (t) {
-	case INT:
-		if (ui <= TARG_INT_MAX)
-			return INT;
-		if (ui <= TARG_UINT_MAX && base != 10 && allow_c90)
-			return UINT;
-		if (ui <= TARG_LONG_MAX)
-			return LONG;
-		/* FALLTHROUGH */
-	case LONG:
-		if (ui <= TARG_LONG_MAX)
-			return LONG;
-		if (ui <= TARG_ULONG_MAX && base != 10)
-			return allow_c90 ? ULONG : LONG;
-		if (!allow_c99) {
-			if (!warned)
-/* integer constant out of range */
-warning(252);
-			return allow_c90 ? ULONG : LONG;
-		}
-		/* FALLTHROUGH */
-	case LLONG:
-		if (ui <= TARG_LLONG_MAX)
-			return LLONG;
-		if (ui <= TARG_ULLONG_MAX && base != 10)
-			return allow_c90 ? ULLONG : LLONG;
+	if (ls == 0 && ui <= TARG_INT_MAX)
+		return INT;
+	if (ls == 0 && ui <= TARG_UINT_MAX && base != 10 && allow_c90)
+		return UINT;
+	if (ls == 0 && ui <= TARG_LONG_MAX)
+		return LONG;
+
+	if (ls <= 1 && ui <= TARG_LONG_MAX)
+		return LONG;
+	if (ls <= 1 && ui <= TARG_ULONG_MAX && base != 10)
+		return allow_c90 ? ULONG : LONG;
+	if (ls <= 1 && !allow_c99) {
 		if (!warned)
 			/* integer constant out of range */
 			warning(252);
+		return allow_c90 ? ULONG : LONG;
+	}
+
+	if (ui <= TARG_LLONG_MAX)
+		return LLONG;
+	if (ui <= TARG_ULLONG_MAX && base != 10)
 		return allow_c90 ? ULLONG : LLONG;
-	case UINT:
-		if (ui <= TARG_UINT_MAX)
-			return UINT;
-		/* FALLTHROUGH */
-	case ULONG:
-		if (ui <= TARG_ULONG_MAX)
-			return ULONG;
-		if (!allow_c99) {
-			if (!warned)
-/* integer constant out of range */
-warning(252);
-			return ULONG;
-		}
-		/* FALLTHROUGH */
-	default:
-		if (ui <= TARG_ULLONG_MAX)
-			return ULLONG;
+	if (!warned)
+		/* integer constant out of range */
+		warning(252);
+	return allow_c90 ? ULLONG : LLONG;
+}
+
+static tspec_t
+integer_constant_type_unsigned(unsigned l, uint64_t ui, bool warned)
+{
+	if (l == 0 && ui <= TARG_UINT_MAX)
+		return UINT;
+
+	if (l <= 1 && ui <= TARG_ULONG_MAX)
+		return ULONG;
+	if (l <= 1 && !allow_c99) {
 		if (!warned)
 			/* integer constant out of range */
 			warning(252);
-		return ULLONG;
+		return ULONG;
 	}
+
+	if (ui <= TARG_ULLONG_MAX)
+		return ULLONG;
+	if (!warned)
+		/* integer constant out of range */
+		warning(252);
+	return ULLONG;
 }
 
 int
 lex_integer_constant(const char *yytext, size_t yyleng, int base)
 {
-	/* C11 6.4.4.1p5 */
-	static const tspec_t suffix_type[2][3] = {
-		{ INT,  LONG,  LLONG, },
-		{ UINT, ULONG, ULLONG, }
-	};
-
 	const char *cp = yytext;
 	size_t len = yyleng;
 
@@ -590,7 +578,6 @@ lex_integer_constant(const char *yytext,
 	if (!allow_c90 && u_suffix > 0)
 		/* suffix 'U' is illegal in traditional C */
 		warning(97);
-	tspec_t ct = suffix_type[u_suffix][l_suffix];
 
 	bool warned = false;
 	errno = 0;
@@ -607,14 +594,17 @@ lex_integer_constant(const char *yytext,
 		/* octal number '%.*s' */
 		query_message(8, (int)len, cp);
 
-	bool ansiu = is_unsigned_since_c90(ct, ui, base);
+	bool unsigned_since_c90 = allow_trad && allow_c90 && u_suffix == 0
+	&& is_unsigned_since_c90(l_suffix, ui, base);
 
-	tspec_t t = integer_constant_type(ct, ui, base, 

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

2024-02-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb 29 21:37:10 UTC 2024

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

Log Message:
lint1: remove redundant type table for integer constant suffixes


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/usr.bin/xlint/lint1/lex.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-02-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  8 20:59:20 UTC 2024

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

Log Message:
lint: clean up variable names, parameter order, comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.392 -r1.393 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.604 -r1.605 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/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.392 src/usr.bin/xlint/lint1/decl.c:1.393
--- src/usr.bin/xlint/lint1/decl.c:1.392	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/decl.c	Thu Feb  8 20:59:19 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.392 2024/02/08 20:45:20 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.393 2024/02/08 20:59:19 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.392 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.393 2024/02/08 20:59:19 rillig Exp $");
 #endif
 
 #include 
@@ -1341,8 +1341,8 @@ add_function(sym_t *decl, struct paramet
 	debug_dcs_all();
 	debug_sym("decl: ", decl, "\n");
 #ifdef DEBUG
-	for (const sym_t *arg = params.first; arg != NULL; arg = arg->s_next)
-		debug_sym("arg: ", arg, "\n");
+	for (const sym_t *p = params.first; p != NULL; p = p->s_next)
+		debug_sym("param: ", p, "\n");
 #endif
 
 	if (params.prototype) {

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.216 src/usr.bin/xlint/lint1/lex.c:1.217
--- src/usr.bin/xlint/lint1/lex.c:1.216	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/lex.c	Thu Feb  8 20:59:19 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.216 2024/02/08 20:45:20 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 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.216 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.217 2024/02/08 20:59:19 rillig Exp $");
 #endif
 
 #include 
@@ -705,7 +705,7 @@ lex_operator(int t, op_t o)
 }
 
 static buffer *
-read_quoted(bool *complete, bool wide, char delim)
+read_quoted(bool *complete, char delim, bool wide)
 {
 	buffer *buf = xcalloc(1, sizeof(*buf));
 	buf_init(buf);
@@ -947,7 +947,7 @@ static buffer *
 lex_quoted(char delim, bool wide)
 {
 	bool complete;
-	buffer *buf = read_quoted(, wide, delim);
+	buffer *buf = read_quoted(, delim, wide);
 	check_quoted(buf, complete, delim);
 	return buf;
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.604 src/usr.bin/xlint/lint1/tree.c:1.605
--- src/usr.bin/xlint/lint1/tree.c:1.604	Thu Feb  8 20:45:20 2024
+++ src/usr.bin/xlint/lint1/tree.c	Thu Feb  8 20:59:19 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.604 2024/02/08 20:45:20 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.605 2024/02/08 20:59:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.604 2024/02/08 20:45:20 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.605 2024/02/08 20:59:19 rillig Exp $");
 #endif
 
 #include 
@@ -321,9 +321,8 @@ ic_expr(const tnode_t *tn)
 type_t *
 block_derive_type(type_t *tp, tspec_t t)
 {
-	type_t *tp2;
 
-	tp2 = block_zero_alloc(sizeof(*tp2), "type");
+	type_t *tp2 = block_zero_alloc(sizeof(*tp2), "type");
 	tp2->t_tspec = t;
 	tp2->t_subt = tp;
 	return tp2;
@@ -336,9 +335,8 @@ block_derive_type(type_t *tp, tspec_t t)
 type_t *
 expr_derive_type(type_t *tp, tspec_t t)
 {
-	type_t *tp2;
 
-	tp2 = expr_zero_alloc(sizeof(*tp2), "type");
+	type_t *tp2 = expr_zero_alloc(sizeof(*tp2), "type");
 	tp2->t_tspec = t;
 	tp2->t_subt = tp;
 	return tp2;
@@ -3806,55 +3804,48 @@ convert_constant_check_range(tspec_t ot,
 		warn_constant_check_range_loss(op, arg, tp, ot);
 }
 
-/*-
- * Converts a typed constant to a constant of another type.
- *
- * op		operator which requires conversion
- * arg		if op is FARG, # of parameter
- * tp		type to which to convert the constant
- * nv		new constant
- * v		old constant
- */
+/* Converts a typed constant to a constant of another type. */
 void
-convert_constant(op_t op, int arg, const type_t *tp, val_t *nv, val_t *v)
+convert_constant(op_t op, int arg, const type_t *ntp, val_t *nv, val_t *ov)
 {
 	/*
-	 * TODO: make 'v' const; the name of this function does not suggest
-	 *  that it modifies 'v'.
+	 * TODO: make 'ov' const; the name of this function does not suggest
+	 *  that it modifies 'ov'.
 	 */
-	tspec_t ot = v->v_tspec;
-	tspec_t nt = nv->v_tspec = tp->t_tspec;
+	tspec_t ot = ov->v_tspec;
+	tspec_t nt = nv->v_tspec = ntp->t_tspec;
 	bool range_check = false;
 
 	if (nt == BOOL) 

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

2024-02-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  8 20:59:20 UTC 2024

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

Log Message:
lint: clean up variable names, parameter order, comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.392 -r1.393 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.604 -r1.605 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-02-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  8 20:45:20 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y decl.c emit1.c func.c init.c lex.c
tree.c

Log Message:
lint: clean up redundant braces

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.488 -r1.489 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.391 -r1.392 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.258 -r1.259 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.603 -r1.604 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-02-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  8 20:45:20 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: cgram.y decl.c emit1.c func.c init.c lex.c
tree.c

Log Message:
lint: clean up redundant braces

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.488 -r1.489 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.391 -r1.392 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.258 -r1.259 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.603 -r1.604 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.488 src/usr.bin/xlint/lint1/cgram.y:1.489
--- src/usr.bin/xlint/lint1/cgram.y:1.488	Thu Feb  8 19:32:12 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Feb  8 20:45:20 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.488 2024/02/08 19:32:12 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.489 2024/02/08 20:45: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.488 2024/02/08 19:32:12 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.489 2024/02/08 20:45:20 rillig Exp $");
 #endif
 
 #include 
@@ -431,13 +431,12 @@ is_either(const char *s, const char *a, 
 program:
 	/* empty */ {
 		/* TODO: Make this an error in C99 mode as well. */
-		if (!allow_trad && !allow_c99) {
+		if (!allow_trad && !allow_c99)
 			/* empty translation unit */
 			error(272);
-		} else if (allow_c90) {
+		else if (allow_c90)
 			/* empty translation unit */
 			warning(272);
-		}
 	}
 |	translation_unit
 ;
@@ -464,10 +463,9 @@ identifier:
 string:
 	T_STRING
 |	string T_STRING {
-		if (!allow_c90) {
+		if (!allow_c90)
 			/* concatenated strings are illegal in traditional C */
 			warning(219);
-		}
 		$$ = cat_strings($1, $2);
 	}
 ;
@@ -670,10 +668,9 @@ unary_expression:
 		$$ = build_unary(INDIR, $2, $3);
 	}
 |	T_ADDITIVE sys cast_expression {
-		if (!allow_c90 && $1 == PLUS) {
+		if (!allow_c90 && $1 == PLUS)
 			/* unary '+' is illegal in traditional C */
 			warning(100);
-		}
 		$$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2, $3);
 	}
 |	T_COMPLEMENT sys cast_expression {
@@ -815,31 +812,28 @@ declaration_or_error:
 /* K ???, C90 ???, C99 6.7, C11 ???, C23 6.7 */
 declaration:
 	begin_type_declmods end_type T_SEMI {
-		if (dcs->d_scl == TYPEDEF) {
+		if (dcs->d_scl == TYPEDEF)
 			/* typedef declares no type name */
 			warning(72);
-		} else {
+		else
 			/* empty declaration */
 			warning(2);
-		}
 	}
 |	begin_type_declmods end_type notype_init_declarators T_SEMI {
-		if (dcs->d_scl == TYPEDEF) {
+		if (dcs->d_scl == TYPEDEF)
 			/* syntax error '%s' */
 			error(249, "missing base type for typedef");
-		} else {
+		else
 			/* old-style declaration; add 'int' */
 			error(1);
-		}
 	}
 |	begin_type_declaration_specifiers end_type T_SEMI {
-		if (dcs->d_scl == TYPEDEF) {
+		if (dcs->d_scl == TYPEDEF)
 			/* typedef declares no type name */
 			warning(72);
-		} else if (!dcs->d_nonempty_decl) {
+		else if (!dcs->d_nonempty_decl)
 			/* empty declaration */
 			warning(2);
-		}
 	}
 |	begin_type_declaration_specifiers end_type
 	type_init_declarators T_SEMI
@@ -1196,13 +1190,12 @@ enum_declaration:		/* helper for C99 6.7
 enums_with_opt_comma:		/* helper for C99 6.7.2.2 */
 	enumerator_list
 |	enumerator_list T_COMMA {
-		if (!allow_c99 && !allow_trad) {
+		if (!allow_c99 && !allow_trad)
 			/* trailing ',' in enum declaration requires C99 ... */
 			error(54);
-		} else {
+		else
 			/* trailing ',' in enum declaration requires C99 ... */
 			c99ism(54);
-		}
 		$$ = $1;
 	}
 ;
@@ -1575,13 +1568,12 @@ vararg_parameter_type_list:	/* specific 
 	}
 |	T_ELLIPSIS {
 		/* TODO: C99 6.7.5 makes this an error as well. */
-		if (!allow_trad && !allow_c99) {
+		if (!allow_trad && !allow_c99)
 			/* C90 to C17 require formal parameter before '...' */
 			error(84);
-		} else if (allow_c90) {
+		else if (allow_c90)
 			/* C90 to C17 require formal parameter before '...' */
 			warning(84);
-		}
 		$$ = (struct parameter_list){ .vararg = true };
 	}
 ;
@@ -2042,13 +2034,12 @@ external_declaration:		/* C99 6.9 */
 		 * TODO: Only allow this in GCC mode, not in plain C99.
 		 * This is one of the top 10 warnings in the NetBSD build.
 		 */
-		if (!allow_trad && !allow_c99) {
+		if (!allow_trad && !allow_c99)
 			/* empty declaration */
 			error(0);
-		} else if (allow_c90) {
+		else if (allow_c90)
 			/* empty declaration */
 			warning(0);
-		}
 	}
 ;
 
@@ -2064,13 +2055,12 @@ external_declaration:		/* C99 6.9 */
 top_level_declaration:		/* C99 6.9 calls this 'declaration' */
 	begin_type 

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

2024-02-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  8 19:32:12 UTC 2024

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

Log Message:
lint: clean up comments, add debug output for Bison


To generate a diff of this commit:
cvs rdiff -u -r1.487 -r1.488 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.487 src/usr.bin/xlint/lint1/cgram.y:1.488
--- src/usr.bin/xlint/lint1/cgram.y:1.487	Mon Feb  5 23:11:22 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Feb  8 19:32:12 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.487 2024/02/05 23:11:22 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.488 2024/02/08 19:32:12 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.487 2024/02/05 23:11:22 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.488 2024/02/08 19:32:12 rillig Exp $");
 #endif
 
 #include 
@@ -85,18 +85,6 @@ clear_warning_flags_loc(const char *file
 static void
 save_warning_flags_loc(const char *file, size_t line)
 {
-	/*
-	 * There used to be an assertion that saved_lwarn is
-	 * LWARN_NOTHING_SAVED here, but that triggered for the following
-	 * code:
-	 *
-	 * void function(int x) { if (x > 0) if (x > 1) return; }
-	 *
-	 * It didn't trigger if the inner 'if' was enclosed in braces though.
-	 *
-	 * TODO: If actually needed, add support for nested suppression of
-	 *  warnings.
-	 */
 	debug_step("%s:%zu: saving flags %d", file, line, lwarn);
 	saved_lwarn = lwarn;
 }
@@ -108,10 +96,6 @@ restore_warning_flags_loc(const char *fi
 	if (saved_lwarn != LWARN_NOTHING_SAVED) {
 		lwarn = saved_lwarn;
 		debug_step("%s:%zu: restoring flags %d", file, line, lwarn);
-		/*
-		 * Do not set 'saved_lwarn = LWARN_NOTHING_SAVED' here, to
-		 * avoid triggering the assertion in save_warning_flags_loc.
-		 */
 	} else
 		clear_warning_flags_loc(file, line);
 }
@@ -179,6 +163,12 @@ is_either(const char *s, const char *a, 
 %printer {
 	fprintf(yyo, "%s", function_specifier_name($$));
 } 
+%printer {
+	size_t n = 0;
+	for (const sym_t *p = $$.first; p != NULL; p = p->s_next)
+		n++;
+	fprintf(yyo, "%zu parameter%s", n, n != 1 ? "s" : "");
+} 
 %printer { fprintf(yyo, "%s", type_name($$)); } 
 %printer {
 	if ($$ == NULL)
@@ -196,6 +186,19 @@ is_either(const char *s, const char *a, 
 %printer { fprintf(yyo, "%s", type_name($$->ga_arg)); } 
 %printer { fprintf(yyo, "%d", $$.dim); } 
 %printer { fprintf(yyo, "%s", $$ ? "yes" : "no"); } 
+%printer {
+	if ($$.dn_len == 0)
+		fprintf(yyo, "(empty)");
+	for (size_t i = 0; i < $$.dn_len; i++) {
+		const designator *dr = $$.dn_items + i;
+		if (dr->dr_kind == DK_MEMBER)
+			fprintf(yyo, ".%s", dr->dr_member->s_name);
+		else if (dr->dr_kind == DK_SUBSCRIPT)
+			fprintf(yyo, "[%zu]", dr->dr_subscript);
+		else
+			fprintf(yyo, "");
+	}
+} 
 */
 
 %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
@@ -1042,7 +1045,7 @@ braced_member_declaration_list:	/* see C
 member_declaration_list_with_rbrace:	/* see C99 6.7.2.1 */
 	member_declaration_list T_RBRACE
 |	T_RBRACE {
-		/* XXX: This is not allowed by any C standard. */
+		/* XXX: Allowed since C23. */
 		$$ = NULL;
 	}
 ;



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

2024-02-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  8 19:32:12 UTC 2024

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

Log Message:
lint: clean up comments, add debug output for Bison


To generate a diff of this commit:
cvs rdiff -u -r1.487 -r1.488 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-02-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 08:00:37 UTC 2024

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

Log Message:
lint: use consistent variable names, reduce code for reading a byte

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/lex.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/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.214 src/usr.bin/xlint/lint1/lex.c:1.215
--- src/usr.bin/xlint/lint1/lex.c:1.214	Wed Feb  7 07:42:50 2024
+++ src/usr.bin/xlint/lint1/lex.c	Wed Feb  7 08:00:36 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.214 2024/02/07 07:42:50 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.215 2024/02/07 08:00:36 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.214 2024/02/07 07:42:50 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.215 2024/02/07 08:00:36 rillig Exp $");
 #endif
 
 #include 
@@ -423,15 +423,11 @@ init_lex(void)
 static int
 read_byte(void)
 {
-	int c;
+	int c = lex_input();
 
-	if ((c = lex_input()) == EOF)
-		return c;
-	if (c == '\0')
-		return EOF;	/* lex returns 0 on EOF. */
 	if (c == '\n')
 		lex_next_line();
-	return c;
+	return c == '\0' ? EOF : c;	/* lex returns 0 on EOF. */
 }
 
 static int
@@ -485,16 +481,16 @@ lex_name(const char *yytext, size_t yyle
 // Determines whether the constant is signed in traditional C but unsigned in
 // C90 and later.
 static bool
-is_unsigned_since_c90(tspec_t typ, uint64_t ui, int base)
+is_unsigned_since_c90(tspec_t t, uint64_t ui, int base)
 {
 	if (!(allow_trad && allow_c90))
 		return false;
-	if (typ == INT) {
+	if (t == INT) {
 		if (ui > TARG_INT_MAX && ui <= TARG_UINT_MAX && base != 10)
 			return true;
 		return ui > TARG_LONG_MAX;
 	}
-	return typ == LONG && ui > TARG_LONG_MAX;
+	return t == LONG && ui > TARG_LONG_MAX;
 }
 
 static tspec_t
@@ -657,17 +653,17 @@ lex_floating_constant(const char *yytext
 		len--;
 
 	char c = cp[len - 1];
-	tspec_t typ;
+	tspec_t t;
 	if (c == 'f' || c == 'F') {
-		typ = imaginary ? FCOMPLEX : FLOAT;
+		t = imaginary ? FCOMPLEX : FLOAT;
 		len--;
 	} else if (c == 'l' || c == 'L') {
-		typ = imaginary ? LCOMPLEX : LDOUBLE;
+		t = imaginary ? LCOMPLEX : LDOUBLE;
 		len--;
 	} else
-		typ = imaginary ? DCOMPLEX : DOUBLE;
+		t = imaginary ? DCOMPLEX : DOUBLE;
 
-	if (!allow_c90 && typ != DOUBLE) {
+	if (!allow_c90 && t != DOUBLE) {
 		/* suffixes 'F' and 'L' are illegal in traditional C */
 		warning(98);
 	}
@@ -679,14 +675,14 @@ lex_floating_constant(const char *yytext
 	if (errno != 0) {
 		/* floating-point constant out of range */
 		warning(248);
-	} else if (typ == FLOAT) {
+	} else if (t == FLOAT) {
 		ld = (float)ld;
 		if (isfinite(ld) == 0) {
 			/* floating-point constant out of range */
 			warning(248);
 			ld = ld > 0 ? FLT_MAX : -FLT_MAX;
 		}
-	} else if (typ == DOUBLE
+	} else if (t == DOUBLE
 	|| /* CONSTCOND */ LDOUBLE_SIZE == DOUBLE_SIZE) {
 		ld = (double)ld;
 		if (isfinite(ld) == 0) {
@@ -697,7 +693,7 @@ lex_floating_constant(const char *yytext
 	}
 
 	yylval.y_val = xcalloc(1, sizeof(*yylval.y_val));
-	yylval.y_val->v_tspec = typ;
+	yylval.y_val->v_tspec = t;
 	yylval.y_val->u.floating = ld;
 
 	return T_CON;



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

2024-02-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Feb  7 08:00:37 UTC 2024

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

Log Message:
lint: use consistent variable names, reduce code for reading a byte

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/lex.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-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb  6 22:47:21 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: Makefile check-msgs.lua err.c makeman

Log Message:
lint: tab-align message numbers in err.c

By replacing block comments with end-of-line comments, the comments take
up less space and thus no longer require to be indented by 6 spaces.

The messages and their comments are used in 3 places: the manual page
lint.7, the err-msgs.h header for debug mode, and check-msgs.lua to
verify that the comments above the message IDs correspond to the actual
messages.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/check-msgs.lua
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/makeman

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/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.102 src/usr.bin/xlint/lint1/Makefile:1.103
--- src/usr.bin/xlint/lint1/Makefile:1.102	Sat Jul 29 10:45:00 2023
+++ src/usr.bin/xlint/lint1/Makefile	Tue Feb  6 22:47:21 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.102 2023/07/29 10:45:00 rillig Exp $
+#	$NetBSD: Makefile,v 1.103 2024/02/06 22:47:21 rillig Exp $
 
 .include 
 
@@ -78,7 +78,7 @@ DPADD+=		${LIBL}
 err-msgs.h: err.c
 	${_MKTARGET_CREATE}
 	sp='[[:space:]]*'; \
-	from="^$$sp\(\"[^\"].*\"\)\,$$sp/\*$$sp\(Q*[0-9][0-9]*\)$$sp\*/\$$"; \
+	from="^$$sp\(\"[^\"].*\"\)\,$$sp// \(Q*[0-9][0-9]*\)\$$"; \
 	${TOOL_SED} -n -e "s,$$from,#define MSG_\2 \1,p" < ${.ALLSRC:M*err.c} > ${.TARGET}.tmp
 	mv -f ${.TARGET}.tmp ${.TARGET}
 

Index: src/usr.bin/xlint/lint1/check-msgs.lua
diff -u src/usr.bin/xlint/lint1/check-msgs.lua:1.20 src/usr.bin/xlint/lint1/check-msgs.lua:1.21
--- src/usr.bin/xlint/lint1/check-msgs.lua:1.20	Sat Aug 12 18:05:51 2023
+++ src/usr.bin/xlint/lint1/check-msgs.lua	Tue Feb  6 22:47:21 2024
@@ -1,5 +1,5 @@
 #! /usr/bin/lua
--- $NetBSD: check-msgs.lua,v 1.20 2023/08/12 18:05:51 rillig Exp $
+-- $NetBSD: check-msgs.lua,v 1.21 2024/02/06 22:47:21 rillig Exp $
 
 --[[
 
@@ -16,7 +16,7 @@ local function load_messages()
 
   local f = assert(io.open("err.c"))
   for line in f:lines() do
-local msg, id = line:match("%s*\"(.+)\",%s*/%*%s*(Q?%d+)%s*%*/$")
+local msg, id = line:match("%s*\"(.+)\",%s*// (Q?%d+)$")
 if msg ~= nil then
   msgs[id] = msg
 end

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.224 src/usr.bin/xlint/lint1/err.c:1.225
--- src/usr.bin/xlint/lint1/err.c:1.224	Sat Feb  3 20:10:10 2024
+++ src/usr.bin/xlint/lint1/err.c	Tue Feb  6 22:47:21 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.224 2024/02/03 20:10:10 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.225 2024/02/06 22:47:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.224 2024/02/03 20:10:10 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.225 2024/02/06 22:47:21 rillig Exp $");
 #endif
 
 #include 
@@ -55,363 +55,363 @@ int sytxerr;
 
 
 static const char *const msgs[] = {
-	"empty declaration",	  /* 0 */
-	"old-style declaration; add 'int'",			  /* 1 */
-	"empty declaration",	  /* 2 */
-	"'%s' declared in parameter declaration list",		  /* 3 */
-	"illegal type combination",  /* 4 */
-	"modifying typedef with '%s'; only qualifiers allowed",	  /* 5 */
-	"use 'double' instead of 'long float'",			  /* 6 */
-	"only one storage class allowed",			  /* 7 */
-	"illegal storage class",  /* 8 */
-	"only 'register' is valid as storage class in parameter", /* 9 */
-	"duplicate '%s'",	  /* 10 */
-	"bit-field initializer out of range",			  /* 11 */
-	"compiler takes size of function",			  /* 12 */
-	"incomplete enum type '%s'",  /* 13 */
-	"",			  /* 14 */
-	"function returns illegal type '%s'",			  /* 15 */
-	"array of function is illegal",  /* 16 */
-	"null dimension",	  /* 17 */
-	"illegal use of 'void'",  /* 18 */
-	"void type for '%s'",	  /* 19 */
-	"negative array dimension (%d)",			  /* 20 */
-	"redeclaration of formal parameter '%s'",		  /* 21 */
-	"incomplete or misplaced function definition",		  /* 22 */
-	"undefined label '%s'",	  /* 23 */
-	"cannot initialize function '%s'",			  /* 24 */
-	"cannot initialize typedef '%s'",			  /* 25 */
-	"cannot initialize extern declaration '%s'",		  /* 26 */
-	"redeclaration of '%s'",  /* 27 */
-	"redefinition of '%s'",	  /* 28 */
-	"'%s' was previously declared extern, becomes static",	  /* 29 */
-	"redeclaration of '%s'; C90 or later require static",	  /* 30 */
-	"'%s' has incomplete type '%s'",			  /* 31 */
-	"type of parameter '%s' 

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

2024-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb  6 22:47:21 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: Makefile check-msgs.lua err.c makeman

Log Message:
lint: tab-align message numbers in err.c

By replacing block comments with end-of-line comments, the comments take
up less space and thus no longer require to be indented by 6 spaces.

The messages and their comments are used in 3 places: the manual page
lint.7, the err-msgs.h header for debug mode, and check-msgs.lua to
verify that the comments above the message IDs correspond to the actual
messages.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/check-msgs.lua
cvs rdiff -u -r1.224 -r1.225 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/xlint/lint1/makeman

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-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb  6 21:28:16 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: makeman

Log Message:
lint.7: remove implementation details from message list

>From a user's perspective, it's irrelevant whether a lint message is
generated using '%s' or '%.*s'; same for the integer widths, as they are
platform-dependent.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/makeman

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/makeman
diff -u src/usr.bin/xlint/lint1/makeman:1.7 src/usr.bin/xlint/lint1/makeman:1.8
--- src/usr.bin/xlint/lint1/makeman:1.7	Fri Jul 21 15:00:32 2023
+++ src/usr.bin/xlint/lint1/makeman	Tue Feb  6 21:28:15 2024
@@ -1,5 +1,5 @@
 #!/bin/sh
-#	$NetBSD: makeman,v 1.7 2023/07/21 15:00:32 lukem Exp $
+#	$NetBSD: makeman,v 1.8 2024/02/06 21:28:15 rillig Exp $
 #
 # Copyright (c) 2000 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -38,6 +38,10 @@ list_messages() {
 	-e 's|^'"$tab"'"",.*/\* '"$2"'[0-9]+ \*/$|---'"$tab"'(no longer used)|p' \
 	"$1" \
 	| ${SED} -E \
+	-e 's,%ld,%d,g' \
+	-e 's,%lu,%u,g' \
+	-e 's,%llu,%u,g' \
+	-e 's|%.\*s|%s|g' \
 	-e 's|\\"|"|g' \
 	-e 's||\\e|g' \
 	-e "s|'|\\'|g" \
@@ -45,7 +49,7 @@ list_messages() {
 }
 
 # shellcheck disable=SC2016
-cvsid='$NetBSD: makeman,v 1.7 2023/07/21 15:00:32 lukem Exp $'
+cvsid='$NetBSD: makeman,v 1.8 2024/02/06 21:28:15 rillig Exp $'
 date="$1"
 year="${date##* }"
 messages="$(list_messages "$2" "")"



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

2024-02-06 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Feb  6 21:28:16 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: makeman

Log Message:
lint.7: remove implementation details from message list

>From a user's perspective, it's irrelevant whether a lint message is
generated using '%s' or '%.*s'; same for the integer widths, as they are
platform-dependent.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/makeman

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-02-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb  5 23:11:23 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md cgram.y ckctype.c ckgetopt.c debug.c
emit1.c externs1.h lint1.h op.h oper.c tree.c

Log Message:
lint: make function call arguments directly accessible

Previously, the arguments of a function call expression were arranged in
a linear tree structure, from right to left.  To allow easier access to
the arguments, store them in an array instead.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/README.md \
src/usr.bin/xlint/lint1/oper.c
cvs rdiff -u -r1.486 -r1.487 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.602 -r1.603 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/README.md
diff -u src/usr.bin/xlint/lint1/README.md:1.14 src/usr.bin/xlint/lint1/README.md:1.15
--- src/usr.bin/xlint/lint1/README.md:1.14	Thu Sep 14 21:08:12 2023
+++ src/usr.bin/xlint/lint1/README.md	Mon Feb  5 23:11:22 2024
@@ -1,4 +1,4 @@
-[//]: # ($NetBSD: README.md,v 1.14 2023/09/14 21:08:12 rillig Exp $)
+[//]: # ($NetBSD: README.md,v 1.15 2024/02/05 23:11:22 rillig Exp $)
 
 # Introduction
 
@@ -123,34 +123,31 @@ structure:
 
 ~~~text
  1: 'call' type 'int'
- 2:  '&' type 'pointer to function(pointer to const char, pointer to const char) returning int'
- 3:'name' 'strcmp' with extern 'function(pointer to const char, pointer to const char) returning int'
- 4:  'push' type 'pointer to const char'
- 5:'convert' type 'pointer to const char'
- 6:  '&' type 'pointer to char'
- 7:'string' type 'array[5] of char', lvalue, length 4, "name"
- 8:'push' type 'pointer to const char'
- 9:  'load' type 'pointer to const char'
-10:'*' type 'pointer to const char', lvalue
-11:  '+' type 'pointer to pointer to const char'
-12:'load' type 'pointer to pointer to const char'
-13:  'name' 'names' with auto 'pointer to pointer to const char', lvalue
-14:'*' type 'long'
-15:  'convert' type 'long'
-16:'load' type 'int'
-17:  'name' 'i' with auto 'int', lvalue
-18:  'constant' type 'long', value 8
+ 2:   '&' type 'pointer to function(pointer to const char, pointer to const char) returning int'
+ 3: 'name' 'strcmp' with extern 'function(pointer to const char, pointer to const char) returning int'
+ 4:   'load' type 'pointer to const char'
+ 5: '*' type 'pointer to const char', lvalue
+ 6:   '+' type 'pointer to pointer to const char'
+ 7: 'load' type 'pointer to pointer to const char'
+ 8:   'name' 'names' with auto 'pointer to pointer to const char', lvalue
+ 9: '*' type 'long'
+10:   'convert' type 'long'
+11: 'load' type 'int'
+12:   'name' 'i' with auto 'int', lvalue
+13:   'constant' type 'long', value 8
+14:   'convert' type 'pointer to const char'
+15: '&' type 'pointer to char'
+16:   'string' type 'array[5] of char', lvalue, "name"
 ~~~
 
-| Lines  | Notes|
-||--|
-| 4, 8   | Each argument of the function call corresponds to a `PUSH` node. |
-| 5, 9   | The left operand of a `PUSH` node is the actual argument.|
-| 8  | The right operand is the `PUSH` node of the previous argument.   |
-| 5, 9   | The arguments of a call are ordered from right to left.  |
-| 10, 11 | Array access is represented as `*(left + right)`.|
-| 14, 18 | Array and struct offsets are in premultiplied form.  |
-| 18 | The size of a pointer on this platform is 8 bytes.   |
+| Lines  | Notes   |
+||-|
+| 1, 2, 4, 7 | A function call consists of the function and its arguments. |
+| 4, 14  | The arguments of a call are ordered from left to right. |
+| 5, 6   | Array access is represented as `*(left + right)`.   |
+| 9, 13  | Array and struct offsets are in premultiplied form. |
+| 9  | The type `ptrdiff_t` on this platform is `long`, not `int`. |
+| 13 | The size of a pointer on this platform is 8 bytes.  |
 
 See `debug_node` for how to 

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

2024-02-05 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Feb  5 23:11:23 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: README.md cgram.y ckctype.c ckgetopt.c debug.c
emit1.c externs1.h lint1.h op.h oper.c tree.c

Log Message:
lint: make function call arguments directly accessible

Previously, the arguments of a function call expression were arranged in
a linear tree structure, from right to left.  To allow easier access to
the arguments, store them in an array instead.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/xlint/lint1/README.md \
src/usr.bin/xlint/lint1/oper.c
cvs rdiff -u -r1.486 -r1.487 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/ckctype.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.602 -r1.603 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-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 19:37:02 UTC 2024

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

Log Message:
lint: remove excessive empty lines


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/main1.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/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.212 src/usr.bin/xlint/lint1/lint1.h:1.213
--- src/usr.bin/xlint/lint1/lint1.h:1.212	Sat Feb  3 19:25:16 2024
+++ src/usr.bin/xlint/lint1/lint1.h	Sat Feb  3 19:37:02 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.212 2024/02/03 19:25:16 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.213 2024/02/03 19:37:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -180,8 +180,6 @@ struct lint1_type {
 #define	t_params	t_u._t_params
 
 
-
-
 typedef enum {
 	SK_VCFT,		/* variable, constant, function, type */
 	SK_MEMBER,		/* member of a struct or union */

Index: src/usr.bin/xlint/lint1/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.81 src/usr.bin/xlint/lint1/main1.c:1.82
--- src/usr.bin/xlint/lint1/main1.c:1.81	Sat Feb  3 12:57:12 2024
+++ src/usr.bin/xlint/lint1/main1.c	Sat Feb  3 19:37:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: main1.c,v 1.81 2024/02/03 12:57:12 rillig Exp $	*/
+/*	$NetBSD: main1.c,v 1.82 2024/02/03 19:37:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: main1.c,v 1.81 2024/02/03 12:57:12 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.82 2024/02/03 19:37:02 rillig Exp $");
 #endif
 
 #include 
@@ -213,7 +213,6 @@ main(int argc, char *argv[])
 	if (argc != 2)
 		usage();
 
-
 	/* initialize output */
 	outopen(argv[1]);
 



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

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

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

Log Message:
lint: remove excessive empty lines


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/main1.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-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 19:25:16 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c externs1.h init.c
lex.c lint1.h tree.c

Log Message:
lint: keep strings in their source representation

This allows further analysis depending on whether individual characters are
escaped as octal, hexadecimal or not at all.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.257 -r1.258 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.211 -r1.212 src/usr.bin/xlint/lint1/lex.c \
src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.601 -r1.602 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/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.21 src/usr.bin/xlint/lint1/ckgetopt.c:1.22
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.21	Sat Feb  3 12:57:12 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Sat Feb  3 19:25:16 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.22 2024/02/03 19:25:16 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.22 2024/02/03 19:25:16 rillig Exp $");
 #endif
 
 #include 
@@ -100,7 +100,12 @@ is_getopt_condition(const tnode_t *tn, c
 	&& last_arg->tn_left->tn_op == ADDR
 	&& last_arg->tn_left->tn_left->tn_op == STRING
 	&& (str = last_arg->tn_left->tn_left->tn_string)->data != NULL) {
-		*out_options = xstrdup(str->data);
+		buffer buf;
+		buf_init();
+		quoted_iterator it = { .start = 0 };
+		while (quoted_next(str, ))
+			buf_add_char(, (char)it.value);
+		*out_options = buf.data;
 		return true;
 	}
 	return false;

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.69 src/usr.bin/xlint/lint1/debug.c:1.70
--- src/usr.bin/xlint/lint1/debug.c:1.69	Fri Feb  2 16:25:58 2024
+++ src/usr.bin/xlint/lint1/debug.c	Sat Feb  3 19:25:16 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.69 2024/02/02 16:25:58 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.70 2024/02/03 19:25:16 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.69 2024/02/02 16:25:58 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.70 2024/02/03 19:25:16 rillig Exp $");
 #endif
 
 #include 
@@ -235,11 +235,10 @@ debug_node(const tnode_t *tn) // NOLINT(
 		debug_printf("\n");
 		break;
 	case STRING:
-		debug_printf(", length %zu", tn->tn_string->len);
 		if (tn->tn_string->data != NULL)
-			// TODO: May contain \0 or control characters.
-			debug_printf(", \"%s\"", tn->tn_string->data);
-		debug_printf("\n");
+			debug_printf(", %s\n", tn->tn_string->data);
+		else
+			debug_printf(", length %zu\n", tn->tn_string->len);
 		break;
 	default:
 		debug_printf("\n");

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.84 src/usr.bin/xlint/lint1/emit1.c:1.85
--- src/usr.bin/xlint/lint1/emit1.c:1.84	Sat Feb  3 12:57:12 2024
+++ src/usr.bin/xlint/lint1/emit1.c	Sat Feb  3 19:25:16 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.84 2024/02/03 12:57:12 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.85 2024/02/03 19:25:16 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,9 +38,11 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.84 2024/02/03 12:57:12 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.85 2024/02/03 19:25:16 rillig Exp $");
 #endif
 
+#include 
+
 #include "lint1.h"
 
 static void outtt(sym_t *, sym_t *);
@@ -367,10 +369,17 @@ outcall(const tnode_t *tn, bool retval_u
 		} else if (arg->tn_op == ADDR &&
 		arg->tn_left->tn_op == STRING &&
 		arg->tn_left->tn_string->data != NULL) {
-			/* constant string, write all format specifiers */
+			buffer buf;
+			buf_init();
+			quoted_iterator it = { .start = 0 };
+			while (quoted_next(arg->tn_left->tn_string, ))
+buf_add_char(, (char)it.value);
+
+			/* string literal, write all format specifiers */
 			outchar('s');
 			outint(n);
-			outfstrg(arg->tn_left->tn_string->data);
+			outfstrg(buf.data);
+			free(buf.data);
 		}
 	}
 	outchar((char)(retval_discarded ? 'd' : retval_used ? 'u' : 'i'));

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.214 src/usr.bin/xlint/lint1/externs1.h:1.215
--- src/usr.bin/xlint/lint1/externs1.h:1.214	Sat Feb  3 12:57:12 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Feb  3 

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

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

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c externs1.h init.c
lex.c lint1.h tree.c

Log Message:
lint: keep strings in their source representation

This allows further analysis depending on whether individual characters are
escaped as octal, hexadecimal or not at all.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.214 -r1.215 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.257 -r1.258 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.211 -r1.212 src/usr.bin/xlint/lint1/lex.c \
src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.601 -r1.602 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-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 12:57:12 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckbool.c ckgetopt.c decl.c emit1.c externs1.h
func.c lex.c main1.c

Log Message:
lint: clean up comments, reduce scope of variables


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.390 -r1.391 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/main1.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.28 src/usr.bin/xlint/lint1/ckbool.c:1.29
--- src/usr.bin/xlint/lint1/ckbool.c:1.28	Sat Dec 30 15:37:27 2023
+++ src/usr.bin/xlint/lint1/ckbool.c	Sat Feb  3 12:57:12 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.28 2023/12/30 15:37:27 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.28 2023/12/30 15:37:27 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.29 2024/02/03 12:57:12 rillig Exp $");
 #endif
 
 #include 
@@ -46,7 +46,7 @@ __RCSID("$NetBSD: ckbool.c,v 1.28 2023/1
 
 /*
  * The option -T treats _Bool as incompatible with all other scalar types.
- * See d_c99_bool_strict.c for the exact rules and for examples.
+ * See d_c99_bool_strict.c for the detailed rules and for examples.
  */
 
 
@@ -113,16 +113,15 @@ typeok_strict_bool_binary_compatible(op_
 	if (is_typeok_strict_bool_binary(op, ln, lt, rn, rt))
 		return true;
 
-	if (op == FARG) {
+	if (op == FARG)
 		/* parameter %d expects '%s', gets passed '%s' */
 		error(334, arg, tspec_name(lt), tspec_name(rt));
-	} else if (op == RETURN) {
+	else if (op == RETURN)
 		/* function has return type '%s' but returns '%s' */
 		error(211, tspec_name(lt), tspec_name(rt));
-	} else {
+	else
 		/* operands of '%s' have incompatible types '%s' and '%s' */
 		error(107, op_name(op), tspec_name(lt), tspec_name(rt));
-	}
 
 	return false;
 }
@@ -136,16 +135,12 @@ typeok_scalar_strict_bool(op_t op, const
 			  const tnode_t *ln,
 			  const tnode_t *rn)
 {
-	tspec_t lt, rt;
-
 	ln = before_conversion(ln);
-	lt = ln->tn_type->t_tspec;
-
+	tspec_t lt = ln->tn_type->t_tspec;
+	tspec_t rt = NO_TSPEC;
 	if (rn != NULL) {
 		rn = before_conversion(rn);
 		rt = rn->tn_type->t_tspec;
-	} else {
-		rt = NO_TSPEC;
 	}
 
 	if (rn != NULL &&
@@ -202,26 +197,16 @@ typeok_scalar_strict_bool(op_t op, const
 	return true;
 }
 
-/*
- * See if the node is valid as operand of an operator that compares its
- * operand with 0.
- */
 bool
 is_typeok_bool_compares_with_zero(const tnode_t *tn)
 {
-	tspec_t t;
-
 	while (tn->tn_op == COMMA)
 		tn = tn->tn_right;
 	tn = before_conversion(tn);
-	t = tn->tn_type->t_tspec;
-
-	if (t == BOOL)
-		return true;
 
-	if (tn->tn_sys && is_scalar(t))
-		return true;
-	return tn->tn_op == BITAND;
+	return tn->tn_type->t_tspec == BOOL
+	|| tn->tn_op == BITAND
+	|| (tn->tn_sys && is_scalar(tn->tn_type->t_tspec));
 }
 
 bool

Index: src/usr.bin/xlint/lint1/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.20 src/usr.bin/xlint/lint1/ckgetopt.c:1.21
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.20	Thu Feb  1 18:37:06 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Sat Feb  3 12:57:12 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.20 2024/02/01 18:37:06 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.20 2024/02/01 18:37:06 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.21 2024/02/03 12:57:12 rillig Exp $");
 #endif
 
 #include 
@@ -109,31 +109,22 @@ is_getopt_condition(const tnode_t *tn, c
 static void
 check_unlisted_option(char opt)
 {
-	char *optptr;
-
-	lint_assert(ck.options != NULL);
-
 	if (opt == ':' && ck.options[0] != ':')
 		goto warn;
 
-	optptr = strchr(ck.options, opt);
+	char *optptr = strchr(ck.options, opt);
 	if (optptr != NULL)
 		*optptr = ' ';
-	else if (opt != '?') {
+	else if (opt != '?')
 	warn:
 		/* option '%c' should be listed in the options string */
 		warning(339, opt);
-	}
 }
 
 static void
 check_unhandled_option(void)
 {
-	const char *opt;
-
-	lint_assert(ck.options != NULL);
-
-	for (opt = ck.options; *opt != '\0'; opt++) {
+	for (const char *opt = ck.options; *opt != '\0'; opt++) {
 		if (*opt == ' ' || *opt == ':')
 			continue;
 

Index: src/usr.bin/xlint/lint1/decl.c

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

2024-02-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Feb  3 12:57:12 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckbool.c ckgetopt.c decl.c emit1.c externs1.h
func.c lex.c main1.c

Log Message:
lint: clean up comments, reduce scope of variables


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.390 -r1.391 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.179 -r1.180 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/main1.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-02-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  1 21:19:13 UTC 2024

Modified Files:
src/usr.bin/xlint/common: externs.h tyname.c
src/usr.bin/xlint/lint1: lex.c tree.c

Log Message:
lint: reuse buffer editing code across lint1

Fix cat_strings to update the capacity of the buffer, to prevent
quadratic runtime when concatenating string literals.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/xlint/common/externs.h
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.205 -r1.206 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.600 -r1.601 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/common/externs.h
diff -u src/usr.bin/xlint/common/externs.h:1.34 src/usr.bin/xlint/common/externs.h:1.35
--- src/usr.bin/xlint/common/externs.h:1.34	Sat Jan 20 12:02:09 2024
+++ src/usr.bin/xlint/common/externs.h	Thu Feb  1 21:19:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs.h,v 1.34 2024/01/20 12:02:09 rillig Exp $	*/
+/*	$NetBSD: externs.h,v 1.35 2024/02/01 21:19:13 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,6 +37,8 @@
 #if IS_LINT1 || IS_LINT2
 const char *type_name(const type_t *);
 const char *tspec_name(tspec_t);
+void buf_init(buffer *);
+void buf_add_char(buffer *, char);
 #endif
 
 /*

Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.59 src/usr.bin/xlint/common/tyname.c:1.60
--- src/usr.bin/xlint/common/tyname.c:1.59	Thu Feb  1 18:37:06 2024
+++ src/usr.bin/xlint/common/tyname.c	Thu Feb  1 21:19:13 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tyname.c,v 1.59 2024/02/01 18:37:06 rillig Exp $	*/
+/*	$NetBSD: tyname.c,v 1.60 2024/02/01 21:19:13 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tyname.c,v 1.59 2024/02/01 18:37:06 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.60 2024/02/01 21:19:13 rillig Exp $");
 #endif
 
 #include 
@@ -94,7 +94,7 @@ intern(const char *name)
 	return n->ntn_name;
 }
 
-static void
+void
 buf_init(buffer *buf)
 {
 	buf->len = 0;
@@ -110,17 +110,28 @@ buf_done(buffer *buf)
 }
 
 static void
-buf_add(buffer *buf, const char *s)
+buf_add_mem(buffer *buf, const char *s, size_t n)
 {
-	size_t len = strlen(s);
-
-	while (buf->len + len + 1 >= buf->cap) {
-		buf->data = xrealloc(buf->data, 2 * buf->cap);
-		buf->cap = 2 * buf->cap;
+	while (buf->len + n + 1 >= buf->cap) {
+		buf->cap *= 2;
+		buf->data = xrealloc(buf->data, buf->cap);
 	}
 
-	memcpy(buf->data + buf->len, s, len + 1);
-	buf->len += len;
+	memcpy(buf->data + buf->len, s, n);
+	buf->len += n;
+	buf->data[buf->len] = '\0';
+}
+
+void
+buf_add_char(buffer *buf, char c)
+{
+	buf_add_mem(buf, , 1);
+}
+
+static void
+buf_add(buffer *buf, const char *s)
+{
+	buf_add_mem(buf, s, strlen(s));
 }
 
 static void

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.205 src/usr.bin/xlint/lint1/lex.c:1.206
--- src/usr.bin/xlint/lint1/lex.c:1.205	Thu Feb  1 18:37:06 2024
+++ src/usr.bin/xlint/lint1/lex.c	Thu Feb  1 21:19:13 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.205 2024/02/01 18:37:06 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.206 2024/02/01 21:19:13 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.205 2024/02/01 18:37:06 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.206 2024/02/01 21:19:13 rillig Exp $");
 #endif
 
 #include 
@@ -1259,27 +1259,18 @@ clear_warn_flags(void)
 int
 lex_string(void)
 {
-	size_t s_len = 0;
-	size_t s_cap = 64;
-	char *s = xmalloc(s_cap);
+	buffer *buf = xcalloc(1, sizeof(*buf));
+	buf_init(buf);
 
 	int c;
-	while ((c = get_escaped_char('"')) >= 0) {
-		/* +1 to reserve space for a trailing NUL character */
-		if (s_len + 1 == s_cap)
-			s = xrealloc(s, s_cap *= 2);
-		s[s_len++] = (char)c;
-	}
-	s[s_len] = '\0';
+	while ((c = get_escaped_char('"')) >= 0)
+		buf_add_char(buf, (char)c);
 	if (c == -2)
 		/* unterminated string constant */
 		error(258);
 
-	buffer *str = xcalloc(1, sizeof(*str));
-	str->len = s_len;
-	str->data = s;
 
-	yylval.y_string = str;
+	yylval.y_string = buf;
 	return T_STRING;
 }
 
@@ -1288,15 +1279,10 @@ lex_wide_string(void)
 {
 	int c, n;
 
-	size_t len = 0, max = 64;
-	char *s = xmalloc(max);
-	while ((c = get_escaped_char('"')) >= 0) {
-		/* +1 to save space for a trailing NUL character */
-		if (len + 1 >= max)
-			s = xrealloc(s, max *= 2);
-		s[len++] = (char)c;
-	}
-	s[len] = '\0';
+	buffer buf;
+	buf_init();
+	while ((c = get_escaped_char('"')) >= 0)
+		buf_add_char(, (char)c);
 	if (c == -2)
 		/* unterminated string constant */
 		error(258);
@@ -1304,8 +1290,8 @@ lex_wide_string(void)
 	/* get length of wide-character string */
 	(void)mblen(NULL, 0);
 	size_t 

CVS commit: src/usr.bin/xlint

2024-02-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  1 21:19:13 UTC 2024

Modified Files:
src/usr.bin/xlint/common: externs.h tyname.c
src/usr.bin/xlint/lint1: lex.c tree.c

Log Message:
lint: reuse buffer editing code across lint1

Fix cat_strings to update the capacity of the buffer, to prevent
quadratic runtime when concatenating string literals.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/xlint/common/externs.h
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.205 -r1.206 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.600 -r1.601 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

2024-02-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  1 18:37:07 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h tyname.c
src/usr.bin/xlint/lint1: cgram.y ckgetopt.c debug.c emit1.c externs1.h
init.c lex.c lint1.h tree.c

Log Message:
lint: use standard buffer for storing string values

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.484 -r1.485 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.256 -r1.257 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.204 -r1.205 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.210 -r1.211 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.599 -r1.600 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/common/lint.h
diff -u src/usr.bin/xlint/common/lint.h:1.47 src/usr.bin/xlint/common/lint.h:1.48
--- src/usr.bin/xlint/common/lint.h:1.47	Sat Jan 20 10:25:57 2024
+++ src/usr.bin/xlint/common/lint.h	Thu Feb  1 18:37:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: lint.h,v 1.47 2024/01/20 10:25:57 rillig Exp $	*/
+/*	$NetBSD: lint.h,v 1.48 2024/02/01 18:37:06 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -48,6 +48,14 @@
 #include "param.h"
 
 #if IS_LINT1 || IS_LINT2
+
+// Null-terminated character buffer, may contain null characters.
+typedef struct {
+	size_t	len;		/* excluding the terminating '\0' */
+	size_t	cap;
+	char	*data;
+} buffer;
+
 /*
  * Type specifiers, used in type structures (type_t) and elsewhere.
  */

Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.58 src/usr.bin/xlint/common/tyname.c:1.59
--- src/usr.bin/xlint/common/tyname.c:1.58	Sat Jan 20 10:25:57 2024
+++ src/usr.bin/xlint/common/tyname.c	Thu Feb  1 18:37:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tyname.c,v 1.58 2024/01/20 10:25:57 rillig Exp $	*/
+/*	$NetBSD: tyname.c,v 1.59 2024/02/01 18:37:06 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: tyname.c,v 1.58 2024/01/20 10:25:57 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.59 2024/02/01 18:37:06 rillig Exp $");
 #endif
 
 #include 
@@ -56,13 +56,6 @@ typedef struct name_tree_node {
 	struct name_tree_node *ntn_greater;
 } name_tree_node;
 
-/* A growable string buffer. */
-typedef struct buffer {
-	size_t	len;
-	size_t	cap;
-	char *	data;
-} buffer;
-
 static name_tree_node *type_names;
 
 static name_tree_node *

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.484 src/usr.bin/xlint/lint1/cgram.y:1.485
--- src/usr.bin/xlint/lint1/cgram.y:1.484	Tue Jan 23 19:44:28 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Feb  1 18:37:06 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.484 2024/01/23 19:44:28 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.485 2024/02/01 18:37:06 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.484 2024/01/23 19:44:28 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.485 2024/02/01 18:37:06 rillig Exp $");
 #endif
 
 #include 
@@ -148,7 +148,7 @@ is_either(const char *s, const char *a, 
 	type_t	*y_type;
 	tnode_t	*y_tnode;
 	range_t	y_range;
-	strg_t	*y_string;
+	buffer	*y_string;
 	qual_ptr *y_qual_ptr;
 	bool	y_seen_statement;
 	struct generic_association *y_generic;

Index: src/usr.bin/xlint/lint1/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.19 src/usr.bin/xlint/lint1/ckgetopt.c:1.20
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.19	Mon Jan 29 21:30:24 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Thu Feb  1 18:37:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.19 2024/01/29 21:30:24 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.20 2024/02/01 18:37:06 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.19 2024/01/29 21:30:24 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.20 2024/02/01 18:37:06 rillig Exp $");
 #endif
 
 #include 
@@ -80,7 +80,7 @@ static bool
 is_getopt_condition(const tnode_t *tn, char **out_options)
 {
 	const tnode_t *call, *last_arg;
-	const strg_t *str;
+	const buffer *str;
 
 	if (tn != NULL
 	&& tn->tn_op == NE
@@ -99,8 +99,8 @@ is_getopt_condition(const tnode_t *tn, c
 	&& (last_arg = call->tn_right->tn_left)->tn_op == CVT
 	&& last_arg->tn_left->tn_op == ADDR
 	&& last_arg->tn_left->tn_left->tn_op == STRING
-	&& (str 

CVS commit: src/usr.bin/xlint

2024-02-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Feb  1 18:37:07 UTC 2024

Modified Files:
src/usr.bin/xlint/common: lint.h tyname.c
src/usr.bin/xlint/lint1: cgram.y ckgetopt.c debug.c emit1.c externs1.h
init.c lex.c lint1.h tree.c

Log Message:
lint: use standard buffer for storing string values

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.484 -r1.485 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.256 -r1.257 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.204 -r1.205 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.210 -r1.211 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.599 -r1.600 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-01-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jan 29 21:30:25 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c lex.c lint1.h
tree.c

Log Message:
lint: do not remember content of wide string literals

The plain char literals are needed for checking printf/scanf format
strings; lint has no similar check for wide strings. These format
strings are checked by modern compilers, making this check less
relevant.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.203 -r1.204 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.598 -r1.599 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/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.18 src/usr.bin/xlint/lint1/ckgetopt.c:1.19
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.18	Mon Jan 29 21:04:21 2024
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Mon Jan 29 21:30:24 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.19 2024/01/29 21:30:24 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.19 2024/01/29 21:30:24 rillig Exp $");
 #endif
 
 #include 
@@ -100,7 +100,7 @@ is_getopt_condition(const tnode_t *tn, c
 	&& last_arg->tn_left->tn_op == ADDR
 	&& last_arg->tn_left->tn_left->tn_op == STRING
 	&& (str = last_arg->tn_left->tn_left->tn_string)->st_char) {
-		*out_options = xstrdup(str->st_mem);
+		*out_options = xstrdup(str->st_chars);
 		return true;
 	}
 	return false;

Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.66 src/usr.bin/xlint/lint1/debug.c:1.67
--- src/usr.bin/xlint/lint1/debug.c:1.66	Tue Jan 23 19:44:28 2024
+++ src/usr.bin/xlint/lint1/debug.c	Mon Jan 29 21:30:24 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.66 2024/01/23 19:44:28 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.67 2024/01/29 21:30:24 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.66 2024/01/23 19:44:28 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.67 2024/01/29 21:30:24 rillig Exp $");
 #endif
 
 #include 
@@ -238,15 +238,9 @@ debug_node(const tnode_t *tn) // NOLINT(
 		if (tn->tn_string->st_char)
 			debug_printf(", length %zu, \"%s\"\n",
 			tn->tn_string->st_len,
-			(const char *)tn->tn_string->st_mem);
-		else {
-			size_t n = MB_CUR_MAX * (tn->tn_string->st_len + 1);
-			char *s = xmalloc(n);
-			(void)wcstombs(s, tn->tn_string->st_mem, n);
-			debug_printf(", length %zu, L\"%s\"\n",
-			tn->tn_string->st_len, s);
-			free(s);
-		}
+			tn->tn_string->st_chars);
+		else
+			debug_printf(", length %zu\n", tn->tn_string->st_len);
 		break;
 	default:
 		debug_printf("\n");

Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.81 src/usr.bin/xlint/lint1/emit1.c:1.82
--- src/usr.bin/xlint/lint1/emit1.c:1.81	Sun Dec  3 18:17:41 2023
+++ src/usr.bin/xlint/lint1/emit1.c	Mon Jan 29 21:30:24 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.81 2023/12/03 18:17:41 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.82 2024/01/29 21:30:24 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.81 2023/12/03 18:17:41 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.82 2024/01/29 21:30:24 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -450,17 +450,13 @@ outqchar(char c)
 static void
 outfstrg(strg_t *strg)
 {
-	char c, oc;
-	bool first;
-	const char *cp;
 
 	lint_assert(strg->st_char);
-	cp = strg->st_mem;
+	const char *cp = strg->st_chars;
 
 	outchar('"');
 
-	c = *cp++;
-
+	char c = *cp++;
 	while (c != '\0') {
 
 		if (c != '%') {
@@ -511,7 +507,7 @@ outfstrg(strg_t *strg)
 		 */
 		if (c != '\0') {
 			outqchar(c);
-			oc = c;
+			char oc = c;
 			c = *cp++;
 			/*
 			 * handle [ for scanf. [-] means that a minus sign was
@@ -522,7 +518,7 @@ outfstrg(strg_t *strg)
 	c = *cp++;
 if (c == ']')
 	c = *cp++;
-first = true;
+bool first = true;
 while (c != '\0' && c != ']') {
 	if (c == '-') {
 		if (!first && *cp != ']')

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.203 src/usr.bin/xlint/lint1/lex.c:1.204
--- src/usr.bin/xlint/lint1/lex.c:1.203	Sat Jan 27 20:03:14 2024
+++ src/usr.bin/xlint/lint1/lex.c	Mon Jan 29 21:30:25 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: 

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

2024-01-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jan 29 21:30:25 UTC 2024

Modified Files:
src/usr.bin/xlint/lint1: ckgetopt.c debug.c emit1.c lex.c lint1.h
tree.c

Log Message:
lint: do not remember content of wide string literals

The plain char literals are needed for checking printf/scanf format
strings; lint has no similar check for wide strings. These format
strings are checked by modern compilers, making this check less
relevant.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint1/ckgetopt.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.203 -r1.204 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.598 -r1.599 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-01-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jan 29 21:04:21 UTC 2024

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

Log Message:
lint: check getopt call more strictly

Previously, '(c = getopt(...)) != -2' would match as well.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/ckgetopt.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/ckgetopt.c
diff -u src/usr.bin/xlint/lint1/ckgetopt.c:1.17 src/usr.bin/xlint/lint1/ckgetopt.c:1.18
--- src/usr.bin/xlint/lint1/ckgetopt.c:1.17	Sun Dec  3 13:12:40 2023
+++ src/usr.bin/xlint/lint1/ckgetopt.c	Mon Jan 29 21:04:21 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.17 2023/12/03 13:12:40 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckgetopt.c,v 1.17 2023/12/03 13:12:40 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.18 2024/01/29 21:04:21 rillig Exp $");
 #endif
 
 #include 
@@ -75,38 +75,35 @@ static struct {
 	int switch_level;
 } ck;
 
-#define NEED(cond) \
-	do {\
-		if (!(cond))		\
-			return false;	\
-	} while (false)
-
-/* Return whether tn has the form 'getopt(argc, argv, "literal") != -1'. */
+/* Return whether tn has the form '(c = getopt(argc, argv, "str")) != -1'. */
 static bool
 is_getopt_condition(const tnode_t *tn, char **out_options)
 {
 	const tnode_t *call, *last_arg;
+	const strg_t *str;
 
-	NEED(tn != NULL);
-	NEED(tn->tn_op == NE);
-	NEED(tn->tn_left->tn_op == ASSIGN);
-
-	call = tn->tn_left->tn_right;
-	NEED(call->tn_op == CALL);
-	NEED(call->tn_left->tn_op == ADDR);
-	NEED(call->tn_left->tn_left->tn_op == NAME);
-	NEED(strcmp(call->tn_left->tn_left->tn_sym->s_name, "getopt") == 0);
-
-	NEED(call->tn_right->tn_op == PUSH);
-
-	last_arg = call->tn_right->tn_left;
-	NEED(last_arg->tn_op == CVT);
-	NEED(last_arg->tn_left->tn_op == ADDR);
-	NEED(last_arg->tn_left->tn_left->tn_op == STRING);
-	NEED(last_arg->tn_left->tn_left->tn_string->st_char);
-
-	*out_options = xstrdup(last_arg->tn_left->tn_left->tn_string->st_mem);
-	return true;
+	if (tn != NULL
+	&& tn->tn_op == NE
+	&& tn->tn_left->tn_op == ASSIGN
+	&& tn->tn_right->tn_op == CON
+	&& tn->tn_right->tn_u._tn_val.v_tspec == INT
+	&& tn->tn_right->tn_u._tn_val.u.integer == -1
+
+	&& (call = tn->tn_left->tn_right)->tn_op == CALL
+	&& call->tn_left->tn_op == ADDR
+	&& call->tn_left->tn_left->tn_op == NAME
+	&& strcmp(call->tn_left->tn_left->tn_sym->s_name, "getopt") == 0
+
+	&& call->tn_right->tn_op == PUSH
+
+	&& (last_arg = call->tn_right->tn_left)->tn_op == CVT
+	&& last_arg->tn_left->tn_op == ADDR
+	&& last_arg->tn_left->tn_left->tn_op == STRING
+	&& (str = last_arg->tn_left->tn_left->tn_string)->st_char) {
+		*out_options = xstrdup(str->st_mem);
+		return true;
+	}
+	return false;
 }
 
 static void



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

2024-01-29 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jan 29 21:04:21 UTC 2024

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

Log Message:
lint: check getopt call more strictly

Previously, '(c = getopt(...)) != -2' would match as well.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint1/ckgetopt.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-01-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jan 27 15:53:28 UTC 2024

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

Log Message:
lint: split determining the type of an integer constant

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/lex.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/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.201 src/usr.bin/xlint/lint1/lex.c:1.202
--- src/usr.bin/xlint/lint1/lex.c:1.201	Sat Jan 27 12:14:58 2024
+++ src/usr.bin/xlint/lint1/lex.c	Sat Jan 27 15:53:27 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.201 2024/01/27 12:14:58 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.202 2024/01/27 15:53:27 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.201 2024/01/27 12:14:58 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.202 2024/01/27 15:53:27 rillig Exp $");
 #endif
 
 #include 
@@ -502,6 +502,67 @@ is_unsigned_since_c90(tspec_t typ, uint6
 	return typ == LONG && ui > TARG_LONG_MAX;
 }
 
+static tspec_t
+integer_constant_type(tspec_t typ, uint64_t ui, int base, bool warned)
+{
+	switch (typ) {
+	case INT:
+		if (ui <= TARG_INT_MAX) {
+			/* ok */
+		} else if (ui <= TARG_UINT_MAX && base != 10) {
+			typ = UINT;
+		} else if (ui <= TARG_LONG_MAX) {
+			typ = LONG;
+		} else {
+			typ = ULONG;
+			if (ui > TARG_ULONG_MAX && !warned) {
+/* integer constant out of range */
+warning(252);
+			}
+		}
+		if ((typ == UINT || typ == ULONG) && !allow_c90)
+			typ = LONG;
+		break;
+	case UINT:
+		if (ui > TARG_UINT_MAX) {
+			typ = ULONG;
+			if (ui > TARG_ULONG_MAX && !warned) {
+/* integer constant out of range */
+warning(252);
+			}
+		}
+		break;
+	case LONG:
+		if (ui > TARG_LONG_MAX && allow_c90) {
+			typ = ULONG;
+			if (ui > TARG_ULONG_MAX && !warned) {
+/* integer constant out of range */
+warning(252);
+			}
+		}
+		break;
+	case ULONG:
+		if (ui > TARG_ULONG_MAX && !warned) {
+			/* integer constant out of range */
+			warning(252);
+		}
+		break;
+	case LLONG:
+		if (ui > TARG_LLONG_MAX && allow_c90)
+			typ = ULLONG;
+		break;
+	case ULLONG:
+		if (ui > TARG_ULLONG_MAX && !warned) {
+			/* integer constant out of range */
+			warning(252);
+		}
+		break;
+	default:
+		break;
+	}
+	return typ;
+}
+
 int
 lex_integer_constant(const char *yytext, size_t yyleng, int base)
 {
@@ -543,7 +604,7 @@ lex_integer_constant(const char *yytext,
 		/* suffix 'U' is illegal in traditional C */
 		warning(97);
 	}
-	tspec_t typ = suffix_type[u_suffix][l_suffix];
+	tspec_t ct = suffix_type[u_suffix][l_suffix];
 
 	bool warned = false;
 	errno = 0;
@@ -561,67 +622,13 @@ lex_integer_constant(const char *yytext,
 		query_message(8, (int)len, cp);
 	}
 
-	bool ansiu = is_unsigned_since_c90(typ, ui, base);
-	switch (typ) {
-	case INT:
-		if (ui <= TARG_INT_MAX) {
-			/* ok */
-		} else if (ui <= TARG_UINT_MAX && base != 10) {
-			typ = UINT;
-		} else if (ui <= TARG_LONG_MAX) {
-			typ = LONG;
-		} else {
-			typ = ULONG;
-			if (ui > TARG_ULONG_MAX && !warned) {
-/* integer constant out of range */
-warning(252);
-			}
-		}
-		if ((typ == UINT || typ == ULONG) && !allow_c90)
-			typ = LONG;
-		break;
-	case UINT:
-		if (ui > TARG_UINT_MAX) {
-			typ = ULONG;
-			if (ui > TARG_ULONG_MAX && !warned) {
-/* integer constant out of range */
-warning(252);
-			}
-		}
-		break;
-	case LONG:
-		if (ui > TARG_LONG_MAX && allow_c90) {
-			typ = ULONG;
-			if (ui > TARG_ULONG_MAX && !warned) {
-/* integer constant out of range */
-warning(252);
-			}
-		}
-		break;
-	case ULONG:
-		if (ui > TARG_ULONG_MAX && !warned) {
-			/* integer constant out of range */
-			warning(252);
-		}
-		break;
-	case LLONG:
-		if (ui > TARG_LLONG_MAX && allow_c90)
-			typ = ULLONG;
-		break;
-	case ULLONG:
-		if (ui > TARG_ULLONG_MAX && !warned) {
-			/* integer constant out of range */
-			warning(252);
-		}
-		break;
-	default:
-		break;
-	}
+	bool ansiu = is_unsigned_since_c90(ct, ui, base);
 
-	ui = (uint64_t)convert_integer((int64_t)ui, typ, 0);
+	tspec_t t = integer_constant_type(ct, ui, base, warned);
+	ui = (uint64_t)convert_integer((int64_t)ui, t, 0);
 
 	yylval.y_val = xcalloc(1, sizeof(*yylval.y_val));
-	yylval.y_val->v_tspec = typ;
+	yylval.y_val->v_tspec = t;
 	yylval.y_val->v_unsigned_since_c90 = ansiu;
 	yylval.y_val->u.integer = (int64_t)ui;
 



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

2024-01-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jan 27 15:53:28 UTC 2024

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

Log Message:
lint: split determining the type of an integer constant

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/lex.c

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



  1   2   3   4   5   6   7   8   9   10   >