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

2021-08-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 17 22:29:11 UTC 2021

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

Log Message:
lint: extract suppress_messages from main

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 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/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.55 src/usr.bin/xlint/lint1/main1.c:1.56
--- src/usr.bin/xlint/lint1/main1.c:1.55	Tue Aug 17 21:19:02 2021
+++ src/usr.bin/xlint/lint1/main1.c	Tue Aug 17 22:29:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main1.c,v 1.55 2021/08/17 21:19:02 rillig Exp $	*/
+/*	$NetBSD: main1.c,v 1.56 2021/08/17 22:29:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.55 2021/08/17 21:19:02 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.56 2021/08/17 22:29:11 rillig Exp $");
 #endif
 
 #include 
@@ -168,11 +168,28 @@ sigfpe(int s)
 	fpe = 1;
 }
 
+static void
+suppress_messages(char *ids)
+{
+	char *ptr, *end;
+	long id;
+
+	for (ptr = strtok(ids, ","); ptr != NULL; ptr = strtok(NULL, ",")) {
+		errno = 0;
+		id = strtol(ptr, , 0);
+		if ((id == TARG_LONG_MIN || id == TARG_LONG_MAX) &&
+		errno == ERANGE)
+			err(1, "invalid error message id '%s'", ptr);
+		if (*end != '\0' || ptr == end || id < 0 || id >= ERR_SETSIZE)
+			errx(1, "invalid error message id '%s'", ptr);
+		ERR_SET(id, );
+	}
+}
+
 int
 main(int argc, char *argv[])
 {
-	int	c;
-	char	*ptr;
+	int c;
 
 	setprogname(argv[0]);
 
@@ -217,23 +234,7 @@ main(int argc, char *argv[])
 			break;
 
 		case 'X':
-			for (ptr = strtok(optarg, ","); ptr != NULL;
-			ptr = strtok(NULL, ",")) {
-char *eptr;
-long msg;
-
-errno = 0;
-msg = strtol(ptr, , 0);
-if ((msg == TARG_LONG_MIN || msg == TARG_LONG_MAX) &&
-errno == ERANGE)
-err(1, "invalid error message id '%s'",
-	ptr);
-if (*eptr != '\0' || ptr == eptr || msg < 0 ||
-msg >= ERR_SETSIZE)
-	errx(1, "invalid error message id '%s'",
-	ptr);
-ERR_SET(msg, );
-			}
+			suppress_messages(optarg);
 			break;
 		default:
 			usage();



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

2021-08-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 17 21:19:02 UTC 2021

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

Log Message:
lint: sync usage message with reality


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 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/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.54 src/usr.bin/xlint/lint1/main1.c:1.55
--- src/usr.bin/xlint/lint1/main1.c:1.54	Tue Aug 17 21:05:34 2021
+++ src/usr.bin/xlint/lint1/main1.c	Tue Aug 17 21:19:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main1.c,v 1.54 2021/08/17 21:05:34 rillig Exp $	*/
+/*	$NetBSD: main1.c,v 1.55 2021/08/17 21:19:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.54 2021/08/17 21:05:34 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.55 2021/08/17 21:19:02 rillig Exp $");
 #endif
 
 #include 
@@ -290,9 +290,9 @@ static void __attribute__((noreturn))
 usage(void)
 {
 	(void)fprintf(stderr,
-	"usage: %s [-abcdeghmprstuvwyzFST] [-Ac11] [-X [,]... "
-	"src dest\n",
-	getprogname());
+	"usage: %s [-abceghmprstuvwyzFPST] [-Ac11] [-R old=new]\n"
+	"   %*s [-X [,]...] src dest\n",
+	getprogname(), (int)strlen(getprogname()), "");
 	exit(1);
 }
 



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

2021-08-17 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 17 21:05:34 UTC 2021

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

Log Message:
lint: move GCC builtins into gcc_builtins

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 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/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.53 src/usr.bin/xlint/lint1/main1.c:1.54
--- src/usr.bin/xlint/lint1/main1.c:1.53	Sun Aug  1 19:11:54 2021
+++ src/usr.bin/xlint/lint1/main1.c	Tue Aug 17 21:05:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main1.c,v 1.53 2021/08/01 19:11:54 rillig Exp $	*/
+/*	$NetBSD: main1.c,v 1.54 2021/08/17 21:05:34 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.53 2021/08/01 19:11:54 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.54 2021/08/17 21:05:34 rillig Exp $");
 #endif
 
 #include 
@@ -130,16 +130,15 @@ sig_atomic_t fpe;
 
 static	void	usage(void);
 
-static const char builtins[] =
-"int __builtin_isinf(long double);\n"
-"int __builtin_isnan(long double);\n"
-"int __builtin_copysign(long double, long double);\n"
-;
-static const size_t builtinlen = sizeof(builtins) - 1;
-
 static FILE *
 gcc_builtins(void)
 {
+	static const char builtins[] =
+	"int __builtin_isinf(long double);\n"
+	"int __builtin_isnan(long double);\n"
+	"int __builtin_copysign(long double, long double);\n";
+	size_t builtins_len = sizeof(builtins) - 1;
+
 #if HAVE_NBTOOL_CONFIG_H
 	char template[] = "/tmp/lint.XX";
 	int fd;
@@ -151,14 +150,14 @@ gcc_builtins(void)
 		close(fd);
 		return NULL;
 	}
-	if (fwrite(builtins, 1, builtinlen, fp) != builtinlen) {
+	if (fwrite(builtins, 1, builtins_len, fp) != builtins_len) {
 		fclose(fp);
 		return NULL;
 	}
 	rewind(fp);
 	return fp;
 #else
-	return fmemopen(__UNCONST(builtins), builtinlen, "r");
+	return fmemopen(__UNCONST(builtins), builtins_len, "r");
 #endif
 }
 



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

2021-08-16 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Aug 16 18:51:03 UTC 2021

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

Log Message:
lint: remove dead code from check_bad_enum_operation

There is a single caller of that function, and it checks the exact same
condition beforehand.


To generate a diff of this commit:
cvs rdiff -u -r1.336 -r1.337 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.336 src/usr.bin/xlint/lint1/tree.c:1.337
--- src/usr.bin/xlint/lint1/tree.c:1.336	Sun Aug 15 14:26:39 2021
+++ src/usr.bin/xlint/lint1/tree.c	Mon Aug 16 18:51:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.336 2021/08/15 14:26:39 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.337 2021/08/16 18:51:03 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.336 2021/08/15 14:26:39 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.337 2021/08/16 18:51:03 rillig Exp $");
 #endif
 
 #include 
@@ -1587,11 +1587,6 @@ check_bad_enum_operation(op_t op, const 
 	if (!eflag)
 		return;
 
-	if (!(ln->tn_type->t_is_enum ||
-	  (modtab[op].m_binary && rn->tn_type->t_is_enum))) {
-		return;
-	}
-
 	/*
 	 * Enum as offset to a pointer is an exception (otherwise enums
 	 * could not be used as array indices).
@@ -1604,7 +1599,6 @@ check_bad_enum_operation(op_t op, const 
 
 	/* dubious operation on enum, op %s */
 	warning(241, op_name(op));
-
 }
 
 /*



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

2021-08-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 10 19:52:14 UTC 2021

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

Log Message:
lint: remove redundant test for negative bit-field size

A bit-field can never have negative size.  Its type is an unsigned
integer.

Strangely, GCC 10.3.0 only complains about this if the extra struct
level lint1_type.t_b is removed.  Clang 12.0.1 does not complain at all.


To generate a diff of this commit:
cvs rdiff -u -r1.219 -r1.220 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.219 src/usr.bin/xlint/lint1/decl.c:1.220
--- src/usr.bin/xlint/lint1/decl.c:1.219	Tue Aug  3 21:18:24 2021
+++ src/usr.bin/xlint/lint1/decl.c	Tue Aug 10 19:52:14 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.219 2021/08/03 21:18:24 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.220 2021/08/10 19:52:14 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.219 2021/08/03 21:18:24 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.220 2021/08/10 19:52:14 rillig Exp $");
 #endif
 
 #include 
@@ -1151,7 +1151,7 @@ declare_bit_field(sym_t *dsym, tspec_t *
 
 	type_t *const tp = *inout_tp;
 	tspec_t const t = *inout_t;
-	if (tp->t_flen < 0 || tp->t_flen > (ssize_t)size_in_bits(t)) {
+	if (tp->t_flen > size_in_bits(t)) {
 		/* illegal bit-field size: %d */
 		error(36, tp->t_flen);
 		tp->t_flen = size_in_bits(t);



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

2021-08-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 10 17:57:16 UTC 2021

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

Log Message:
lint: remove redundant function prototypes


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/xlint/lint1/mem1.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/mem1.c
diff -u src/usr.bin/xlint/lint1/mem1.c:1.48 src/usr.bin/xlint/lint1/mem1.c:1.49
--- src/usr.bin/xlint/lint1/mem1.c:1.48	Tue Aug 10 17:31:44 2021
+++ src/usr.bin/xlint/lint1/mem1.c	Tue Aug 10 17:57:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mem1.c,v 1.48 2021/08/10 17:31:44 rillig Exp $	*/
+/*	$NetBSD: mem1.c,v 1.49 2021/08/10 17:57:16 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem1.c,v 1.48 2021/08/10 17:31:44 rillig Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.49 2021/08/10 17:57:16 rillig Exp $");
 #endif
 
 #include 
@@ -205,9 +205,6 @@ static	memory_block	*frmblks;
 /* length of new allocated memory blocks */
 static	size_t	mblklen;
 
-static	void	*xgetblk(memory_block **, size_t);
-static	void	xfreeblk(memory_block **);
-static	memory_block *xnewblk(void);
 
 static memory_block *
 xnewblk(void)



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

2021-08-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 10 16:59:28 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: ops.def

Log Message:
lint: fix documentation of FARG and PUSH


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

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/ops.def
diff -u src/usr.bin/xlint/lint1/ops.def:1.22 src/usr.bin/xlint/lint1/ops.def:1.23
--- src/usr.bin/xlint/lint1/ops.def:1.22	Tue Aug 10 07:02:00 2021
+++ src/usr.bin/xlint/lint1/ops.def	Tue Aug 10 16:59:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ops.def,v 1.22 2021/08/10 07:02:00 rillig Exp $ */
+/*	$NetBSD: ops.def,v 1.23 2021/08/10 16:59:28 rillig Exp $ */
 
 begin_ops()
 
@@ -93,6 +93,12 @@ op(	COMMA,	",",		1,-,1,-,-,-,-,-,-,-,-,-
 op(	CVT,	"convert",	-,-,-,-,-,-,-,-,-,1,-,-,-,-,-,-,-,-,-,-)
 op(	ICALL,	"icall",	1,-,-,-,-,-,-,-,-,-,-,-,1,-,-,-,-,-,-,-)
 op(	LOAD,	"load",		-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-)
+/*
+ * PUSH is a virtual node that is used to concatenate arguments in a function
+ * call expression.  The PUSH nodes are ordered from right to left.  For
+ * example, the function call f(17, 23) is represented as
+ * CALL(f, PUSH(23, PUSH(17, NULL))).
+ */
 op(	PUSH,	"push",		-,-,-,-,-,-,-,-,-,1,-,-,-,-,-,-,-,-,-,-)
 op(	RETURN,	"return",	1,-,1,-,-,-,-,-,-,-,-,-,1,-,-,-,-,1,-,-)
 op(	REAL,	"real",		-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-)
@@ -102,17 +108,11 @@ op(	IMAG,	"imag",		-,-,-,-,-,-,-,-,-,-,-
 /*	name	repr		b l b B i c a s f v t b s l r p c e e = */
 op(	INIT,	"init",		1,-,1,-,-,-,-,-,-,-,-,-,-,-,-,-,-,1,-,-)
 op(	CASE,	"case",		-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-)
-op(	FARG,	"farg",		1,-,1,-,-,-,-,-,-,-,-,-,-,-,-,-,-,1,-,-)
-
 /*
- * Both FARG and PUSH represent function arguments.  FARG is used in the
- * early phase of analysis, when the node is not yet part of a function call
- * expression (CALL or ICALL).  Later, build_function_argument builds a
- * function call expression out of the FARG nodes, where they become PUSH.
- * In a function call expression, the PUSH nodes are ordered from right to
- * left, that is, the function call f(17, 23) is represented as
- * CALL(f, PUSH(23, PUSH(17, NULL))).
+ * FARG is only used temporarily in check_prototype_argument to check type
+ * compatibility and conversion for function arguments.
  */
+op(	FARG,	"farg",		1,-,1,-,-,-,-,-,-,-,-,-,-,-,-,-,-,1,-,-)
 
 end_ops()
 



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

2021-08-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 10 07:02:00 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: ops.def

Log Message:
lint: document the difference between FARG and PUSH


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/ops.def

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/ops.def
diff -u src/usr.bin/xlint/lint1/ops.def:1.21 src/usr.bin/xlint/lint1/ops.def:1.22
--- src/usr.bin/xlint/lint1/ops.def:1.21	Tue Aug 10 06:31:16 2021
+++ src/usr.bin/xlint/lint1/ops.def	Tue Aug 10 07:02:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ops.def,v 1.21 2021/08/10 06:31:16 rillig Exp $ */
+/*	$NetBSD: ops.def,v 1.22 2021/08/10 07:02:00 rillig Exp $ */
 
 begin_ops()
 
@@ -104,6 +104,16 @@ op(	INIT,	"init",		1,-,1,-,-,-,-,-,-,-,-
 op(	CASE,	"case",		-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-)
 op(	FARG,	"farg",		1,-,1,-,-,-,-,-,-,-,-,-,-,-,-,-,-,1,-,-)
 
+/*
+ * Both FARG and PUSH represent function arguments.  FARG is used in the
+ * early phase of analysis, when the node is not yet part of a function call
+ * expression (CALL or ICALL).  Later, build_function_argument builds a
+ * function call expression out of the FARG nodes, where they become PUSH.
+ * In a function call expression, the PUSH nodes are ordered from right to
+ * left, that is, the function call f(17, 23) is represented as
+ * CALL(f, PUSH(23, PUSH(17, NULL))).
+ */
+
 end_ops()
 
 #ifndef NOPS



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

2021-08-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Aug 10 06:31:16 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: ops.def

Log Message:
lint: document operator properties directly at the definition


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/ops.def

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/ops.def
diff -u src/usr.bin/xlint/lint1/ops.def:1.20 src/usr.bin/xlint/lint1/ops.def:1.21
--- src/usr.bin/xlint/lint1/ops.def:1.20	Thu Apr  1 14:59:21 2021
+++ src/usr.bin/xlint/lint1/ops.def	Tue Aug 10 06:31:16 2021
@@ -1,9 +1,31 @@
-/*	$NetBSD: ops.def,v 1.20 2021/04/01 14:59:21 rillig Exp $ */
+/*	$NetBSD: ops.def,v 1.21 2021/08/10 06:31:16 rillig Exp $ */
 
 begin_ops()
 
-/* See mod_t in op.h for the definition of the table columns. */
-
+/*
+ * Operator properties; see mod_t in op.h.
+ *
+ * 	warn if operand '='	  x
+ *	bad on enum		x
+ *	valid on enum		  x
+ *	comparison		- - - - - - - - - - - - - - - - x
+ *	possible precedence confusion			  x	|
+ *	warn if right operand unsigned			x	|
+ *	warn if left operand unsigned			  x	|
+ *	has side effects	- - - - - - - - - - - - x	|
+ *	balance operands			  x	|	|
+ *	left test context			x	|	|
+ *	left value context			  x	|	|
+ *	fold constant operands	- - - - - - - - x	|	|
+ *	requires scalar			  x	|	|	|
+ *	requires arithmetic		x	|	|	|
+ *	requires integer or complex	  x	|	|	|
+ *	requires integer	- - - - x	|	|	|
+ *	requires _Bool		  x	|	|	|	|
+ *	takes _Bool		x	|	|	|	|
+ *	logical			  x	|	|	|	|
+ *	binary			x	|	|	|	|
+ */
 /*	name	repr		b l b B i c a s f v t b s l r p c e e =	*/
 op(	NOOP,	"no-op",	-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-)
 op(	ARROW,	"->",		1,-,1,-,-,-,-,-,-,1,-,-,-,-,-,-,-,-,-,-)



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

2021-08-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  8 10:41:34 UTC 2021

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

Log Message:
lint: condense code for writing the .ln files

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/xlint/lint1/emit1.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/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.47 src/usr.bin/xlint/lint1/emit1.c:1.48
--- src/usr.bin/xlint/lint1/emit1.c:1.47	Sat Jul 31 19:52:44 2021
+++ src/usr.bin/xlint/lint1/emit1.c	Sun Aug  8 10:41:34 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.47 2021/07/31 19:52:44 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.48 2021/08/08 10:41:34 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit1.c,v 1.47 2021/07/31 19:52:44 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.48 2021/08/08 10:41:34 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -227,26 +227,19 @@ outsym(const sym_t *sym, scl_t sc, def_t
 
 	/* flags */
 
-	switch (def) {
-	case DEF:
-		/* defined */
-		outchar('d');
-		break;
-	case TDEF:
-		/* tentative defined */
-		outchar('t');
-		break;
-	case DECL:
-		/* declared */
-		outchar('e');
-		break;
-	default:
-		lint_assert(/*CONSTCOND*/false);
+	if (def == DEF)
+		outchar('d');	/* defined */
+	else if (def == TDEF)
+		outchar('t');	/* tentative defined */
+	else {
+		lint_assert(def == DECL);
+		outchar('e');	/* declared */
 	}
+
 	if (llibflg && def != DECL) {
 		/*
-		 * mark it as used so we get no warnings from lint2 about
-		 * unused symbols in libraries.
+		 * mark it as used so lint2 does not complain about
+		 * unused symbols in libraries
 		 */
 		outchar('u');
 	}
@@ -327,8 +320,7 @@ outfdef(const sym_t *fsym, const pos_t *
 	outchar('d');
 
 	if (rval)
-		/* has return value */
-		outchar('r');
+		outchar('r');	/* has return value */
 
 	if (llibflg)
 		/*
@@ -338,8 +330,7 @@ outfdef(const sym_t *fsym, const pos_t *
 		outchar('u');
 
 	if (osdef)
-		/* old style function definition */
-		outchar('o');
+		outchar('o');	/* old style function definition */
 
 	if (fsym->s_inline)
 		outchar('i');



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

2021-08-02 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Aug  2 20:58:39 UTC 2021

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

Log Message:
lint: expand abbreviations in definitions of operator properties

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/oper.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/oper.c
diff -u src/usr.bin/xlint/lint1/oper.c:1.9 src/usr.bin/xlint/lint1/oper.c:1.10
--- src/usr.bin/xlint/lint1/oper.c:1.9	Sat Mar 20 20:56:58 2021
+++ src/usr.bin/xlint/lint1/oper.c	Mon Aug  2 20:58:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: oper.c,v 1.9 2021/03/20 20:56:58 rillig Exp $	*/
+/*	$NetBSD: oper.c,v 1.10 2021/08/02 20:58:39 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,17 +36,23 @@
 const mod_t modtab[NOPS] =
 #define begin_ops() {
 #define op(name, repr, \
-		bi, lo, tb, rb, \
-		in, ic, ar, sc, \
-		fo, va, ts, ba, \
-		se, lu, ru, pc, \
-		cm, ve, de, ew) \
+		is_binary, is_logical, takes_bool, requires_bool, \
+		is_integer, is_complex, is_arithmetic, is_scalar, \
+		can_fold, is_value, is_test, balances_operands, \
+		side_effects, left_unsigned, right_unsigned, \
+		precedence_confusion, is_comparison, \
+		valid_on_enum, bad_on_enum, warn_if_eq) \
 	{ \
-		bi + 0 > 0, lo + 0 > 0, tb + 0 > 0, rb + 0 > 0, \
-		in + 0 > 0, ic + 0 > 0, ar + 0 > 0, sc + 0 > 0, \
-		fo + 0 > 0, va + 0 > 0, ts + 0 > 0, ba + 0 > 0, \
-		se + 0 > 0, lu + 0 > 0, ru + 0 > 0, pc + 0 > 0, \
-		cm + 0 > 0, ve + 0 > 0, de + 0 > 0, ew + 0 > 0, \
+		is_binary	+ 0 > 0, is_logical		+ 0 > 0, \
+		takes_bool	+ 0 > 0, requires_bool		+ 0 > 0, \
+		is_integer	+ 0 > 0, is_complex		+ 0 > 0, \
+		is_arithmetic	+ 0 > 0, is_scalar		+ 0 > 0, \
+		can_fold	+ 0 > 0, is_value		+ 0 > 0, \
+		is_test		+ 0 > 0, balances_operands	+ 0 > 0, \
+		side_effects	+ 0 > 0, left_unsigned		+ 0 > 0, \
+		right_unsigned	+ 0 > 0, precedence_confusion	+ 0 > 0, \
+		is_comparison	+ 0 > 0, valid_on_enum		+ 0 > 0, \
+		bad_on_enum	+ 0 > 0, warn_if_eq		+ 0 > 0, \
 		repr, \
 	},
 #define end_ops(n) };



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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 19:18:10 UTC 2021

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

Log Message:
lint: clean up debug logging in the C grammar


To generate a diff of this commit:
cvs rdiff -u -r1.353 -r1.354 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.353 src/usr.bin/xlint/lint1/cgram.y:1.354
--- src/usr.bin/xlint/lint1/cgram.y:1.353	Sun Aug  1 06:40:37 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Aug  1 19:18:10 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.353 2021/08/01 06:40:37 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.354 2021/08/01 19:18:10 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.353 2021/08/01 06:40:37 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.354 2021/08/01 19:18:10 rillig Exp $");
 #endif
 
 #include 
@@ -75,7 +75,7 @@ static	sym_t	*symbolrename(sym_t *, sbuf
 static void
 CLEAR_WARN_FLAGS(const char *file, size_t line)
 {
-	printf("%s:%zu: clearing flags\n", file, line);
+	debug_step("%s:%zu: clearing flags", file, line);
 	clear_warn_flags();
 	olwarn = LWARN_BAD;
 }
@@ -84,7 +84,7 @@ static void
 SAVE_WARN_FLAGS(const char *file, size_t line)
 {
 	lint_assert(olwarn == LWARN_BAD);
-	printf("%s:%zu: saving flags %d\n", file, line, lwarn);
+	debug_step("%s:%zu: saving flags %d", file, line, lwarn);
 	olwarn = lwarn;
 }
 
@@ -93,18 +93,16 @@ RESTORE_WARN_FLAGS(const char *file, siz
 {
 	if (olwarn != LWARN_BAD) {
 		lwarn = olwarn;
-		printf("%s:%zu: restoring flags %d\n", file, line, lwarn);
+		debug_step("%s:%zu: restoring flags %d", file, line, lwarn);
 		olwarn = LWARN_BAD;
 	} else
 		CLEAR_WARN_FLAGS(file, line);
 }
-#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args)
 #else
 #define CLEAR_WARN_FLAGS(f, l)	clear_warn_flags(), olwarn = LWARN_BAD
 #define SAVE_WARN_FLAGS(f, l)	olwarn = lwarn
 #define RESTORE_WARN_FLAGS(f, l) \
 	(void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn))
-#define cgram_debug(fmt, args...) do { } while (false)
 #endif
 
 #define clear_warning_flags()	CLEAR_WARN_FLAGS(__FILE__, __LINE__)
@@ -383,11 +381,11 @@ identifier_sym:			/* helper for struct/u
 /* K ???, C90 ???, C99 6.4.2.1, C11 ??? */
 identifier:
 	  T_NAME {
-		cgram_debug("name '%s'", $1->sb_name);
+		debug_printf("cgram: name '%s'", $1->sb_name);
 		$$ = $1;
 	  }
 	| T_TYPENAME {
-		cgram_debug("typename '%s'", $1->sb_name);
+		debug_printf("cgram: typename '%s'", $1->sb_name);
 		$$ = $1;
 	  }
 	;



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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 19:11:54 UTC 2021

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

Log Message:
lint: merge duplicate debugging code

The functions 'debug_node' and 'display_expression' were similar enough
to be merged.

Migrate debug_node to use the existing debug logging functions.

Remove the now unused option 'd' from the options string.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.127 -r1.128 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/xlint/lint1/main1.c
cvs rdiff -u -r1.325 -r1.326 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/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.1 src/usr.bin/xlint/lint1/debug.c:1.2
--- src/usr.bin/xlint/lint1/debug.c:1.1	Sat Jul 31 18:16:42 2021
+++ src/usr.bin/xlint/lint1/debug.c	Sun Aug  1 19:11:54 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.1 2021/07/31 18:16:42 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.2 2021/08/01 19:11:54 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,9 +35,11 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: debug.c,v 1.1 2021/07/31 18:16:42 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.2 2021/08/01 19:11:54 rillig Exp $");
 #endif
 
+#include 
+
 #include "lint1.h"
 
 
@@ -104,40 +106,54 @@ void
 }
 
 void
-debug_node(const tnode_t *tn, int indent)
+debug_node(const tnode_t *tn)
 {
 	op_t op;
 
 	if (tn == NULL) {
-		printf("%*s" "null\n", indent, "");
+		debug_step("null");
 		return;
 	}
 
 	op = tn->tn_op;
-	printf("%*s%s with type '%s'%s%s",
-	2 * indent, "",
+	debug_indent();
+	debug_printf("'%s' with type '%s'%s%s",
 	op == CVT && !tn->tn_cast ? "convert" : modtab[op].m_name,
 	type_name(tn->tn_type), tn->tn_lvalue ? ", lvalue" : "",
 	tn->tn_parenthesized ? ", parenthesized" : "");
 
 	if (op == NAME)
-		printf(" %s\n", tn->tn_sym->s_name);
+		debug_printf(" %s %s\n", tn->tn_sym->s_name,
+		storage_class_name(tn->tn_sym->s_scl));
 	else if (op == CON && is_floating(tn->tn_type->t_tspec))
-		printf(", value %Lg", tn->tn_val->v_ldbl);
+		debug_printf(", value %Lg", tn->tn_val->v_ldbl);
 	else if (op == CON && is_uinteger(tn->tn_type->t_tspec))
-		printf(", value %llu\n", (unsigned long long)tn->tn_val->v_quad);
+		debug_printf(", value %llu\n", (unsigned long long)tn->tn_val->v_quad);
 	else if (op == CON && is_integer(tn->tn_type->t_tspec))
-		printf(", value %lld\n", (long long)tn->tn_val->v_quad);
+		debug_printf(", value %lld\n", (long long)tn->tn_val->v_quad);
 	else if (op == CON)
-		printf(", unknown value\n");
-	else if (op == STRING)
-		printf(", length %zu\n", tn->tn_string->st_len);
-	else {
-		printf("\n");
+		debug_printf(", unknown value\n");
+	else if (op == STRING && tn->tn_string->st_tspec == CHAR)
+		debug_printf(", length %zu, \"%s\"\n",
+		tn->tn_string->st_len, tn->tn_string->st_cp);
+	else if (op == STRING && tn->tn_string->st_tspec == WCHAR) {
+		char *s;
+		size_t n;
+		n = MB_CUR_MAX * (tn->tn_string->st_len + 1);
+		s = xmalloc(n);
+		(void)wcstombs(s, tn->tn_string->st_wcp, n);
+		debug_printf(", length %zu, L\"%s\"",
+		tn->tn_string->st_len, s);
+		free(s);
+
+	} else {
+		debug_printf("\n");
 
-		debug_node(tn->tn_left, indent + 1);
+		debug_indent_inc();
+		debug_node(tn->tn_left);
 		if (modtab[op].m_binary || tn->tn_right != NULL)
-			debug_node(tn->tn_right, indent + 1);
+			debug_node(tn->tn_right);
+		debug_indent_dec();
 	}
 }
 

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.127 src/usr.bin/xlint/lint1/externs1.h:1.128
--- src/usr.bin/xlint/lint1/externs1.h:1.127	Sun Aug  1 18:37:29 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sun Aug  1 19:11:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.127 2021/08/01 18:37:29 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.128 2021/08/01 19:11:54 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -115,7 +115,7 @@ extern	void	expr_restore_memory(struct m
  */
 
 #ifdef DEBUG
-void	debug_node(const tnode_t *, int);
+void	debug_node(const tnode_t *);
 void	debug_printf(const char *fmt, ...) __printflike(1, 2);
 void	debug_indent(void);
 void	debug_indent_inc(void);
@@ -127,7 +127,7 @@ void	debug_leave(const char *);
 #define	debug_leave()		(debug_leave)(__func__)
 #else
 #define	debug_noop()		do { } while (false)
-#define	debug_node(tn, indent)	debug_noop()
+#define	debug_node(tn)		debug_noop()
 #define	debug_printf(...)	debug_noop()
 #define	debug_indent()		debug_noop()
 #define	debug_step(...)		debug_noop()

Index: src/usr.bin/xlint/lint1/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.52 src/usr.bin/xlint/lint1/main1.c:1.53
--- src/usr.bin/xlint/lint1/main1.c:1.52	Sun Aug  1 18:37:29 2021
+++ 

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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 18:37:29 UTC 2021

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

Log Message:
lint: remove option -d, clean up debug logging

The command line option -d was not used by /usr/bin/lint, and it only
triggered a handful of debug messages.  Move this debug logging over to
the compile-time -DDEBUG setting.

Move display_expression further up to avoid the forward declaration.


To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/xlint/lint1/main1.c
cvs rdiff -u -r1.324 -r1.325 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.216 src/usr.bin/xlint/lint1/decl.c:1.217
--- src/usr.bin/xlint/lint1/decl.c:1.216	Sun Aug  1 06:40:37 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun Aug  1 18:37:29 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.216 2021/08/01 06:40:37 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.217 2021/08/01 18:37:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.216 2021/08/01 06:40:37 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.217 2021/08/01 18:37:29 rillig Exp $");
 #endif
 
 #include 
@@ -649,8 +649,7 @@ begin_declaration_level(scl_t sc)
 	dcs = di;
 	di->d_ctx = sc;
 	di->d_ldlsym = >d_dlsyms;
-	if (dflag)
-		(void)printf("%s(%p %s)\n", __func__, dcs, scl_name(sc));
+	debug_step("%s(%p %s)", __func__, dcs, scl_name(sc));
 }
 
 /*
@@ -661,9 +660,7 @@ end_declaration_level(void)
 {
 	dinfo_t	*di;
 
-	if (dflag)
-		(void)printf("%s(%p %s)\n",
-		__func__, dcs, scl_name(dcs->d_ctx));
+	debug_step("%s(%p %s)", __func__, dcs, scl_name(dcs->d_ctx));
 
 	lint_assert(dcs->d_next != NULL);
 	di = dcs;

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.126 src/usr.bin/xlint/lint1/externs1.h:1.127
--- src/usr.bin/xlint/lint1/externs1.h:1.126	Sat Jul 31 19:12:35 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sun Aug  1 18:37:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.126 2021/07/31 19:12:35 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.127 2021/08/01 18:37:29 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,6 @@ extern	int	aflag;
 extern	bool	bflag;
 extern	bool	cflag;
 extern	bool	c11flag;
-extern	bool	dflag;
 extern	bool	eflag;
 extern	bool	Fflag;
 extern	bool	gflag;

Index: src/usr.bin/xlint/lint1/main1.c
diff -u src/usr.bin/xlint/lint1/main1.c:1.51 src/usr.bin/xlint/lint1/main1.c:1.52
--- src/usr.bin/xlint/lint1/main1.c:1.51	Sun Aug  1 06:40:37 2021
+++ src/usr.bin/xlint/lint1/main1.c	Sun Aug  1 18:37:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main1.c,v 1.51 2021/08/01 06:40:37 rillig Exp $	*/
+/*	$NetBSD: main1.c,v 1.52 2021/08/01 18:37:29 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.51 2021/08/01 06:40:37 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.52 2021/08/01 18:37:29 rillig Exp $");
 #endif
 
 #include 
@@ -71,9 +71,6 @@ bool	cflag;
 /* Allow features from C11, C99 and C90. */
 bool	c11flag;
 
-/* Print various debug information. */
-bool	dflag;
-
 /* Perform stricter checking of enum types and operations on enum types. */
 bool	eflag;
 
@@ -186,7 +183,6 @@ main(int argc, char *argv[])
 		case 'a':	aflag++;	break;
 		case 'b':	bflag = true;	break;
 		case 'c':	cflag = true;	break;
-		case 'd':	dflag = true;	break;
 		case 'e':	eflag = true;	break;
 		case 'F':	Fflag = true;	break;
 		case 'g':	gflag = true;	break;
@@ -257,8 +253,6 @@ main(int argc, char *argv[])
 #ifdef DEBUG
 	setvbuf(stdout, NULL, _IONBF, 0);
 #endif
-	if (dflag)
-		setvbuf(stdout, NULL, _IONBF, 0);
 #ifdef YYDEBUG
 	if (yflag)
 		yydebug = 1;

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.324 src/usr.bin/xlint/lint1/tree.c:1.325
--- src/usr.bin/xlint/lint1/tree.c:1.324	Sun Aug  1 14:45:39 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Aug  1 18:37:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.324 2021/08/01 14:45:39 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.325 2021/08/01 18:37:29 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.324 2021/08/01 14:45:39 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.325 2021/08/01 18:37:29 rillig Exp $");
 #endif
 
 #include 
@@ -90,7 +90,6 @@ static	tnode_t	*fold_float(tnode_t *);
 static	tnode_t	*check_function_arguments(type_t *, tnode_t *);
 static	tnode_t	*check_prototype_argument(int, type_t *, 

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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 14:45:40 UTC 2021

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

Log Message:
lint: remove unreachable code from usual arithmetic conversions


To generate a diff of this commit:
cvs rdiff -u -r1.323 -r1.324 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.323 src/usr.bin/xlint/lint1/tree.c:1.324
--- src/usr.bin/xlint/lint1/tree.c:1.323	Sun Aug  1 13:49:17 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Aug  1 14:45:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.323 2021/08/01 13:49:17 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.324 2021/08/01 14:45:39 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.323 2021/08/01 13:49:17 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.324 2021/08/01 14:45:39 rillig Exp $");
 #endif
 
 #include 
@@ -1782,8 +1782,6 @@ balance(op_t op, tnode_t **lnp, tnode_t 
 			t = LCOMPLEX;
 		} else if (lt == DCOMPLEX || rt == DCOMPLEX) {
 			t = DCOMPLEX;
-		} else if (lt == COMPLEX || rt == COMPLEX) {
-			t = COMPLEX;
 		} else if (lt == FCOMPLEX || rt == FCOMPLEX) {
 			t = FCOMPLEX;
 		} else if (lt == LDOUBLE || rt == LDOUBLE) {



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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 08:03:43 UTC 2021

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

Log Message:
lint: remove hash value from symbol buffer

Conceptually, a symbol buffer does not need to remember its hash value
since that belongs to the symbol table.  This makes the code for the
symbol table simpler.  The number of hash calculations increases by
about 5%, which is negligible.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.120 -r1.121 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/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.61 src/usr.bin/xlint/lint1/lex.c:1.62
--- src/usr.bin/xlint/lint1/lex.c:1.61	Sun Aug  1 07:46:51 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Aug  1 08:03:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.61 2021/08/01 07:46:51 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.62 2021/08/01 08:03:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.61 2021/08/01 07:46:51 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.62 2021/08/01 08:03:43 rillig Exp $");
 #endif
 
 #include 
@@ -259,9 +259,11 @@ symt_t	symtyp;
 
 
 static void
-symtab_add_hash(sym_t *sym, size_t h)
+symtab_add(sym_t *sym)
 {
+	size_t h;
 
+	h = hash(sym->s_name);
 	if ((sym->s_link = symtab[h]) != NULL)
 		symtab[h]->s_rlink = >s_link;
 	sym->s_rlink = [h];
@@ -269,15 +271,6 @@ symtab_add_hash(sym_t *sym, size_t h)
 }
 
 static void
-symtab_add(sym_t *sym)
-{
-	size_t h;
-
-	h = hash(sym->s_name);
-	symtab_add_hash(sym, h);
-}
-
-static void
 symtab_remove(sym_t *sym)
 {
 
@@ -445,7 +438,6 @@ lex_name(const char *yytext, size_t yyle
 	sb = allocsb();
 	sb->sb_name = yytext;
 	sb->sb_len = yyleng;
-	sb->sb_hash = hash(yytext);
 	if ((sym = search(sb)) != NULL && sym->s_keyword != NULL) {
 		freesb(sb);
 		return keyw(sym);
@@ -473,10 +465,12 @@ lex_name(const char *yytext, size_t yyle
 static sym_t *
 search(sbuf_t *sb)
 {
+	int h;
 	sym_t *sym;
 	const struct kwtab *kw;
 
-	for (sym = symtab[sb->sb_hash]; sym != NULL; sym = sym->s_link) {
+	h = hash(sb->sb_name);
+	for (sym = symtab[h]; sym != NULL; sym = sym->s_link) {
 		if (strcmp(sym->s_name, sb->sb_name) != 0)
 			continue;
 		kw = sym->s_keyword;
@@ -1471,7 +1465,7 @@ getsym(sbuf_t *sb)
 
 	symtyp = FVFT;
 
-	symtab_add_hash(sym, sb->sb_hash);
+	symtab_add(sym);
 
 	*di->d_ldlsym = sym;
 	di->d_ldlsym = >s_dlnxt;

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.120 src/usr.bin/xlint/lint1/lint1.h:1.121
--- src/usr.bin/xlint/lint1/lint1.h:1.120	Sat Jul 31 19:52:44 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Sun Aug  1 08:03:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.120 2021/07/31 19:52:44 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.121 2021/08/01 08:03:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -293,7 +293,6 @@ typedef	struct sym {
 typedef	struct sbuf {
 	const	char *sb_name;		/* name of symbol */
 	size_t	sb_len;			/* length (without '\0') */
-	int	sb_hash;		/* hash value */
 	sym_t	*sb_sym;		/* symbol table entry */
 	struct	sbuf *sb_next;		/* for freelist */
 } sbuf_t;



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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 07:46:51 UTC 2021

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

Log Message:
lint: merge duplicate code for removing a symbol from the table

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 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.60 src/usr.bin/xlint/lint1/lex.c:1.61
--- src/usr.bin/xlint/lint1/lex.c:1.60	Sun Aug  1 06:58:58 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Aug  1 07:46:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.60 2021/08/01 06:58:58 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.61 2021/08/01 07:46:51 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.60 2021/08/01 06:58:58 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.61 2021/08/01 07:46:51 rillig Exp $");
 #endif
 
 #include 
@@ -278,6 +278,16 @@ symtab_add(sym_t *sym)
 }
 
 static void
+symtab_remove(sym_t *sym)
+{
+
+	if ((*sym->s_rlink = sym->s_link) != NULL)
+		sym->s_link->s_rlink = sym->s_rlink;
+	sym->s_link = NULL;
+}
+
+
+static void
 add_keyword(const struct kwtab *kw, u_int deco)
 {
 	sym_t *sym;
@@ -1504,21 +1514,17 @@ mktempsym(type_t *t)
 	return sym;
 }
 
-/*
- * Remove a symbol forever from the symbol table. s_block_level
- * is set to -1 to avoid that the symbol will later be put
- * back to the symbol table.
- */
+/* Remove a symbol forever from the symbol table. */
 void
 rmsym(sym_t *sym)
 {
 
 	debug_step("rmsym '%s' %d '%s'",
 	sym->s_name, (int)sym->s_kind, type_name(sym->s_type));
-	if ((*sym->s_rlink = sym->s_link) != NULL)
-		sym->s_link->s_rlink = sym->s_rlink;
+	symtab_remove(sym);
+
+	/* avoid that the symbol will later be put back to the symbol table */
 	sym->s_block_level = -1;
-	sym->s_link = NULL;
 }
 
 /*
@@ -1535,9 +1541,7 @@ rmsyms(sym_t *syms)
 			debug_step("rmsyms '%s' %d '%s'",
 			sym->s_name, (int)sym->s_kind,
 			type_name(sym->s_type));
-			if ((*sym->s_rlink = sym->s_link) != NULL)
-sym->s_link->s_rlink = sym->s_rlink;
-			sym->s_link = NULL;
+			symtab_remove(sym);
 			sym->s_rlink = NULL;
 		}
 	}
@@ -1574,10 +1578,8 @@ cleanup(void)
 	for (i = 0; i < HSHSIZ1; i++) {
 		for (sym = symtab[i]; sym != NULL; sym = nsym) {
 			nsym = sym->s_link;
-			if (sym->s_block_level >= 1) {
-if ((*sym->s_rlink = nsym) != NULL)
-	nsym->s_rlink = sym->s_rlink;
-			}
+			if (sym->s_block_level >= 1)
+symtab_remove(sym);
 		}
 	}
 



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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 06:58:58 UTC 2021

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

Log Message:
lint: extract duplicate code for modifying the symbol table

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/usr.bin/xlint/lint1/lex.c:1.60
--- src/usr.bin/xlint/lint1/lex.c:1.59	Sun Aug  1 06:40:37 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Aug  1 06:58:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.59 2021/08/01 06:40:37 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.60 2021/08/01 06:58:58 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.59 2021/08/01 06:40:37 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.60 2021/08/01 06:58:58 rillig Exp $");
 #endif
 
 #include 
@@ -259,10 +259,28 @@ symt_t	symtyp;
 
 
 static void
+symtab_add_hash(sym_t *sym, size_t h)
+{
+
+	if ((sym->s_link = symtab[h]) != NULL)
+		symtab[h]->s_rlink = >s_link;
+	sym->s_rlink = [h];
+	symtab[h] = sym;
+}
+
+static void
+symtab_add(sym_t *sym)
+{
+	size_t h;
+
+	h = hash(sym->s_name);
+	symtab_add_hash(sym, h);
+}
+
+static void
 add_keyword(const struct kwtab *kw, u_int deco)
 {
 	sym_t *sym;
-	size_t h;
 	char buf[256];
 	const char *name;
 
@@ -298,11 +316,8 @@ add_keyword(const struct kwtab *kw, u_in
 	} else if (kw->kw_token == T_QUAL) {
 		sym->s_tqual = kw->kw_tqual;
 	}
-	h = hash(sym->s_name);
-	if ((sym->s_link = symtab[h]) != NULL)
-		symtab[h]->s_rlink = >s_link;
-	sym->s_rlink = [h];
-	symtab[h] = sym;
+
+	symtab_add(sym);
 }
 
 /*
@@ -1380,15 +1395,15 @@ lex_wide_string(void)
 }
 
 /*
- * As noted above the scanner does not create new symbol table entries
+ * As noted above, the scanner does not create new symbol table entries
  * for symbols it cannot find in the symbol table. This is to avoid
  * putting undeclared symbols into the symbol table if a syntax error
  * occurs.
  *
- * getsym() is called as soon as it is probably ok to put the symbol to the
+ * getsym() is called as soon as it is probably ok to put the symbol in the
  * symbol table. It is still possible that symbols are put in the symbol
  * table that are not completely declared due to syntax errors. To avoid too
- * many problems in this case, symbols get type int in getsym().
+ * many problems in this case, symbols get type 'int' in getsym().
  *
  * XXX calls to getsym() should be delayed until decl1*() is called.
  */
@@ -1446,10 +1461,7 @@ getsym(sbuf_t *sb)
 
 	symtyp = FVFT;
 
-	if ((sym->s_link = symtab[sb->sb_hash]) != NULL)
-		symtab[sb->sb_hash]->s_rlink = >s_link;
-	sym->s_rlink = [sb->sb_hash];
-	symtab[sb->sb_hash] = sym;
+	symtab_add_hash(sym, sb->sb_hash);
 
 	*di->d_ldlsym = sym;
 	di->d_ldlsym = >s_dlnxt;
@@ -1466,13 +1478,11 @@ sym_t *
 mktempsym(type_t *t)
 {
 	static int n = 0;
-	int h;
 	char *s = getlblk(block_level, 64);
 	sym_t *sym = getblk(sizeof(*sym));
 	scl_t scl;
 
 	(void)snprintf(s, 64, "%.8d_tmp", n++);
-	h = hash(s);
 
 	scl = dcs->d_scl;
 	if (scl == NOSCL)
@@ -1486,10 +1496,7 @@ mktempsym(type_t *t)
 	sym->s_used = true;
 	sym->s_set = true;
 
-	if ((sym->s_link = symtab[h]) != NULL)
-		symtab[h]->s_rlink = >s_link;
-	sym->s_rlink = [h];
-	symtab[h] = sym;
+	symtab_add(sym);
 
 	*dcs->d_ldlsym = sym;
 	dcs->d_ldlsym = >s_dlnxt;
@@ -1542,15 +1549,10 @@ rmsyms(sym_t *syms)
 void
 inssym(int bl, sym_t *sym)
 {
-	int	h;
 
 	debug_step("inssym '%s' %d '%s'",
 	sym->s_name, sym->s_kind, type_name(sym->s_type));
-	h = hash(sym->s_name);
-	if ((sym->s_link = symtab[h]) != NULL)
-		symtab[h]->s_rlink = >s_link;
-	sym->s_rlink = [h];
-	symtab[h] = sym;
+	symtab_add(sym);
 	sym->s_block_level = bl;
 	lint_assert(sym->s_link == NULL ||
 		sym->s_block_level >= sym->s_link->s_block_level);
@@ -1589,12 +1591,10 @@ cleanup(void)
 sym_t *
 pushdown(const sym_t *sym)
 {
-	int	h;
 	sym_t	*nsym;
 
 	debug_step("pushdown '%s' %d '%s'",
 	sym->s_name, (int)sym->s_kind, type_name(sym->s_type));
-	h = hash(sym->s_name);
 	nsym = getblk(sizeof(*nsym));
 	lint_assert(sym->s_block_level <= block_level);
 	nsym->s_name = sym->s_name;
@@ -1602,10 +1602,7 @@ pushdown(const sym_t *sym)
 	nsym->s_kind = sym->s_kind;
 	nsym->s_block_level = block_level;
 
-	if ((nsym->s_link = symtab[h]) != NULL)
-		symtab[h]->s_rlink = >s_link;
-	nsym->s_rlink = [h];
-	symtab[h] = nsym;
+	symtab_add(nsym);
 
 	*dcs->d_ldlsym = nsym;
 	dcs->d_ldlsym = >s_dlnxt;



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

2021-08-01 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Aug  1 06:40:37 UTC 2021

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

Log Message:
lint: add debug logging for symbol table, clean up debug logging

When I tried to fix msg_115, I quickly ran into a segmentation fault,
probably related to the symbol table.  To better understand this part,
log insertions and deletions.

The other debug log messages do not need to mention the current file
position anymore, this is what lex_next_line takes care of since scan.l
1.113 from 2021-01-05.


To generate a diff of this commit:
cvs rdiff -u -r1.352 -r1.353 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.117 -r1.118 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.50 -r1.51 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/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.352 src/usr.bin/xlint/lint1/cgram.y:1.353
--- src/usr.bin/xlint/lint1/cgram.y:1.352	Sat Jul 31 17:09:21 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Aug  1 06:40:37 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.352 2021/07/31 17:09:21 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.353 2021/08/01 06:40:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.352 2021/07/31 17:09:21 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.353 2021/08/01 06:40:37 rillig Exp $");
 #endif
 
 #include 
@@ -75,8 +75,7 @@ static	sym_t	*symbolrename(sym_t *, sbuf
 static void
 CLEAR_WARN_FLAGS(const char *file, size_t line)
 {
-	printf("%s:%d: %s:%zu: clearing flags\n",
-	curr_pos.p_file, curr_pos.p_line, file, line);
+	printf("%s:%zu: clearing flags\n", file, line);
 	clear_warn_flags();
 	olwarn = LWARN_BAD;
 }
@@ -85,8 +84,7 @@ static void
 SAVE_WARN_FLAGS(const char *file, size_t line)
 {
 	lint_assert(olwarn == LWARN_BAD);
-	printf("%s:%d: %s:%zu: saving flags %d\n",
-	curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
+	printf("%s:%zu: saving flags %d\n", file, line, lwarn);
 	olwarn = lwarn;
 }
 
@@ -95,8 +93,7 @@ RESTORE_WARN_FLAGS(const char *file, siz
 {
 	if (olwarn != LWARN_BAD) {
 		lwarn = olwarn;
-		printf("%s:%d: %s:%zu: restoring flags %d\n",
-		curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
+		printf("%s:%zu: restoring flags %d\n", file, line, lwarn);
 		olwarn = LWARN_BAD;
 	} else
 		CLEAR_WARN_FLAGS(file, line);

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.215 src/usr.bin/xlint/lint1/decl.c:1.216
--- src/usr.bin/xlint/lint1/decl.c:1.215	Sat Jul 31 19:52:44 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun Aug  1 06:40:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.215 2021/07/31 19:52:44 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.216 2021/08/01 06:40:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.215 2021/07/31 19:52:44 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.216 2021/08/01 06:40:37 rillig Exp $");
 #endif
 
 #include 
@@ -3015,13 +3015,11 @@ check_usage(dinfo_t *di)
 	mklwarn = lwarn;
 	lwarn = LWARN_ALL;
 
-	debug_step("%s, %d: >temp lwarn = %d",
-	curr_pos.p_file, curr_pos.p_line, lwarn);
+	debug_step("begin lwarn %d", lwarn);
 	for (sym = di->d_dlsyms; sym != NULL; sym = sym->s_dlnxt)
 		check_usage_sym(di->d_asm, sym);
 	lwarn = mklwarn;
-	debug_step("%s, %d: 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.117 2021/07/31 19:07:52 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.118 2021/08/01 06:40:37 rillig Exp $");
 #endif
 
 #include 
@@ -192,8 +192,7 @@ end_control_statement(control_statement_
 static void
 set_reached(bool new_reached)
 {
-	debug_step("%s:%d: %s -> %s",
-	curr_pos.p_file, curr_pos.p_line,
+	debug_step("%s -> %s",
 	reached ? "reachable" : "unreachable",
 	new_reached ? "reachable" : "unreachable");
 	reached = new_reached;
@@ -1327,8 +1326,7 @@ void
 linted(int n)
 {
 
-	debug_step("%s, %d: lwarn = %d",
-	curr_pos.p_file, curr_pos.p_line, n);
+	debug_step("set lwarn %d", n);
 	lwarn = n;
 }
 

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.58 src/usr.bin/xlint/lint1/lex.c:1.59
--- src/usr.bin/xlint/lint1/lex.c:1.58	Sat Jul 31 19:07:52 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Aug  1 06:40:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.58 2021/07/31 19:07:52 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.59 2021/08/01 06:40:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if 

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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 19:20:59 UTC 2021

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

Log Message:
lint: initialize shared types in the same order as in tspec_t

This makes it easier to see whether there are any types missing, such as
__uint128_t.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 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.213 src/usr.bin/xlint/lint1/decl.c:1.214
--- src/usr.bin/xlint/lint1/decl.c:1.213	Sat Jul 31 19:07:52 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sat Jul 31 19:20:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.213 2021/07/31 19:07:52 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.214 2021/07/31 19:20:59 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.213 2021/07/31 19:07:52 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.214 2021/07/31 19:20:59 rillig Exp $");
 #endif
 
 #include 
@@ -105,6 +105,14 @@ initdecl(void)
 	typetab = xcalloc(NTSPEC, sizeof(*typetab));
 	for (i = 0; i < NTSPEC; i++)
 		typetab[i].t_tspec = NOTSPEC;
+
+	/*
+	 * The following two are not real types. They are only used by the
+	 * parser to handle the keywords "signed" and "unsigned".
+	 */
+	typetab[SIGNED].t_tspec = SIGNED;
+	typetab[UNSIGN].t_tspec = UNSIGN;
+
 	typetab[BOOL].t_tspec = BOOL;
 	typetab[CHAR].t_tspec = CHAR;
 	typetab[SCHAR].t_tspec = SCHAR;
@@ -117,20 +125,19 @@ initdecl(void)
 	typetab[ULONG].t_tspec = ULONG;
 	typetab[QUAD].t_tspec = QUAD;
 	typetab[UQUAD].t_tspec = UQUAD;
+#ifdef INT128_SIZE
+	/* TODO: add __int128_t */
+	/* TODO: add __uint128_t */
+#endif
 	typetab[FLOAT].t_tspec = FLOAT;
 	typetab[DOUBLE].t_tspec = DOUBLE;
 	typetab[LDOUBLE].t_tspec = LDOUBLE;
+	typetab[VOID].t_tspec = VOID;
+	/* struct, union, enum, ptr, array and func are not shared. */
+	typetab[COMPLEX].t_tspec = COMPLEX;
 	typetab[FCOMPLEX].t_tspec = FCOMPLEX;
 	typetab[DCOMPLEX].t_tspec = DCOMPLEX;
 	typetab[LCOMPLEX].t_tspec = LCOMPLEX;
-	typetab[COMPLEX].t_tspec = COMPLEX;
-	typetab[VOID].t_tspec = VOID;
-	/*
-	 * Next two are not real types. They are only used by the parser
-	 * to return keywords "signed" and "unsigned"
-	 */
-	typetab[SIGNED].t_tspec = SIGNED;
-	typetab[UNSIGN].t_tspec = UNSIGN;
 }
 
 /* Return the name of the "storage class" in the wider sense. */



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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 19:12:35 UTC 2021

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

Log Message:
lint: do not evaluate arguments of debug_step

To analyze the unexpected test failure of op_shl_lp64, I had reverted
debug_step to evaluate its arguments.  I then accidentally committed
that without running the tests again.

Anyway, the previous commit can now be used as a demonstration that
initdecl is indeed missing the initialization for __uint128_t, which
leads to the internal error in op_shl_lp64.


To generate a diff of this commit:
cvs rdiff -u -r1.125 -r1.126 src/usr.bin/xlint/lint1/externs1.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/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.125 src/usr.bin/xlint/lint1/externs1.h:1.126
--- src/usr.bin/xlint/lint1/externs1.h:1.125	Sat Jul 31 19:07:52 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Jul 31 19:12:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.125 2021/07/31 19:07:52 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.126 2021/07/31 19:12:35 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -131,8 +131,7 @@ void	debug_leave(const char *);
 #define	debug_node(tn, indent)	debug_noop()
 #define	debug_printf(...)	debug_noop()
 #define	debug_indent()		debug_noop()
-static inline void __printflike(1, 2) debug_step(const char *fmt, ...) {}
-/*#define	debug_step(...)		debug_noop()*/
+#define	debug_step(...)		debug_noop()
 #define	debug_indent()		debug_noop()
 #define	debug_indent_inc()	debug_noop()
 #define	debug_indent_dec()	debug_noop()



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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 19:07:52 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: decl.c err.c externs1.h func.c init.c lex.c
main1.c

Log Message:
lint: clean up debug logging

The calls to debug_step, unlike printf, don't need a trailing newline.

Remove the debug_step0 macro and its relatives since lint already uses
enough other features from C99 that it essentially requires this
standard, which supports varargs macro arguments.  Among these features
are __func__ and printf("%zu").

In non-debug mode, do not evaluate the arguments of debug_step.
Evaluating the arguments had caused an internal error when running the
test op_shl_lp64.  This is indeed a bug since initdecl should have
initialized the type table for __uint128_t.  This had been forgotten
when support for __uint128_t was added in decl.c 1.69 from 2018-09-07.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.131 -r1.132 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.205 -r1.206 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.49 -r1.50 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/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.212 src/usr.bin/xlint/lint1/decl.c:1.213
--- src/usr.bin/xlint/lint1/decl.c:1.212	Sat Jul 31 17:09:21 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sat Jul 31 19:07:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.212 2021/07/31 17:09:21 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.213 2021/07/31 19:07:52 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.212 2021/07/31 17:09:21 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.213 2021/07/31 19:07:52 rillig Exp $");
 #endif
 
 #include 
@@ -289,9 +289,8 @@ void
 add_type(type_t *tp)
 {
 	tspec_t	t;
-#ifdef DEBUG
-	printf("%s: %s\n", __func__, type_name(tp));
-#endif
+
+	debug_step("%s: %s", __func__, type_name(tp));
 	if (tp->t_typedef) {
 		/*
 		 * something like "typedef int a; int a b;"
@@ -801,9 +800,7 @@ dcs_merge_declaration_specifiers(void)
 	l = dcs->d_rank_mod;	/* SHORT, LONG or QUAD */
 	tp = dcs->d_type;
 
-#ifdef DEBUG
-	printf("%s: %s\n", __func__, type_name(tp));
-#endif
+	debug_step("%s: %s", __func__, type_name(tp));
 	if (t == NOTSPEC && s == NOTSPEC && l == NOTSPEC && c == NOTSPEC &&
 	tp == NULL)
 		dcs->d_notyp = true;
@@ -3011,17 +3008,13 @@ check_usage(dinfo_t *di)
 	mklwarn = lwarn;
 	lwarn = LWARN_ALL;
 
-#ifdef DEBUG
-	printf("%s, %d: >temp lwarn = %d\n", curr_pos.p_file, curr_pos.p_line,
-	lwarn);
-#endif
+	debug_step("%s, %d: >temp lwarn = %d",
+	curr_pos.p_file, curr_pos.p_line, lwarn);
 	for (sym = di->d_dlsyms; sym != NULL; sym = sym->s_dlnxt)
 		check_usage_sym(di->d_asm, sym);
 	lwarn = mklwarn;
-#ifdef DEBUG
-	printf("%s, %d: 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.131 2021/07/25 10:39:10 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.132 2021/07/31 19:07:52 rillig Exp $");
 #endif
 
 #include 
@@ -511,9 +511,7 @@ vwarning_at(int msgid, const pos_t *pos,
 	if (ERR_ISSET(msgid, ))
 		return;
 
-#ifdef DEBUG
-	printf("%s: lwarn=%d msgid=%d\n", __func__, lwarn, msgid);
-#endif
+	debug_step("%s: lwarn=%d msgid=%d", __func__, lwarn, msgid);
 	if (lwarn == LWARN_NONE || lwarn == msgid)
 		/* this warning is suppressed by a LINTED comment */
 		return;

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.124 src/usr.bin/xlint/lint1/externs1.h:1.125
--- src/usr.bin/xlint/lint1/externs1.h:1.124	Sat Jul 31 18:16:42 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Jul 31 19:07:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.124 2021/07/31 18:16:42 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.125 2021/07/31 19:07:52 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -123,27 +123,20 @@ void	debug_indent_inc(void);
 void	debug_indent_dec(void);
 void	debug_enter(const char *);
 void	debug_step(const char *fmt, ...) __printflike(1, 2);
-#define	debug_step0		debug_step
-#define	debug_step1		debug_step
-#define	debug_step2		debug_step
 void	debug_leave(const char *);
 #define	debug_enter()		(debug_enter)(__func__)
 #define	debug_leave()		(debug_leave)(__func__)
 #else
 #define	debug_noop()		do { } while (false)
-#define	debug_node(tn, indent) debug_noop()
-/* ARGSUSED */
-static inline void __printflike(1, 2) debug_printf(const char *fmt, ...) {}
-#define debug_indent()		debug_noop()
-/* ARGSUSED */
+#define	debug_node(tn, indent)	debug_noop()
+#define	

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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 18:16:42 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: Makefile externs1.h init.c tree.c
Added Files:
src/usr.bin/xlint/lint1: debug.c

Log Message:
lint: extract debug logging to separate file

Lint currently has several different kinds of debug log:

* The -DDEBUG log is controlled at compile time.
* The -d command line options enables some other debug logging.
* The -DYYDEBUG log for parsing is controlled at compile time.
* The -y command line option only has an effect in -DYYDEBUG mode.

Extracting the logging into a separate file is a first step towards
unifying these logs and making the code for debug logging stand out less
than the current #ifdef DEBUG.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.204 -r1.205 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.321 -r1.322 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/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.81 src/usr.bin/xlint/lint1/Makefile:1.82
--- src/usr.bin/xlint/lint1/Makefile:1.81	Sat Jul 31 17:09:21 2021
+++ src/usr.bin/xlint/lint1/Makefile	Sat Jul 31 18:16:42 2021
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.81 2021/07/31 17:09:21 rillig Exp $
+#	$NetBSD: Makefile,v 1.82 2021/07/31 18:16:42 rillig Exp $
 
 .include 
 
 PROG=		lint1
 SRCS=		cgram.y \
-		ckbool.c ckctype.c ckgetopt.c \
+		ckbool.c ckctype.c ckgetopt.c debug.c \
 		decl.c emit.c emit1.c err.c func.c init.c inittyp.c lex.c \
 		main1.c mem.c mem1.c oper.c scan.l tree.c tyname.c
 

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.123 src/usr.bin/xlint/lint1/externs1.h:1.124
--- src/usr.bin/xlint/lint1/externs1.h:1.123	Sat Jul 31 17:09:21 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Jul 31 18:16:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.123 2021/07/31 17:09:21 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.124 2021/07/31 18:16:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -112,6 +112,42 @@ extern	struct	memory_block *expr_save_me
 extern	void	expr_restore_memory(struct memory_block *);
 
 /*
+ * debug.c
+ */
+
+#ifdef DEBUG
+void	debug_node(const tnode_t *, int);
+void	debug_printf(const char *fmt, ...) __printflike(1, 2);
+void	debug_indent(void);
+void	debug_indent_inc(void);
+void	debug_indent_dec(void);
+void	debug_enter(const char *);
+void	debug_step(const char *fmt, ...) __printflike(1, 2);
+#define	debug_step0		debug_step
+#define	debug_step1		debug_step
+#define	debug_step2		debug_step
+void	debug_leave(const char *);
+#define	debug_enter()		(debug_enter)(__func__)
+#define	debug_leave()		(debug_leave)(__func__)
+#else
+#define	debug_noop()		do { } while (false)
+#define	debug_node(tn, indent) debug_noop()
+/* ARGSUSED */
+static inline void __printflike(1, 2) debug_printf(const char *fmt, ...) {}
+#define debug_indent()		debug_noop()
+/* ARGSUSED */
+static inline void __printflike(1, 2) debug_step(const char *fmt, ...) {}
+#define	debug_indent()		debug_noop()
+#define	debug_indent_inc()	debug_noop()
+#define	debug_indent_dec()	debug_noop()
+#define	debug_enter()		debug_noop()
+#define	debug_step0(fmt)	debug_noop()
+#define	debug_step1(fmt, arg0)	debug_noop()
+#define	debug_step2(fmt, arg1, arg2) debug_noop()
+#define	debug_leave()		debug_noop()
+#endif
+
+/*
  * err.c
  */
 extern	int	nerr;
@@ -235,11 +271,6 @@ extern	void	check_expr_misc(const tnode_
 extern	bool	constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *);
 extern	strg_t	*cat_strings(strg_t *, strg_t *);
 extern  int64_t type_size_in_bits(const type_t *);
-#ifdef DEBUG
-extern	void	debug_node(const tnode_t *, int);
-#else
-#define debug_node(tn, indent) do { } while (false)
-#endif
 
 /*
  * func.c

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.204 src/usr.bin/xlint/lint1/init.c:1.205
--- src/usr.bin/xlint/lint1/init.c:1.204	Sat Jul 31 11:03:04 2021
+++ src/usr.bin/xlint/lint1/init.c	Sat Jul 31 18:16:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.205 2021/07/31 18:16:42 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.205 2021/07/31 18:16:42 rillig Exp $");
 #endif
 
 #include 
@@ -172,74 +172,6 @@ struct initialization {
 };
 
 
-#ifdef DEBUG
-static int debug_indentation = 0;
-#endif
-
-
-#ifdef DEBUG
-
-static void __printflike(1, 2)
-debug_printf(const char *fmt, ...)
-{
-	va_list va;
-
-	va_start(va, 

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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 17:09:21 UTC 2021

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

Log Message:
lint: add debugging output for the grammar tokens

No functional change outside debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.351 -r1.352 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.211 -r1.212 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/xlint/lint1/externs1.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/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.80 src/usr.bin/xlint/lint1/Makefile:1.81
--- src/usr.bin/xlint/lint1/Makefile:1.80	Sun Jul 25 22:14:36 2021
+++ src/usr.bin/xlint/lint1/Makefile	Sat Jul 31 17:09:21 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.80 2021/07/25 22:14:36 rillig Exp $
+#	$NetBSD: Makefile,v 1.81 2021/07/31 17:09:21 rillig Exp $
 
 .include 
 
@@ -22,7 +22,7 @@ LOBJS.${PROG}+=		${SRCS:M*.l:.l=.ln}
 
 CPPFLAGS+=	-DIS_LINT1
 CPPFLAGS+=	-I${.CURDIR}
-CPPFLAGS+=	${DEBUG:D-DDEBUG}
+CPPFLAGS+=	${DEBUG:D-DDEBUG -DYYDEBUG}
 
 COPTS.err.c+=	${${ACTIVE_CC} == "clang":? -Wno-format-nonliteral :}
 

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.351 src/usr.bin/xlint/lint1/cgram.y:1.352
--- src/usr.bin/xlint/lint1/cgram.y:1.351	Tue Jul 27 05:52:53 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 31 17:09:21 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.351 2021/07/27 05:52:53 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.352 2021/07/31 17:09:21 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.351 2021/07/27 05:52:53 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.352 2021/07/31 17:09:21 rillig Exp $");
 #endif
 
 #include 
@@ -122,6 +122,13 @@ anonymize(sym_t *s)
 		s->s_styp = NULL;
 }
 
+#if defined(YYDEBUG) && (defined(YYBYACC) || defined(YYBISON))
+#define YYSTYPE_TOSTRING cgram_to_string
+#endif
+#if defined(YYDEBUG) && defined(YYBISON)
+#define YYPRINT cgram_print
+#endif
+
 %}
 
 %expect 150
@@ -349,6 +356,12 @@ anonymize(sym_t *s)
 %type		do_while_expr
 %type			func_declarator
 
+%{
+#if defined(YYDEBUG) && defined(YYBISON)
+static void cgram_print(FILE *, int, YYSTYPE);
+#endif
+%}
+
 %%
 
 program:
@@ -2116,6 +2129,47 @@ yyerror(const char *msg)
 	return 0;
 }
 
+#if (defined(YYDEBUG) && YYDEBUG > 0 && defined(YYBYACC)) \
+|| (defined(YYDEBUG) && defined(YYBISON))
+static const char *
+cgram_to_string(int token, YYSTYPE val)
+{
+	static const char *tqual_name[] = {
+		"const", "volatile", "restrict", "_Thread_local"
+	};
+
+	switch (token) {
+	case T_INCDEC:
+	case T_MULTIPLICATIVE:
+	case T_ADDITIVE:
+	case T_SHIFT:
+	case T_RELATIONAL:
+	case T_EQUALITY:
+	case T_OPASSIGN:
+		return modtab[val.y_op].m_name;
+	case T_SCLASS:
+		return scl_name(val.y_scl);
+	case T_TYPE:
+	case T_STRUCT_OR_UNION:
+		return tspec_name(val.y_tspec);
+	case T_QUAL:
+		return tqual_name[val.y_tqual];
+	case T_NAME:
+		return val.y_name->sb_name;
+	default:
+		return "";
+	}
+}
+#endif
+
+#if defined(YYDEBUG) && defined(YYBISON)
+static void
+cgram_print(FILE *output, int token, YYSTYPE val)
+{
+	fprintf(output, "%s", cgram_to_string(token, val));
+}
+#endif
+
 static void
 cgram_declare(sym_t *decl, bool initflg, sbuf_t *renaming)
 {

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.211 src/usr.bin/xlint/lint1/decl.c:1.212
--- src/usr.bin/xlint/lint1/decl.c:1.211	Sat Jul 31 11:03:04 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sat Jul 31 17:09:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.211 2021/07/31 11:03:04 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.212 2021/07/31 17:09:21 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.211 2021/07/31 11:03:04 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.212 2021/07/31 17:09:21 rillig Exp $");
 #endif
 
 #include 
@@ -134,7 +134,7 @@ initdecl(void)
 }
 
 /* Return the name of the "storage class" in the wider sense. */
-static const char *
+const char *
 scl_name(scl_t scl)
 {
 	static const char *const names[] = {

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.122 src/usr.bin/xlint/lint1/externs1.h:1.123
--- src/usr.bin/xlint/lint1/externs1.h:1.122	Sat Jul 31 11:03:04 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Jul 31 17:09:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.122 2021/07/31 11:03:04 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.123 2021/07/31 17:09:21 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -198,6 +198,7 @@ extern	void	

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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 13:47:19 UTC 2021

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

Log Message:
lint: reduce indentation in 'search'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 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.56 src/usr.bin/xlint/lint1/lex.c:1.57
--- src/usr.bin/xlint/lint1/lex.c:1.56	Fri Jul 23 15:36:56 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sat Jul 31 13:47:19 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.56 2021/07/23 15:36:56 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.57 2021/07/31 13:47:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.56 2021/07/23 15:36:56 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.57 2021/07/31 13:47:19 rillig Exp $");
 #endif
 
 #include 
@@ -450,17 +450,20 @@ lex_name(const char *yytext, size_t yyle
 static sym_t *
 search(sbuf_t *sb)
 {
-	sym_t	*sym;
+	sym_t *sym;
+	const struct kwtab *kw;
 
 	for (sym = symtab[sb->sb_hash]; sym != NULL; sym = sym->s_link) {
-		if (strcmp(sym->s_name, sb->sb_name) == 0) {
-			if (sym->s_keyword != NULL) {
-const struct kwtab *kw = sym->s_keyword;
-if (!kw->kw_attr || attron)
-	return sym;
-			} else if (!attron && sym->s_kind == symtyp)
-return sym;
-		}
+		if (strcmp(sym->s_name, sb->sb_name) != 0)
+			continue;
+		kw = sym->s_keyword;
+
+		if (kw != NULL && !kw->kw_attr)
+			return sym;
+		if (kw != NULL && attron)
+			return sym;
+		if (kw == NULL && !attron && sym->s_kind == symtyp)
+			return sym;
 	}
 
 	return NULL;



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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 11:37:54 UTC 2021

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

Log Message:
lint: in has_constant_member, don't reuse variables

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.320 -r1.321 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.320 src/usr.bin/xlint/lint1/tree.c:1.321
--- src/usr.bin/xlint/lint1/tree.c:1.320	Sat Jul 31 11:03:04 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sat Jul 31 11:37:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.320 2021/07/31 11:03:04 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.321 2021/07/31 11:37:53 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.320 2021/07/31 11:03:04 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.321 2021/07/31 11:37:53 rillig Exp $");
 #endif
 
 #include 
@@ -2546,19 +2546,17 @@ merge_qualifiers(type_t *tp1, const type
 static bool
 has_constant_member(const type_t *tp)
 {
-	sym_t	*m;
-	tspec_t	t;
+	sym_t *m;
 
-	lint_assert((t = tp->t_tspec) == STRUCT || t == UNION);
+	lint_assert(is_struct_or_union(tp->t_tspec));
 
 	for (m = tp->t_str->sou_first_member; m != NULL; m = m->s_next) {
-		tp = m->s_type;
-		if (tp->t_const)
+		const type_t *mtp = m->s_type;
+		if (mtp->t_const)
+			return true;
+		if (is_struct_or_union(mtp->t_tspec) &&
+		has_constant_member(mtp))
 			return true;
-		if ((t = tp->t_tspec) == STRUCT || t == UNION) {
-			if (has_constant_member(m->s_type))
-return true;
-		}
 	}
 	return false;
 }



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

2021-07-31 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 31 11:03:04 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: decl.c externs1.h func.c init.c lint1.h tree.c

Log Message:
lint: merge duplicate code for generating unqualified type

This is a preparation for fixing the wrong warnings in msg_115.c.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.121 -r1.122 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.203 -r1.204 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.118 -r1.119 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.319 -r1.320 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.210 src/usr.bin/xlint/lint1/decl.c:1.211
--- src/usr.bin/xlint/lint1/decl.c:1.210	Sun Jul 25 22:14:36 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sat Jul 31 11:03:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.210 2021/07/25 22:14:36 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.211 2021/07/31 11:03:04 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.210 2021/07/25 22:14:36 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.211 2021/07/31 11:03:04 rillig Exp $");
 #endif
 
 #include 
@@ -187,6 +187,27 @@ expr_dup_type(const type_t *tp)
 }
 
 /*
+ * Return the unqualified version of the type.  The returned type is freed at
+ * the end of the current expression.
+ *
+ * See C99 6.2.5p25.
+ */
+type_t *
+expr_unqualified_type(const type_t *tp)
+{
+	type_t *ntp;
+
+	ntp = expr_zalloc(sizeof(*ntp));
+	*ntp = *tp;
+	ntp->t_const = false;
+	ntp->t_volatile = false;
+
+	/* TODO: deep-copy struct/union members; see msg_115.c */
+
+	return ntp;
+}
+
+/*
  * Returns whether the argument is void or an incomplete array,
  * struct, union or enum type.
  */

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.121 src/usr.bin/xlint/lint1/externs1.h:1.122
--- src/usr.bin/xlint/lint1/externs1.h:1.121	Sun Jul 25 22:14:36 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sat Jul 31 11:03:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.121 2021/07/25 22:14:36 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.122 2021/07/31 11:03:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -145,6 +145,7 @@ extern	void	initdecl(void);
 extern	type_t	*gettyp(tspec_t);
 extern	type_t	*dup_type(const type_t *);
 extern	type_t	*expr_dup_type(const type_t *);
+extern	type_t	*expr_unqualified_type(const type_t *);
 extern	bool	is_incomplete(const type_t *);
 extern	void	setcomplete(type_t *, bool);
 extern	void	add_storage_class(scl_t);

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.115 src/usr.bin/xlint/lint1/func.c:1.116
--- src/usr.bin/xlint/lint1/func.c:1.115	Fri Jul 23 17:06:37 2021
+++ src/usr.bin/xlint/lint1/func.c	Sat Jul 31 11:03:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.116 2021/07/31 11:03:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.116 2021/07/31 11:03:04 rillig Exp $");
 #endif
 
 #include 
@@ -1091,8 +1091,7 @@ do_return(tnode_t *tn)
 		/* Create a temporary node for the left side */
 		ln = expr_zalloc(sizeof(*ln));
 		ln->tn_op = NAME;
-		ln->tn_type = expr_dup_type(funcsym->s_type->t_subt);
-		ln->tn_type->t_const = false;
+		ln->tn_type = expr_unqualified_type(funcsym->s_type->t_subt);
 		ln->tn_lvalue = true;
 		ln->tn_sym = funcsym;		/* better than nothing */
 

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.203 src/usr.bin/xlint/lint1/init.c:1.204
--- src/usr.bin/xlint/lint1/init.c:1.203	Tue Jul 20 19:44:36 2021
+++ src/usr.bin/xlint/lint1/init.c	Sat Jul 31 11:03:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.203 2021/07/20 19:44:36 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.203 2021/07/20 19:44:36 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.204 2021/07/31 11:03:04 rillig Exp $");
 #endif
 
 #include 
@@ -400,8 +400,7 @@ check_init_expr(const type_t *tp, sym_t 
 	tspec_t lt, rt;
 	struct memory_block *tmem;
 
-	ltp = expr_dup_type(tp);
-	ltp->t_const = false;
+	ltp = expr_unqualified_type(tp);
 
 	/* Create a temporary node for the left side. */
 	ln = expr_zalloc(sizeof(*ln));
@@ -900,8 +899,7 @@ 

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

2021-07-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Jul 27 05:52:53 UTC 2021

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

Log Message:
lint: inline align_as in the grammar

This saves 500 bytes in the resulting binary.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.350 -r1.351 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.350 src/usr.bin/xlint/lint1/cgram.y:1.351
--- src/usr.bin/xlint/lint1/cgram.y:1.350	Tue Jul 27 05:42:36 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Jul 27 05:52:53 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.350 2021/07/27 05:42:36 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.351 2021/07/27 05:52:53 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.350 2021/07/27 05:42:36 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.351 2021/07/27 05:52:53 rillig Exp $");
 #endif
 
 #include 
@@ -836,19 +836,14 @@ type_attribute_opt:
 
 type_attribute:			/* See C11 6.7 declaration-specifiers */
 	  gcc_attribute
-	  /* TODO: c11ism */
-	| T_ALIGNAS T_LPAREN align_as T_RPAREN
+	| T_ALIGNAS T_LPAREN type_specifier T_RPAREN	/* C11 6.7.5 */
+	| T_ALIGNAS T_LPAREN constant_expr T_RPAREN	/* C11 6.7.5 */
 	| T_PACKED {
 		addpacked();
 	  }
 	| T_NORETURN
 	;
 
-align_as:			/* See alignment-specifier in C11 6.7.5 */
-	  type_specifier
-	| constant_expr
-	;
-
 begin_type:
 	  /* empty */ {
 		begin_type();



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

2021-07-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Jul 27 05:42:36 UTC 2021

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

Log Message:
lint: provide a direct link to the documentation

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.349 -r1.350 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.349 src/usr.bin/xlint/lint1/cgram.y:1.350
--- src/usr.bin/xlint/lint1/cgram.y:1.349	Mon Jul 26 18:10:14 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Jul 27 05:42:36 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.349 2021/07/26 18:10:14 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.350 2021/07/27 05:42:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.349 2021/07/26 18:10:14 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.350 2021/07/27 05:42:36 rillig Exp $");
 #endif
 
 #include 
@@ -1154,8 +1154,8 @@ type_qualifier_list:		/* C99 6.7.5 */
 	;
 
 /*
- * For an explanation of 'notype' in the following rules, see the Bison
- * manual, section 7.1 "Semantic Info in Token Kinds".
+ * For an explanation of 'notype' in the following rules, see
+ * https://www.gnu.org/software/bison/manual/bison.html#Semantic-Tokens.
  */
 
 notype_init_declarators:



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

2021-07-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul 26 17:15:24 UTC 2021

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

Log Message:
lint: remove redundant associativity declarations

Since cgram.y 1.325 from 2021-07-15, these are not needed anymore.
Strangely, neither yacc nor Bison warned about this redundancy.

No functional change, the grammar rules are the same as before.


To generate a diff of this commit:
cvs rdiff -u -r1.346 -r1.347 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.346 src/usr.bin/xlint/lint1/cgram.y:1.347
--- src/usr.bin/xlint/lint1/cgram.y:1.346	Sun Jul 25 21:31:01 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Mon Jul 26 17:15:24 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.346 2021/07/25 21:31:01 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.347 2021/07/26 17:15:24 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.346 2021/07/25 21:31:01 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.347 2021/07/26 17:15:24 rillig Exp $");
 #endif
 
 #include 
@@ -260,8 +260,6 @@ anonymize(sym_t *s)
 
 %left	T_THEN
 %left	T_ELSE
-%left	T_COMMA
-%right	T_ASSIGN T_OPASSIGN
 %right	T_QUEST T_COLON
 %left	T_LOGOR
 %left	T_LOGAND



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

2021-07-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul 26 16:22:24 UTC 2021

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

Log Message:
lint: make typeok_scalar_strict_bool simpler

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 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.7 src/usr.bin/xlint/lint1/ckbool.c:1.8
--- src/usr.bin/xlint/lint1/ckbool.c:1.7	Sun Jul  4 09:13:59 2021
+++ src/usr.bin/xlint/lint1/ckbool.c	Mon Jul 26 16:22:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.7 2021/07/04 09:13:59 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.8 2021/07/26 16:22:24 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include 
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckbool.c,v 1.7 2021/07/04 09:13:59 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.8 2021/07/26 16:22:24 rillig Exp $");
 #endif
 
 #include 
@@ -181,7 +181,7 @@ typeok_scalar_strict_bool(op_t op, const
 
 	if (!mp->m_takes_bool) {
 		bool binary = mp->m_binary;
-		bool lbool = ln->tn_type->t_tspec == BOOL;
+		bool lbool = lt == BOOL;
 		bool ok = true;
 
 		if (!binary && lbool) {
@@ -194,7 +194,7 @@ typeok_scalar_strict_bool(op_t op, const
 			error(336, op_name(op));
 			ok = false;
 		}
-		if (binary && rn->tn_type->t_tspec == BOOL) {
+		if (binary && rt == BOOL) {
 			/* right operand of '%s' must not be bool */
 			error(337, op_name(op));
 			ok = false;



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

2021-07-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 25 22:14:37 UTC 2021

Modified Files:
src/usr.bin/xlint/lint1: Makefile decl.c externs1.h
Removed Files:
src/usr.bin/xlint/lint1: print.c

Log Message:
lint: move scl_name from print.c to decl.c

It is only needed there.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.209 -r1.210 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.15 -r0 src/usr.bin/xlint/lint1/print.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/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.79 src/usr.bin/xlint/lint1/Makefile:1.80
--- src/usr.bin/xlint/lint1/Makefile:1.79	Sat Jul 10 09:14:38 2021
+++ src/usr.bin/xlint/lint1/Makefile	Sun Jul 25 22:14:36 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.79 2021/07/10 09:14:38 rillig Exp $
+#	$NetBSD: Makefile,v 1.80 2021/07/25 22:14:36 rillig Exp $
 
 .include 
 
@@ -6,7 +6,7 @@ PROG=		lint1
 SRCS=		cgram.y \
 		ckbool.c ckctype.c ckgetopt.c \
 		decl.c emit.c emit1.c err.c func.c init.c inittyp.c lex.c \
-		main1.c mem.c mem1.c oper.c print.c scan.l tree.c tyname.c
+		main1.c mem.c mem1.c oper.c scan.l tree.c tyname.c
 
 MAN=		lint.7
 YHEADER=

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.209 src/usr.bin/xlint/lint1/decl.c:1.210
--- src/usr.bin/xlint/lint1/decl.c:1.209	Fri Jul 23 16:48:48 2021
+++ src/usr.bin/xlint/lint1/decl.c	Sun Jul 25 22:14:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.209 2021/07/23 16:48:48 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.210 2021/07/25 22:14:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.209 2021/07/23 16:48:48 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.210 2021/07/25 22:14:36 rillig Exp $");
 #endif
 
 #include 
@@ -133,6 +133,20 @@ initdecl(void)
 	typetab[UNSIGN].t_tspec = UNSIGN;
 }
 
+/* Return the name of the "storage class" in the wider sense. */
+static const char *
+scl_name(scl_t scl)
+{
+	static const char *const names[] = {
+	"none", "extern", "static", "auto", "register", "typedef",
+	"struct", "union", "enum", "member of struct", "member of union",
+	"compile-time constant", "abstract", "argument",
+	"prototype argument", "inline"
+	};
+
+	return names[scl];
+}
+
 /*
  * Returns a shared type structure for arithmetic types and void.
  *

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.120 src/usr.bin/xlint/lint1/externs1.h:1.121
--- src/usr.bin/xlint/lint1/externs1.h:1.120	Tue Jul 20 19:44:36 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Sun Jul 25 22:14:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.120 2021/07/20 19:44:36 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.121 2021/07/25 22:14:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -340,11 +340,6 @@ extern	void	lex_unknown_character(int);
 extern	int	lex_input(void);
 
 /*
- * print.c
- */
-const char	*scl_name(scl_t);
-
-/*
  * ckbool.c
  */
 extern	bool	typeok_scalar_strict_bool(op_t, const mod_t *, int,



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

2021-07-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 25 21:31:01 UTC 2021

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

Log Message:
lint: revert previous commit; it didn't improve readability

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.345 -r1.346 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.345 src/usr.bin/xlint/lint1/cgram.y:1.346
--- src/usr.bin/xlint/lint1/cgram.y:1.345	Sun Jul 25 19:57:22 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 25 21:31:01 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.345 2021/07/25 19:57:22 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.346 2021/07/25 21:31:01 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.345 2021/07/25 19:57:22 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.346 2021/07/25 21:31:01 rillig Exp $");
 #endif
 
 #include 
@@ -337,9 +337,7 @@ anonymize(sym_t *s)
 %type			identifier_list
 %type		type_name
 %type			abstract_declaration
-%type			abstract_declarator_opt
 %type			abstract_declarator
-%type			direct_abstract_declarator_opt
 %type			direct_abstract_declarator
 %type			abstract_decl_param_list
 %type			vararg_parameter_type_list
@@ -1373,36 +1371,30 @@ type_name:			/* C99 6.7.6 */
 	;
 
 abstract_declaration:		/* specific to lint */
-	  begin_type_qualifier_list end_type abstract_declarator_opt {
-		$$ = declare_1_abstract($3);
+	  begin_type_qualifier_list end_type {
+		$$ = declare_1_abstract(abstract_name());
+	  }
+	| begin_type_specifier_qualifier_list end_type {
+		$$ = declare_1_abstract(abstract_name());
 	  }
-	| begin_type_specifier_qualifier_list end_type
-	abstract_declarator_opt {
+	| begin_type_qualifier_list end_type abstract_declarator {
 		$$ = declare_1_abstract($3);
 	  }
-	;
-
-abstract_declarator_opt:
-	  /* empty */ {
-		$$ = abstract_name();
+	| begin_type_specifier_qualifier_list end_type abstract_declarator {
+		$$ = declare_1_abstract($3);
 	  }
-	| abstract_declarator
 	;
 
 /* K 8.7, C90 ???, C99 6.7.6, C11 6.7.7 */
 /* In K, abstract-declarator could be empty and was still simpler. */
 abstract_declarator:
-	  pointer direct_abstract_declarator_opt {
-		$$ = add_pointer($2, $1);
+	  pointer {
+		$$ = add_pointer(abstract_name(), $1);
 	  }
 	| direct_abstract_declarator
-	;
-
-direct_abstract_declarator_opt:
-	  /* empty */ {
-		$$ = abstract_name();
+	| pointer direct_abstract_declarator {
+		$$ = add_pointer($2, $1);
 	  }
-	| direct_abstract_declarator
 	;
 
 /* K ---, C90 ???, C99 6.7.6, C11 6.7.7 */



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

2021-07-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 25 19:57:22 UTC 2021

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

Log Message:
lint: merge duplicate code for abstract_declaration

No functional change; same code coverage outside of cgram.y.


To generate a diff of this commit:
cvs rdiff -u -r1.344 -r1.345 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.344 src/usr.bin/xlint/lint1/cgram.y:1.345
--- src/usr.bin/xlint/lint1/cgram.y:1.344	Sun Jul 25 19:27:26 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 25 19:57:22 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.344 2021/07/25 19:27:26 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.345 2021/07/25 19:57:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.344 2021/07/25 19:27:26 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.345 2021/07/25 19:57:22 rillig Exp $");
 #endif
 
 #include 
@@ -337,7 +337,9 @@ anonymize(sym_t *s)
 %type			identifier_list
 %type		type_name
 %type			abstract_declaration
+%type			abstract_declarator_opt
 %type			abstract_declarator
+%type			direct_abstract_declarator_opt
 %type			direct_abstract_declarator
 %type			abstract_decl_param_list
 %type			vararg_parameter_type_list
@@ -1371,30 +1373,36 @@ type_name:			/* C99 6.7.6 */
 	;
 
 abstract_declaration:		/* specific to lint */
-	  begin_type_qualifier_list end_type {
-		$$ = declare_1_abstract(abstract_name());
-	  }
-	| begin_type_specifier_qualifier_list end_type {
-		$$ = declare_1_abstract(abstract_name());
-	  }
-	| begin_type_qualifier_list end_type abstract_declarator {
+	  begin_type_qualifier_list end_type abstract_declarator_opt {
 		$$ = declare_1_abstract($3);
 	  }
-	| begin_type_specifier_qualifier_list end_type abstract_declarator {
+	| begin_type_specifier_qualifier_list end_type
+	abstract_declarator_opt {
 		$$ = declare_1_abstract($3);
 	  }
 	;
 
+abstract_declarator_opt:
+	  /* empty */ {
+		$$ = abstract_name();
+	  }
+	| abstract_declarator
+	;
+
 /* K 8.7, C90 ???, C99 6.7.6, C11 6.7.7 */
 /* In K, abstract-declarator could be empty and was still simpler. */
 abstract_declarator:
-	  pointer {
-		$$ = add_pointer(abstract_name(), $1);
+	  pointer direct_abstract_declarator_opt {
+		$$ = add_pointer($2, $1);
 	  }
 	| direct_abstract_declarator
-	| pointer direct_abstract_declarator {
-		$$ = add_pointer($2, $1);
+	;
+
+direct_abstract_declarator_opt:
+	  /* empty */ {
+		$$ = abstract_name();
 	  }
+	| direct_abstract_declarator
 	;
 
 /* K ---, C90 ???, C99 6.7.6, C11 6.7.7 */



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

2021-07-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 25 19:27:26 UTC 2021

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

Log Message:
lint: resolve conflicts in begin_type_specifier_qualifier_list

The 9 shift/reduce conflicts were all internal to the grammar rule
begin_type_specifier_qualifier_list.  Previously, there were two
possible ways to parse '__attribute__(()) const int':

1. '__attribute__(())' 'const int'
2. '__attribute__(()) const' 'int'

Both ways would produce the same result since __attribute__ has almost
no observable effects on the resulting type.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.343 -r1.344 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.343 src/usr.bin/xlint/lint1/cgram.y:1.344
--- src/usr.bin/xlint/lint1/cgram.y:1.343	Sun Jul 25 19:05:27 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 25 19:27:26 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.343 2021/07/25 19:05:27 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.344 2021/07/25 19:27:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.343 2021/07/25 19:05:27 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.344 2021/07/25 19:27:26 rillig Exp $");
 #endif
 
 #include 
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
 
 %}
 
-%expect 159
+%expect 150
 
 %union {
 	val_t	*y_val;
@@ -778,21 +778,24 @@ begin_type_declmods:		/* see C99 6.7 */
 	;
 
 begin_type_specifier_qualifier_list:	/* see C11 6.7.2.1 */
+	  begin_type_specifier_qualifier_list_postfix
+	| type_attribute_list begin_type_specifier_qualifier_list_postfix
+	;
+
+begin_type_specifier_qualifier_list_postfix:
 	  begin_type_typespec {
 		add_type($1);
 	  }
-	  /* TODO: shift/reduce conflict for type_attribute */
-	| type_attribute begin_type_specifier_qualifier_list
 	| begin_type_qualifier_list type_specifier {
 		add_type($2);
 	  }
-	| begin_type_specifier_qualifier_list T_QUAL {
+	| begin_type_specifier_qualifier_list_postfix T_QUAL {
 		add_qualifier($2);
 	  }
-	| begin_type_specifier_qualifier_list notype_type_specifier {
+	| begin_type_specifier_qualifier_list_postfix notype_type_specifier {
 		add_type($2);
 	  }
-	| begin_type_specifier_qualifier_list type_attribute
+	| begin_type_specifier_qualifier_list_postfix type_attribute
 	;
 
 begin_type_typespec:



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

2021-07-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 25 18:01:03 UTC 2021

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

Log Message:
lint: add citations for a few grammar rules

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.339 -r1.340 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.339 src/usr.bin/xlint/lint1/cgram.y:1.340
--- src/usr.bin/xlint/lint1/cgram.y:1.339	Sun Jul 25 17:40:04 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 25 18:01:03 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.339 2021/07/25 17:40:04 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.340 2021/07/25 18:01:03 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.339 2021/07/25 17:40:04 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.340 2021/07/25 18:01:03 rillig Exp $");
 #endif
 
 #include 
@@ -1366,7 +1366,7 @@ type_name:			/* C99 6.7.6 */
 	  }
 	;
 
-abstract_declaration:
+abstract_declaration:		/* specific to lint */
 	  begin_type_qualifier_list end_type {
 		$$ = declare_1_abstract(abstract_name());
 	  }
@@ -1381,7 +1381,9 @@ abstract_declaration:
 	  }
 	;
 
-abstract_declarator:		/* C99 6.7.6 */
+/* K 8.7, C90 ???, C99 6.7.6, C11 6.7.7 */
+/* In K, abstract-declarator could be empty and was still simpler. */
+abstract_declarator:
 	  pointer {
 		$$ = add_pointer(abstract_name(), $1);
 	  }
@@ -1391,7 +1393,8 @@ abstract_declarator:		/* C99 6.7.6 */
 	  }
 	;
 
-direct_abstract_declarator:	/* C99 6.7.6 */
+/* K ---, C90 ???, C99 6.7.6, C11 6.7.7 */
+direct_abstract_declarator:
 	  T_LPAREN abstract_declarator T_RPAREN {
 		$$ = $2;
 	  }
@@ -1428,7 +1431,7 @@ direct_abstract_declarator:	/* C99 6.7.6
 	| direct_abstract_declarator type_attribute_list
 	;
 
-abstract_decl_param_list:
+abstract_decl_param_list:	/* specific to lint */
 	  abstract_decl_lparen T_RPAREN type_attribute_opt {
 		$$ = NULL;
 	  }
@@ -1442,14 +1445,14 @@ abstract_decl_param_list:
 	  }
 	;
 
-abstract_decl_lparen:
+abstract_decl_lparen:		/* specific to lint */
 	  T_LPAREN {
 		block_level++;
 		begin_declaration_level(PROTO_ARG);
 	  }
 	;
 
-vararg_parameter_type_list:
+vararg_parameter_type_list:	/* specific to lint */
 	  parameter_type_list
 	| parameter_type_list T_COMMA T_ELLIPSIS {
 		dcs->d_vararg = true;



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

2021-07-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 25 16:57:23 UTC 2021

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

Log Message:
lint: wrap overly long lines

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.337 -r1.338 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.337 src/usr.bin/xlint/lint1/cgram.y:1.338
--- src/usr.bin/xlint/lint1/cgram.y:1.337	Sun Jul 25 15:58:24 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 25 16:57:23 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.337 2021/07/25 15:58:24 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.338 2021/07/25 16:57:23 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.337 2021/07/25 15:58:24 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.338 2021/07/25 16:57:23 rillig Exp $");
 #endif
 
 #include 
@@ -608,7 +608,8 @@ unary_expression:
 	| T_SIZEOF unary_expression {
 		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
 		if ($$ != NULL)
-			check_expr_misc($2, false, false, false, false, false, true);
+			check_expr_misc($2,
+			false, false, false, false, false, true);
 	  }
 	| T_SIZEOF T_LPAREN type_name T_RPAREN {
 		$$ = build_sizeof($3);
@@ -971,7 +972,8 @@ struct_declaration:		/* C99 6.7.2.1 */
 		error(249, "member without type");
 		$$ = NULL;
 	  }
-	| begin_type_specifier_qualifier_list end_type type_attribute_opt T_SEMI {
+	| begin_type_specifier_qualifier_list end_type type_attribute_opt
+	T_SEMI {
 		symtyp = FVFT;
 		if (!Sflag)
 			/* anonymous struct/union members is a C9X feature */
@@ -1016,7 +1018,7 @@ type_struct_declarators:
 
 notype_struct_declarator:
 	  notype_declarator
-	| notype_declarator T_COLON constant_expr {		/* C99 6.7.2.1 */
+	| notype_declarator T_COLON constant_expr {	/* C99 6.7.2.1 */
 		$$ = bitfield($1, to_int_constant($3, true));
 	  }
 	| {
@@ -1107,7 +1109,8 @@ enumerator:			/* C99 6.7.2.2 */
 		$$ = enumeration_constant($1, enumval, true);
 	  }
 	| identifier_sym T_ASSIGN constant_expr {
-		$$ = enumeration_constant($1, to_int_constant($3, true), false);
+		$$ = enumeration_constant($1, to_int_constant($3, true),
+		false);
 	  }
 	;
 
@@ -1258,9 +1261,9 @@ type_direct_declarator:
 	;
 
 /*
- * The two distinct rules type_param_declarator and notype_param_declarator avoid a
- * conflict in argument lists. A typename enclosed in parentheses is always
- * treated as a typename, not an argument name. For example, after
+ * The two distinct rules type_param_declarator and notype_param_declarator
+ * avoid a conflict in argument lists. A typename enclosed in parentheses is
+ * always treated as a typename, not an argument name. For example, after
  * "typedef double a;", the declaration "f(int (a));" is interpreted as
  * "f(int (double));", not "f(int a);".
  */
@@ -1400,7 +1403,8 @@ direct_abstract_declarator:	/* C99 6.7.6
 		$$ = add_array(abstract_name(), false, 0);
 	  }
 	| T_LBRACK array_size T_RBRACK {
-		$$ = add_array(abstract_name(), true, to_int_constant($2, false));
+		$$ = add_array(abstract_name(), true,
+		to_int_constant($2, false));
 	  }
 	| type_attribute direct_abstract_declarator {
 		$$ = $2;
@@ -1419,7 +1423,8 @@ direct_abstract_declarator:	/* C99 6.7.6
 		end_declaration_level();
 		block_level--;
 	  }
-	| direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt {
+	| direct_abstract_declarator abstract_decl_param_list
+	asm_or_symbolrename_opt {
 		$$ = add_function(symbolrename($1, $3), $2);
 		end_declaration_level();
 		block_level--;
@@ -1431,7 +1436,8 @@ abstract_decl_param_list:
 	  abstract_decl_lparen T_RPAREN type_attribute_opt {
 		$$ = NULL;
 	  }
-	| abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt {
+	| abstract_decl_lparen vararg_parameter_type_list T_RPAREN
+	type_attribute_opt {
 		dcs->d_proto = true;
 		$$ = $2;
 	  }



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

2021-07-23 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 23 17:06:37 UTC 2021

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

Log Message:
lint: rename cstk_t to control_statement

Rename the variables as well.  Their previous name 'ci' was not easy to
understand, the 'i' may have meant 'stack item'.  The new name 'cs'
simply means 'control statement'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.117 -r1.118 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.114 src/usr.bin/xlint/lint1/func.c:1.115
--- src/usr.bin/xlint/lint1/func.c:1.114	Tue Jul 20 19:35:53 2021
+++ src/usr.bin/xlint/lint1/func.c	Fri Jul 23 17:06:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.114 2021/07/20 19:35:53 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.114 2021/07/20 19:35:53 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.115 2021/07/23 17:06:37 rillig Exp $");
 #endif
 
 #include 
@@ -76,7 +76,7 @@ bool	warn_about_unreachable;
 bool	seen_fallthrough;
 
 /* The innermost control statement */
-cstk_t	*cstmt;
+control_statement *cstmt;
 
 /*
  * Number of arguments which will be checked for usage in following
@@ -155,12 +155,12 @@ bool	quadflg;
 void
 begin_control_statement(control_statement_kind kind)
 {
-	cstk_t	*ci;
+	control_statement *cs;
 
-	ci = xcalloc(1, sizeof(*ci));
-	ci->c_kind = kind;
-	ci->c_surrounding = cstmt;
-	cstmt = ci;
+	cs = xcalloc(1, sizeof(*cs));
+	cs->c_kind = kind;
+	cs->c_surrounding = cstmt;
+	cstmt = cs;
 }
 
 /*
@@ -169,7 +169,7 @@ begin_control_statement(control_statemen
 void
 end_control_statement(control_statement_kind kind)
 {
-	cstk_t	*ci;
+	control_statement *cs;
 	case_label_t *cl, *next;
 
 	lint_assert(cstmt != NULL);
@@ -177,16 +177,16 @@ end_control_statement(control_statement_
 	while (cstmt->c_kind != kind)
 		cstmt = cstmt->c_surrounding;
 
-	ci = cstmt;
-	cstmt = ci->c_surrounding;
+	cs = cstmt;
+	cstmt = cs->c_surrounding;
 
-	for (cl = ci->c_case_labels; cl != NULL; cl = next) {
+	for (cl = cs->c_case_labels; cl != NULL; cl = next) {
 		next = cl->cl_next;
 		free(cl);
 	}
 
-	free(ci->c_switch_type);
-	free(ci);
+	free(cs->c_switch_type);
+	free(cs);
 }
 
 static void
@@ -465,32 +465,32 @@ check_case_label_bitand(const tnode_t *c
 }
 
 static void
-check_case_label_enum(const tnode_t *tn, const cstk_t *ci)
+check_case_label_enum(const tnode_t *tn, const control_statement *cs)
 {
 	/* similar to typeok_enum in tree.c */
 
-	if (!(tn->tn_type->t_is_enum || ci->c_switch_type->t_is_enum))
+	if (!(tn->tn_type->t_is_enum || cs->c_switch_type->t_is_enum))
 		return;
-	if (tn->tn_type->t_is_enum && ci->c_switch_type->t_is_enum &&
-	tn->tn_type->t_enum == ci->c_switch_type->t_enum)
+	if (tn->tn_type->t_is_enum && cs->c_switch_type->t_is_enum &&
+	tn->tn_type->t_enum == cs->c_switch_type->t_enum)
 		return;
 
 #if 0 /* not yet ready, see msg_130.c */
 	/* enum type mismatch: '%s' '%s' '%s' */
-	warning(130, type_name(ci->c_switch_type), op_name(EQ),
+	warning(130, type_name(cs->c_switch_type), op_name(EQ),
 	type_name(tn->tn_type));
 #endif
 }
 
 static void
-check_case_label(tnode_t *tn, cstk_t *ci)
+check_case_label(tnode_t *tn, control_statement *cs)
 {
 	case_label_t *cl;
 	val_t	*v;
 	val_t	nv;
 	tspec_t	t;
 
-	if (ci == NULL) {
+	if (cs == NULL) {
 		/* case not in switch */
 		error(195);
 		return;
@@ -508,10 +508,10 @@ check_case_label(tnode_t *tn, cstk_t *ci
 		return;
 	}
 
-	check_case_label_bitand(tn, ci->c_switch_expr);
-	check_case_label_enum(tn, ci);
+	check_case_label_bitand(tn, cs->c_switch_expr);
+	check_case_label_enum(tn, cs);
 
-	lint_assert(ci->c_switch_type != NULL);
+	lint_assert(cs->c_switch_type != NULL);
 
 	if (reached && !seen_fallthrough) {
 		if (hflag)
@@ -533,11 +533,11 @@ check_case_label(tnode_t *tn, cstk_t *ci
 	 */
 	v = constant(tn, true);
 	(void)memset(, 0, sizeof(nv));
-	convert_constant(CASE, 0, ci->c_switch_type, , v);
+	convert_constant(CASE, 0, cs->c_switch_type, , v);
 	free(v);
 
 	/* look if we had this value already */
-	for (cl = ci->c_case_labels; cl != NULL; cl = cl->cl_next) {
+	for (cl = cs->c_case_labels; cl != NULL; cl = cl->cl_next) {
 		if (cl->cl_val.v_quad == nv.v_quad)
 			break;
 	}
@@ -553,21 +553,21 @@ check_case_label(tnode_t *tn, cstk_t *ci
 		/* append the value to the list of case values */
 		cl = xcalloc(1, sizeof(*cl));
 		cl->cl_val = nv;
-		cl->cl_next = ci->c_case_labels;
-		ci->c_case_labels = cl;
+		cl->cl_next = cs->c_case_labels;
+		cs->c_case_labels = cl;
 	}
 }
 
 void
 case_label(tnode_t *tn)
 {
-	cstk_t	*ci;
+	

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

2021-07-23 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 23 16:48:48 UTC 2021

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

Log Message:
lint: remove a few unnecessary abbreviations

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.116 -r1.117 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/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.208 src/usr.bin/xlint/lint1/decl.c:1.209
--- src/usr.bin/xlint/lint1/decl.c:1.208	Fri Jul 23 16:43:11 2021
+++ src/usr.bin/xlint/lint1/decl.c	Fri Jul 23 16:48:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.208 2021/07/23 16:43:11 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.209 2021/07/23 16:48:48 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.208 2021/07/23 16:43:11 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.209 2021/07/23 16:48:48 rillig Exp $");
 #endif
 
 #include 
@@ -236,11 +236,7 @@ add_storage_class(scl_t sc)
 	if (dcs->d_scl == NOSCL) {
 		dcs->d_scl = sc;
 	} else {
-		/*
-		 * multiple storage classes. An error will be reported in
-		 * end_type().
-		 */
-		dcs->d_mscl = true;
+		dcs->d_multiple_storage_classes = true;
 	}
 }
 
@@ -284,11 +280,7 @@ add_type(type_t *tp)
 		 */
 		if (dcs->d_type != NULL || dcs->d_abstract_type != NOTSPEC ||
 		dcs->d_rank_mod != NOTSPEC || dcs->d_sign_mod != NOTSPEC) {
-			/*
-			 * remember that an error must be reported in
-			 * end_type().
-			 */
-			dcs->d_terr = true;
+			dcs->d_invalid_type_combination = true;
 			dcs->d_abstract_type = NOTSPEC;
 			dcs->d_sign_mod = NOTSPEC;
 			dcs->d_rank_mod = NOTSPEC;
@@ -302,7 +294,7 @@ add_type(type_t *tp)
 		 * something like "struct a int"
 		 * struct/union/enum with anything else is not allowed
 		 */
-		dcs->d_terr = true;
+		dcs->d_invalid_type_combination = true;
 		return;
 	}
 
@@ -341,11 +333,8 @@ add_type(type_t *tp)
 		 * dcs->d_sign_mod
 		 */
 		if (dcs->d_sign_mod != NOTSPEC)
-			/*
-			 * more than one "signed" and/or "unsigned"; print
-			 * an error in end_type()
-			 */
-			dcs->d_terr = true;
+			/* more than one "signed" and/or "unsigned" */
+			dcs->d_invalid_type_combination = true;
 		dcs->d_sign_mod = t;
 	} else if (t == SHORT || t == LONG || t == QUAD) {
 		/*
@@ -353,18 +342,17 @@ add_type(type_t *tp)
 		 * dcs->d_rank_mod
 		 */
 		if (dcs->d_rank_mod != NOTSPEC)
-			/* more than one, print error in end_type() */
-			dcs->d_terr = true;
+			dcs->d_invalid_type_combination = true;
 		dcs->d_rank_mod = t;
 	} else if (t == FLOAT || t == DOUBLE) {
 		if (dcs->d_rank_mod == NOTSPEC || dcs->d_rank_mod == LONG) {
 			if (dcs->d_complex_mod != NOTSPEC
 			|| (t == FLOAT && dcs->d_rank_mod == LONG))
-dcs->d_terr = true;
+dcs->d_invalid_type_combination = true;
 			dcs->d_complex_mod = t;
 		} else {
 			if (dcs->d_abstract_type != NOTSPEC)
-dcs->d_terr = true;
+dcs->d_invalid_type_combination = true;
 			dcs->d_abstract_type = t;
 		}
 	} else if (t == PTR) {
@@ -375,8 +363,7 @@ add_type(type_t *tp)
 		 * or "_Complex" in dcs->d_abstract_type
 		 */
 		if (dcs->d_abstract_type != NOTSPEC)
-			/* more than one, print error in end_type() */
-			dcs->d_terr = true;
+			dcs->d_invalid_type_combination = true;
 		dcs->d_abstract_type = t;
 	}
 }
@@ -491,7 +478,7 @@ tdeferr(type_t *td, tspec_t t)
 
 	/* Anything other is not accepted. */
 
-	dcs->d_terr = true;
+	dcs->d_invalid_type_combination = true;
 	return td;
 }
 
@@ -738,8 +725,8 @@ begin_type(void)
 	dcs->d_const = false;
 	dcs->d_volatile = false;
 	dcs->d_inline = false;
-	dcs->d_mscl = false;
-	dcs->d_terr = false;
+	dcs->d_multiple_storage_classes = false;
+	dcs->d_invalid_type_combination = false;
 	dcs->d_nonempty_decl = false;
 	dcs->d_notyp = false;
 }
@@ -801,7 +788,7 @@ dcs_merge_declaration_specifiers(void)
 	if (s == NOTSPEC && t == INT)
 		s = SIGNED;
 	if (l != NOTSPEC && t == CHAR) {
-		dcs->d_terr = true;
+		dcs->d_invalid_type_combination = true;
 		l = NOTSPEC;
 	}
 	if (l == LONG && t == FLOAT) {
@@ -825,7 +812,7 @@ dcs_merge_declaration_specifiers(void)
 	}
 
 	if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) {
-		dcs->d_terr = true;
+		dcs->d_invalid_type_combination = true;
 		l = s = NOTSPEC;
 	}
 	if (l != NOTSPEC)
@@ -845,11 +832,11 @@ end_type(void)
 
 	dcs_merge_declaration_specifiers();
 
-	if (dcs->d_mscl) {
+	if (dcs->d_multiple_storage_classes) {
 		/* only one storage class allowed */
 		error(7);
 	}
-	if (dcs->d_terr) {
+	if (dcs->d_invalid_type_combination) {
 		/* illegal type combination */
 		error(4);
 	}

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.116 src/usr.bin/xlint/lint1/lint1.h:1.117
--- 

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

2021-07-23 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 23 16:43:11 UTC 2021

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

Log Message:
lint: make offset and alignment positive numbers

There's no use case for negative alignment or offsets in structures.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.115 -r1.116 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/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.207 src/usr.bin/xlint/lint1/decl.c:1.208
--- src/usr.bin/xlint/lint1/decl.c:1.207	Thu Jul 15 23:54:22 2021
+++ src/usr.bin/xlint/lint1/decl.c	Fri Jul 23 16:43:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.207 2021/07/15 23:54:22 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.208 2021/07/23 16:43:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.207 2021/07/15 23:54:22 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.208 2021/07/23 16:43:11 rillig Exp $");
 #endif
 
 #include 
@@ -64,7 +64,7 @@ dinfo_t	*dcs;
 
 static	type_t	*tdeferr(type_t *, tspec_t);
 static	void	settdsym(type_t *, sym_t *);
-static	void	align(int, int);
+static	void	align(u_int, u_int);
 static	sym_t	*newtag(sym_t *, scl_t, bool, bool);
 static	bool	eqargs(const type_t *, const type_t *, bool *);
 static	bool	mnoarg(const type_t *, bool *);
@@ -1154,7 +1154,7 @@ declarator_1_struct_union(sym_t *dsym)
 	type_t	*tp;
 	tspec_t	t;
 	int	sz;
-	int	o = 0;	/* Appease GCC */
+	u_int	o = 0;	/* Appease GCC */
 
 	lint_assert(dsym->s_scl == MOS || dsym->s_scl == MOU);
 
@@ -1231,9 +1231,9 @@ declarator_1_struct_union(sym_t *dsym)
  * al contains the required alignment, len the length of a bit-field.
  */
 static void
-align(int al, int len)
+align(u_int al, u_int len)
 {
-	int	no;
+	u_int no;
 
 	/*
 	 * The alignment of the current element becomes the alignment of

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.115 src/usr.bin/xlint/lint1/lint1.h:1.116
--- src/usr.bin/xlint/lint1/lint1.h:1.115	Thu Jul 15 18:13:25 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Fri Jul 23 16:43:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.115 2021/07/15 18:13:25 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.116 2021/07/23 16:43:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -360,8 +360,8 @@ typedef	struct dinfo {
 	type_t	*d_type;	/* after end_type() pointer to the type used
    for all declarators */
 	sym_t	*d_redeclared_symbol;
-	int	d_offset;	/* offset of next structure member */
-	int	d_sou_align_in_bits; /* alignment required for current
+	u_int	d_offset;	/* offset of next structure member */
+	u_int	d_sou_align_in_bits; /* alignment required for current
  * structure */
 	scl_t	d_ctx;		/* context of declaration */
 	bool	d_const : 1;	/* const in declaration specifiers */



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

2021-07-23 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 23 15:36:57 UTC 2021

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

Log Message:
lint: write canonical form of keywords

For keywords that have a single spelling variant (such as __packed),
write this form in the source, to make it searchable.  This also avoids
a few calls to malloc.

Previously, some keywords had leading underscores and some hadn't, this
was inconsistent.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 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.55 src/usr.bin/xlint/lint1/lex.c:1.56
--- src/usr.bin/xlint/lint1/lex.c:1.55	Sun Jul 11 19:24:41 2021
+++ src/usr.bin/xlint/lint1/lex.c	Fri Jul 23 15:36:56 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.55 2021/07/11 19:24:41 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.56 2021/07/23 15:36:56 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.55 2021/07/11 19:24:41 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.56 2021/07/23 15:36:56 rillig Exp $");
 #endif
 
 #include 
@@ -134,34 +134,26 @@ static	struct	kwtab {
 	bool	kw_attr : 1;	/* GCC attribute, keyword */
 	u_int	kw_deco : 3;	/* 1 = name, 2 = __name, 4 = __name__ */
 } kwtab[] = {
-#ifdef INT128_SIZE
-	kwdef_type(	"__int128_t",	INT128,			0,1,0,0,1),
-	kwdef_type(	"__uint128_t",	UINT128,		0,1,0,0,1),
-#endif
-	kwdef_tqual(	"__thread",	THREAD,			0,0,1,0,1),
+	kwdef_gcc_attr(	"alias",	T_AT_ALIAS),
 	kwdef_keyword(	"_Alignas",	T_ALIGNAS),
 	kwdef_keyword(	"_Alignof",	T_ALIGNOF),
-	kwdef_type(	"_Bool",	BOOL,			0,1,0,0,1),
-	kwdef_type(	"_Complex",	COMPLEX,		0,1,0,0,1),
-	kwdef_token(	"_Generic",	T_GENERIC,		0,1,0,0,1),
-	kwdef_token(	"_Noreturn",	T_NORETURN,		0,1,0,0,1),
-	kwdef_tqual(	"_Thread_local", THREAD,		0,1,0,0,1),
-	kwdef_gcc_attr(	"alias",	T_AT_ALIAS),
 	kwdef_gcc_attr(	"aligned",	T_AT_ALIGNED),
-	kwdef_token(	"alignof",	T_ALIGNOF,		0,0,0,0,4),
+	kwdef_token(	"__alignof__",	T_ALIGNOF,		0,0,0,0,1),
 	kwdef_gcc_attr(	"alloc_size",	T_AT_ALLOC_SIZE),
 	kwdef_gcc_attr(	"always_inline",T_AT_ALWAYS_INLINE),
 	kwdef_token(	"asm",		T_ASM,			0,0,1,0,7),
 	kwdef_token(	"attribute",	T_ATTRIBUTE,		0,0,1,0,6),
 	kwdef_sclass(	"auto",		AUTO,			0,0,0,0,1),
+	kwdef_type(	"_Bool",	BOOL,			0,1,0,0,1),
 	kwdef_gcc_attr(	"bounded",	T_AT_BOUNDED),
 	kwdef_keyword(	"break",	T_BREAK),
 	kwdef_gcc_attr(	"buffer",	T_AT_BUFFER),
-	kwdef_token(	"builtin_offsetof", T_BUILTIN_OFFSETOF,	0,0,1,0,2),
+	kwdef_token(	"__builtin_offsetof", T_BUILTIN_OFFSETOF, 0,0,1,0,1),
 	kwdef_keyword(	"case",		T_CASE),
 	kwdef_type(	"char",		CHAR,			0,0,0,0,1),
 	kwdef_gcc_attr(	"cold",		T_AT_COLD),
 	kwdef_gcc_attr(	"common",	T_AT_COMMON),
+	kwdef_type(	"_Complex",	COMPLEX,		0,1,0,0,1),
 	kwdef_tqual(	"const",	CONST,			1,0,0,0,7),
 	kwdef_gcc_attr(	"constructor",	T_AT_CONSTRUCTOR),
 	kwdef_keyword(	"continue",	T_CONTINUE),
@@ -172,21 +164,25 @@ static	struct	kwtab {
 	kwdef_type(	"double",	DOUBLE,			0,0,0,0,1),
 	kwdef_keyword(	"else",		T_ELSE),
 	kwdef_keyword(	"enum",		T_ENUM),
-	kwdef_token(	"extension",	T_EXTENSION,		0,0,1,0,4),
+	kwdef_token(	"__extension__",T_EXTENSION,		0,0,1,0,1),
 	kwdef_sclass(	"extern",	EXTERN,			0,0,0,0,1),
 	kwdef_gcc_attr(	"fallthrough",	T_AT_FALLTHROUGH),
 	kwdef_type(	"float",	FLOAT,			0,0,0,0,1),
 	kwdef_keyword(	"for",		T_FOR),
 	kwdef_gcc_attr(	"format",	T_AT_FORMAT),
 	kwdef_gcc_attr(	"format_arg",	T_AT_FORMAT_ARG),
+	kwdef_token(	"_Generic",	T_GENERIC,		0,1,0,0,1),
 	kwdef_gcc_attr(	"gnu_inline",	T_AT_GNU_INLINE),
 	kwdef_gcc_attr(	"gnu_printf",	T_AT_FORMAT_GNU_PRINTF),
 	kwdef_keyword(	"goto",		T_GOTO),
 	kwdef_gcc_attr(	"hot",		T_AT_HOT),
 	kwdef_keyword(	"if",		T_IF),
-	kwdef_token(	"imag",		T_IMAG,			0,0,1,0,4),
+	kwdef_token(	"__imag__",	T_IMAG,			0,0,1,0,1),
 	kwdef_sclass(	"inline",	INLINE,			0,1,0,0,7),
 	kwdef_type(	"int",		INT,			0,0,0,0,1),
+#ifdef INT128_SIZE
+	kwdef_type(	"__int128_t",	INT128,			0,1,0,0,1),
+#endif
 	kwdef_type(	"long",		LONG,			0,0,0,0,1),
 	kwdef_gcc_attr(	"malloc",	T_AT_MALLOC),
 	kwdef_gcc_attr(	"may_alias",	T_AT_MAY_ALIAS),
@@ -197,15 +193,16 @@ static	struct	kwtab {
 	kwdef_gcc_attr(	"noinline",	T_AT_NOINLINE),
 	kwdef_gcc_attr(	"nonnull",	T_AT_NONNULL),
 	kwdef_gcc_attr(	"nonstring",	T_AT_NONSTRING),
+	kwdef_token(	"_Noreturn",	T_NORETURN,		0,1,0,0,1),
 	kwdef_gcc_attr(	"noreturn",	T_AT_NORETURN),
 	kwdef_gcc_attr(	"nothrow",	T_AT_NOTHROW),
 	kwdef_gcc_attr(	"optimize",	T_AT_OPTIMIZE),
 	kwdef_gcc_attr(	"packed",	T_AT_PACKED),
-	kwdef_token(	"packed",	T_PACKED,		0,0,0,0,2),
+	kwdef_token(	"__packed",	T_PACKED,		0,0,0,0,1),
 	kwdef_gcc_attr(	"pcs",		T_AT_PCS),
 	kwdef_gcc_attr(	"printf",	T_AT_FORMAT_PRINTF),
 	kwdef_gcc_attr(	

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

2021-07-23 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul 23 15:14:49 UTC 2021

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

Log Message:
lint: move single semicolon to external_declaration

This aligns more closely with the grammar from GCC's parser.  The global
cleanup from the grammar rule 'external_declaration:
top_level_declaration' is not performed anymore, which doesn't matter
since there is nothing to clean up after a single semicolon.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.334 -r1.335 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.334 src/usr.bin/xlint/lint1/cgram.y:1.335
--- src/usr.bin/xlint/lint1/cgram.y:1.334	Wed Jul 21 21:24:45 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Jul 23 15:14:49 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.334 2021/07/21 21:24:45 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.335 2021/07/23 15:14:49 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.334 2021/07/21 21:24:45 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.335 2021/07/23 15:14:49 rillig Exp $");
 #endif
 
 #include 
@@ -1870,8 +1870,7 @@ translation_unit:		/* C99 6.9 */
 	;
 
 external_declaration:		/* C99 6.9 */
-	  asm_statement
-	| function_definition {
+	  function_definition {
 		global_clean_up_decl(false);
 		clear_warning_flags();
 	  }
@@ -1879,6 +1878,16 @@ external_declaration:		/* C99 6.9 */
 		global_clean_up_decl(false);
 		clear_warning_flags();
 	  }
+	| asm_statement		/* GCC extension */
+	| T_SEMI {		/* GCC extension */
+		if (sflag) {
+			/* empty declaration */
+			error(0);
+		} else if (!tflag) {
+			/* empty declaration */
+			warning(0);
+		}
+	  }
 	;
 
 /*
@@ -1891,16 +1900,7 @@ external_declaration:		/* C99 6.9 */
  * See 'declaration' for all other declarations.
  */
 top_level_declaration:		/* C99 6.9 calls this 'declaration' */
-	  T_SEMI {
-		if (sflag) {
-			/* empty declaration */
-			error(0);
-		} else if (!tflag) {
-			/* empty declaration */
-			warning(0);
-		}
-	  }
-	| begin_type end_type notype_init_declarators T_SEMI {
+	  begin_type end_type notype_init_declarators T_SEMI {
 		if (sflag) {
 			/* old style declaration; add 'int' */
 			error(1);



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

2021-07-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 21 21:24:45 UTC 2021

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

Log Message:
lint: move assignments to $$ at the end of the action

They are closely related to return statements.

While here, add some more remarks from reviewing the grammar.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 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.333 src/usr.bin/xlint/lint1/cgram.y:1.334
--- src/usr.bin/xlint/lint1/cgram.y:1.333	Wed Jul 21 21:17:57 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Wed Jul 21 21:24:45 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.333 2021/07/21 21:17:57 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.334 2021/07/21 21:24:45 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.333 2021/07/21 21:17:57 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.334 2021/07/21 21:24:45 rillig Exp $");
 #endif
 
 #include 
@@ -375,12 +375,12 @@ identifier_sym:			/* helper for struct/u
 /* K ???, C90 ???, C99 6.4.2.1, C11 ??? */
 identifier:
 	  T_NAME {
+		cgram_debug("name '%s'", $1->sb_name);
 		$$ = $1;
-		cgram_debug("name '%s'", $$->sb_name);
 	  }
 	| T_TYPENAME {
+		cgram_debug("typename '%s'", $1->sb_name);
 		$$ = $1;
-		cgram_debug("typename '%s'", $$->sb_name);
 	  }
 	;
 
@@ -543,9 +543,9 @@ gcc_statement_expr_item:
 			/* XXX: do that only on the last name */
 			if ($1->tn_op == NAME)
 $1->tn_sym->s_used = true;
-			$$ = $1;
 			expr($1, false, false, false, false);
 			seen_fallthrough = false;
+			$$ = $1;
 		}
 	  }
 	;
@@ -615,6 +615,7 @@ unary_expression:
 	  }
 	/* K ---, C90 ---, C99 ---, C11 6.5.3 */
 	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
+		/* TODO: c11ism */
 		$$ = build_alignof($3);
 	  }
 	;
@@ -736,6 +737,7 @@ declaration:			/* C99 6.7 */
 		}
 	  }
 	| begin_type_declmods end_type notype_init_declarators T_SEMI
+	/* ^^ There is no check for the missing type-specifier. */
 	| begin_type_declaration_specifiers end_type T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
@@ -777,6 +779,7 @@ begin_type_specifier_qualifier_list:	/* 
 	  begin_type_typespec {
 		add_type($1);
 	  }
+	  /* TODO: shift/reduce conflict for type_attribute */
 	| type_attribute begin_type_specifier_qualifier_list
 	| begin_type_qualifier_list type_specifier {
 		add_type($2);
@@ -834,6 +837,7 @@ type_attribute:			/* See C11 6.7 declara
 	  } gcc_attribute_spec_list {
 	attron = false;
 	  } T_RPAREN T_RPAREN
+	  /* TODO: c11ism */
 	| T_ALIGNAS T_LPAREN align_as T_RPAREN
 	| T_PACKED {
 		addpacked();
@@ -949,6 +953,7 @@ struct_declaration_list:	/* C99 6.7.2.1 
 
 struct_declaration:		/* C99 6.7.2.1 */
 	  begin_type_qualifier_list end_type {
+		/* ^^ There is no check for the missing type-specifier. */
 		/* too late, i know, but getsym() compensates it */
 		symtyp = FMEMBER;
 	  } notype_struct_declarators type_attribute_opt T_SEMI {
@@ -1475,12 +1480,14 @@ parameter_type_list:
 /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
 parameter_declaration:
 	  begin_type_declmods end_type {
+		/* ^^ There is no check for the missing type-specifier. */
 		$$ = declare_argument(abstract_name(), false);
 	  }
 	| begin_type_declaration_specifiers end_type {
 		$$ = declare_argument(abstract_name(), false);
 	  }
 	| begin_type_declmods end_type notype_param_declarator {
+		/* ^^ There is no check for the missing type-specifier. */
 		$$ = declare_argument($3, false);
 	  }
 	/*
@@ -1494,6 +1501,7 @@ parameter_declaration:
 		$$ = declare_argument($3, false);
 	  }
 	| begin_type_declmods end_type abstract_declarator {
+		/* ^^ There is no check for the missing type-specifier. */
 		$$ = declare_argument($3, false);
 	  }
 	| begin_type_declaration_specifiers end_type abstract_declarator {
@@ -1509,6 +1517,7 @@ initializer:			/* C99 6.7.8 "Initializat
 		/* XXX: Empty braces are not covered by C99 6.7.8. */
 	  }
 	| init_lbrace initializer_list comma_opt init_rbrace
+	  /* XXX: What is this error handling for? */
 	| error
 	;
 
@@ -1940,9 +1949,11 @@ function_definition:		/* C99 6.9.1 */
 
 func_declarator:
 	  begin_type end_type notype_declarator {
+		/* ^^ There is no check for the missing type-specifier. */
 		$$ = $3;
 	  }
 	| begin_type_declmods end_type notype_declarator {
+		/* ^^ There is no check for the missing type-specifier. */
 		$$ = $3;
 	  }
 	| begin_type_declaration_specifiers end_type type_declarator {



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

2021-07-21 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 21 21:11:19 UTC 2021

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

Log Message:
lint: remove unnecessary assertion for type qualifier

If there is any new type qualifier that lint should support (such as
_Atomic from C11), the obvious place is to look in the grammar rule
type_qualifier, so there is no need to have an assertion.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.331 -r1.332 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.331 src/usr.bin/xlint/lint1/cgram.y:1.332
--- src/usr.bin/xlint/lint1/cgram.y:1.331	Wed Jul 21 21:04:00 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Wed Jul 21 21:11:19 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.331 2021/07/21 21:04:00 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.332 2021/07/21 21:11:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.331 2021/07/21 21:04:00 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.332 2021/07/21 21:11:19 rillig Exp $");
 #endif
 
 #include 
@@ -1109,13 +1109,10 @@ enumerator:			/* C99 6.7.2.2 */
 type_qualifier:			/* C99 6.7.3 */
 	  T_QUAL {
 		$$ = xcalloc(1, sizeof(*$$));
-		if ($1 == CONST) {
+		if ($1 == CONST)
 			$$->p_const = true;
-		} else if ($1 == VOLATILE) {
+		if ($1 == VOLATILE)
 			$$->p_volatile = true;
-		} else {
-			lint_assert($1 == RESTRICT || $1 == THREAD);
-		}
 	  }
 	;
 



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

2021-07-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Jul 20 19:44:36 UTC 2021

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

Log Message:
lint: use consistent naming scheme for functions that build nodes

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.329 -r1.330 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.119 -r1.120 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.202 -r1.203 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.317 -r1.318 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.329 src/usr.bin/xlint/lint1/cgram.y:1.330
--- src/usr.bin/xlint/lint1/cgram.y:1.329	Tue Jul 20 19:35:53 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Jul 20 19:44:36 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.329 2021/07/20 19:35:53 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.330 2021/07/20 19:44:36 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.329 2021/07/20 19:35:53 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.330 2021/07/20 19:44:36 rillig Exp $");
 #endif
 
 #include 
@@ -412,13 +412,13 @@ primary_expression:
 		/* XXX really necessary? */
 		if (yychar < 0)
 			yychar = yylex();
-		$$ = new_name_node(getsym($1), yychar);
+		$$ = build_name(getsym($1), yychar);
 	  }
 	| T_CON {
-		$$ = expr_new_constant(gettyp($1->v_tspec), $1);
+		$$ = build_constant(gettyp($1->v_tspec), $1);
 	  }
 	| string {
-		$$ = new_string_node($1);
+		$$ = build_string($1);
 	  }
 	| T_LPAREN expression T_RPAREN {
 		if ($2 != NULL)
@@ -473,10 +473,10 @@ postfix_expression:
 		$$ = build_unary(INDIR, build_binary($1, PLUS, $3));
 	  }
 	| postfix_expression T_LPAREN T_RPAREN {
-		$$ = new_function_call_node($1, NULL);
+		$$ = build_function_call($1, NULL);
 	  }
 	| postfix_expression T_LPAREN argument_expression_list T_RPAREN {
-		$$ = new_function_call_node($1, $3);
+		$$ = build_function_call($1, $3);
 	  }
 	| postfix_expression point_or_arrow T_NAME {
 		$$ = build_member_access($1, $2, $3);
@@ -492,7 +492,7 @@ postfix_expression:
 		if (!Sflag)
 			 /* compound literals are a C9X/GCC extension */
 			 gnuism(319);
-		$$ = new_name_node(*current_initsym(), 0);
+		$$ = build_name(*current_initsym(), 0);
 		end_initialization();
 	  }
 	| T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
@@ -504,7 +504,7 @@ postfix_expression:
 		/* ({ }) is a GCC extension */
 		gnuism(320);
 	  } compound_statement_rbrace T_RPAREN {
-		$$ = new_name_node(*current_initsym(), 0);
+		$$ = build_name(*current_initsym(), 0);
 		end_initialization();
 	  }
 	;
@@ -564,10 +564,10 @@ point_or_arrow:			/* helper for 'postfix
 /* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
 argument_expression_list:
 	  assignment_expression {
-		$$ = new_function_argument_node(NULL, $1);
+		$$ = build_function_argument(NULL, $1);
 	  }
 	| argument_expression_list T_COMMA assignment_expression {
-		$$ = new_function_argument_node($1, $3);
+		$$ = build_function_argument($1, $3);
 	  }
 	;
 

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.119 src/usr.bin/xlint/lint1/externs1.h:1.120
--- src/usr.bin/xlint/lint1/externs1.h:1.119	Tue Jul 20 19:35:53 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Tue Jul 20 19:44:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.119 2021/07/20 19:35:53 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.120 2021/07/20 19:44:36 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -204,9 +204,9 @@ extern	int	to_int_constant(tnode_t *, bo
 extern	const tnode_t *before_conversion(const tnode_t *);
 extern	type_t	*derive_type(type_t *, tspec_t);
 extern	type_t	*expr_derive_type(type_t *, tspec_t);
-extern	tnode_t	*expr_new_constant(type_t *, val_t *);
-extern	tnode_t	*new_name_node(sym_t *, int);
-extern	tnode_t	*new_string_node(strg_t *);
+extern	tnode_t	*build_constant(type_t *, val_t *);
+extern	tnode_t	*build_name(sym_t *, int);
+extern	tnode_t	*build_string(strg_t *);
 extern	sym_t	*struct_or_union_member(tnode_t *, op_t, sym_t *);
 extern	tnode_t	*build_generic_selection(const tnode_t *,
 		struct generic_association *);
@@ -224,8 +224,8 @@ extern	tnode_t	*build_sizeof(const type_
 extern	tnode_t	*build_offsetof(const type_t *, const sym_t *);
 extern	tnode_t	*build_alignof(const type_t *);
 extern	tnode_t	*cast(tnode_t *, type_t *);
-extern	tnode_t	*new_function_argument_node(tnode_t *, tnode_t *);
-extern	tnode_t	*new_function_call_node(tnode_t *, tnode_t *);
+extern	tnode_t	*build_function_argument(tnode_t *, tnode_t *);
+extern	tnode_t	*build_function_call(tnode_t *, tnode_t *);
 extern	val_t	*constant(tnode_t *, bool);
 extern	void	expr(tnode_t *, bool, bool, bool, 

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

2021-07-20 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Jul 20 19:35:53 UTC 2021

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

Log Message:
lint: split 'build' into build_binary and build_unary

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.328 -r1.329 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.118 -r1.119 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.316 -r1.317 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.328 src/usr.bin/xlint/lint1/cgram.y:1.329
--- src/usr.bin/xlint/lint1/cgram.y:1.328	Thu Jul 15 20:05:49 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Jul 20 19:35:53 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.328 2021/07/15 20:05:49 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.329 2021/07/20 19:35:53 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.328 2021/07/15 20:05:49 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.329 2021/07/20 19:35:53 rillig Exp $");
 #endif
 
 #include 
@@ -470,7 +470,7 @@ generic_association:
 postfix_expression:
 	  primary_expression
 	| postfix_expression T_LBRACK expression T_RBRACK {
-		$$ = build(INDIR, build(PLUS, $1, $3), NULL);
+		$$ = build_unary(INDIR, build_binary($1, PLUS, $3));
 	  }
 	| postfix_expression T_LPAREN T_RPAREN {
 		$$ = new_function_call_node($1, NULL);
@@ -482,7 +482,7 @@ postfix_expression:
 		$$ = build_member_access($1, $2, $3);
 	  }
 	| postfix_expression T_INCDEC {
-		$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
+		$$ = build_unary($2 == INC ? INCAFT : DECAFT, $1);
 	  }
 	| T_LPAREN type_name T_RPAREN {	/* C99 6.5.2.5 "Compound literals" */
 		sym_t *tmp = mktempsym($2);
@@ -575,32 +575,32 @@ argument_expression_list:
 unary_expression:
 	  postfix_expression
 	| T_INCDEC unary_expression {
-		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
+		$$ = build_unary($1 == INC ? INCBEF : DECBEF, $2);
 	  }
 	| T_AMPER cast_expression {
-		$$ = build(ADDR, $2, NULL);
+		$$ = build_unary(ADDR, $2);
 	  }
 	| T_ASTERISK cast_expression {
-		$$ = build(INDIR, $2, NULL);
+		$$ = build_unary(INDIR, $2);
 	  }
 	| T_ADDITIVE cast_expression {
 		if (tflag && $1 == PLUS) {
 			/* unary + is illegal in traditional C */
 			warning(100);
 		}
-		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
+		$$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2);
 	  }
 	| T_COMPLEMENT cast_expression {
-		$$ = build(COMPL, $2, NULL);
+		$$ = build_unary(COMPL, $2);
 	  }
 	| T_LOGNOT cast_expression {
-		$$ = build(NOT, $2, NULL);
+		$$ = build_unary(NOT, $2);
 	  }
 	| T_REAL cast_expression {	/* GCC c_parser_unary_expression */
-		$$ = build(REAL, $2, NULL);
+		$$ = build_unary(REAL, $2);
 	  }
 	| T_IMAG cast_expression {	/* GCC c_parser_unary_expression */
-		$$ = build(IMAG, $2, NULL);
+		$$ = build_unary(IMAG, $2);
 	  }
 	| T_EXTENSION cast_expression {	/* GCC c_parser_unary_expression */
 		$$ = $2;
@@ -649,41 +649,41 @@ expression_opt:
 /* K ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15 */
 conditional_expression:
 	  conditional_expression T_ASTERISK conditional_expression {
-		$$ = build(MULT, $1, $3);
+		$$ = build_binary($1, MULT, $3);
 	  }
 	| conditional_expression T_MULTIPLICATIVE conditional_expression {
-		$$ = build($2, $1, $3);
+		$$ = build_binary($1, $2, $3);
 	  }
 	| conditional_expression T_ADDITIVE conditional_expression {
-		$$ = build($2, $1, $3);
+		$$ = build_binary($1, $2, $3);
 	  }
 	| conditional_expression T_SHIFT conditional_expression {
-		$$ = build($2, $1, $3);
+		$$ = build_binary($1, $2, $3);
 	  }
 	| conditional_expression T_RELATIONAL conditional_expression {
-		$$ = build($2, $1, $3);
+		$$ = build_binary($1, $2, $3);
 	  }
 	| conditional_expression T_EQUALITY conditional_expression {
-		$$ = build($2, $1, $3);
+		$$ = build_binary($1, $2, $3);
 	  }
 	| conditional_expression T_AMPER conditional_expression {
-		$$ = build(BITAND, $1, $3);
+		$$ = build_binary($1, BITAND, $3);
 	  }
 	| conditional_expression T_BITXOR conditional_expression {
-		$$ = build(BITXOR, $1, $3);
+		$$ = build_binary($1, BITXOR, $3);
 	  }
 	| conditional_expression T_BITOR conditional_expression {
-		$$ = build(BITOR, $1, $3);
+		$$ = build_binary($1, BITOR, $3);
 	  }
 	| conditional_expression T_LOGAND conditional_expression {
-		$$ = build(LOGAND, $1, $3);
+		$$ = build_binary($1, LOGAND, $3);
 	  }
 	| conditional_expression T_LOGOR conditional_expression {
-		$$ = build(LOGOR, $1, $3);
+		$$ = build_binary($1, LOGOR, $3);
 	  }
 	| conditional_expression T_QUEST 

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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 23:54:22 UTC 2021

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

Log Message:
lint: reduce verboseness of merge_signedness

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 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.206 src/usr.bin/xlint/lint1/decl.c:1.207
--- src/usr.bin/xlint/lint1/decl.c:1.206	Thu Jul 15 23:47:00 2021
+++ src/usr.bin/xlint/lint1/decl.c	Thu Jul 15 23:54:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.206 2021/07/15 23:47:00 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.207 2021/07/15 23:54:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.206 2021/07/15 23:47:00 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.207 2021/07/15 23:54:22 rillig Exp $");
 #endif
 
 #include 
@@ -386,20 +386,16 @@ static tspec_t
 merge_signedness(tspec_t t, tspec_t s)
 {
 
-	if (s != SIGNED && s != UNSIGN)
+	if (s == SIGNED)
+		return t == CHAR ? SCHAR : t;
+	if (s != UNSIGN)
 		return t;
-
-	if (t == CHAR)
-		return s == SIGNED ? SCHAR : UCHAR;
-	if (t == SHORT)
-		return s == SIGNED ? SHORT : USHORT;
-	if (t == INT)
-		return s == SIGNED ? INT : UINT;
-	if (t == LONG)
-		return s == SIGNED ? LONG : ULONG;
-	if (t == QUAD)
-		return s == SIGNED ? QUAD : UQUAD;
-	return t;
+	return t == CHAR ? UCHAR
+	: t == SHORT ? USHORT
+	: t == INT ? UINT
+	: t == LONG ? ULONG
+	: t == QUAD ? UQUAD
+	: t;
 }
 
 /*



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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 23:47:00 UTC 2021

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

Log Message:
lint: rename merge_type_specifiers to merge_signedness

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.205 -r1.206 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.205 src/usr.bin/xlint/lint1/decl.c:1.206
--- src/usr.bin/xlint/lint1/decl.c:1.205	Thu Jul 15 23:42:49 2021
+++ src/usr.bin/xlint/lint1/decl.c	Thu Jul 15 23:47:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.205 2021/07/15 23:42:49 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.206 2021/07/15 23:47:00 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.205 2021/07/15 23:42:49 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.206 2021/07/15 23:47:00 rillig Exp $");
 #endif
 
 #include 
@@ -64,7 +64,6 @@ dinfo_t	*dcs;
 
 static	type_t	*tdeferr(type_t *, tspec_t);
 static	void	settdsym(type_t *, sym_t *);
-static	tspec_t	merge_type_specifiers(tspec_t, tspec_t);
 static	void	align(int, int);
 static	sym_t	*newtag(sym_t *, scl_t, bool, bool);
 static	bool	eqargs(const type_t *, const type_t *, bool *);
@@ -382,6 +381,27 @@ add_type(type_t *tp)
 	}
 }
 
+/* Merge the signedness into the abstract type. */
+static tspec_t
+merge_signedness(tspec_t t, tspec_t s)
+{
+
+	if (s != SIGNED && s != UNSIGN)
+		return t;
+
+	if (t == CHAR)
+		return s == SIGNED ? SCHAR : UCHAR;
+	if (t == SHORT)
+		return s == SIGNED ? SHORT : USHORT;
+	if (t == INT)
+		return s == SIGNED ? INT : UINT;
+	if (t == LONG)
+		return s == SIGNED ? LONG : ULONG;
+	if (t == QUAD)
+		return s == SIGNED ? QUAD : UQUAD;
+	return t;
+}
+
 /*
  * called if a list of declaration specifiers contains a typedef name
  * and other specifiers (except struct, union, enum, typedef name)
@@ -401,7 +421,7 @@ tdeferr(type_t *td, tspec_t t)
 			if (!tflag)
 /* modifying typedef with '%s'; only ... */
 warning(5, ttab[t].tt_name);
-			td = dup_type(gettyp(merge_type_specifiers(t2, t)));
+			td = dup_type(gettyp(merge_signedness(t2, t)));
 			td->t_typedef = true;
 			return td;
 		}
@@ -814,7 +834,7 @@ dcs_merge_declaration_specifiers(void)
 	}
 	if (l != NOTSPEC)
 		t = l;
-	dcs->d_type = gettyp(merge_type_specifiers(t, s));
+	dcs->d_type = gettyp(merge_signedness(t, s));
 }
 
 /*
@@ -859,29 +879,6 @@ end_type(void)
 }
 
 /*
- * Merge type specifiers (char, ..., long long, signed, unsigned).
- */
-static tspec_t
-merge_type_specifiers(tspec_t t, tspec_t s)
-{
-
-	if (s != SIGNED && s != UNSIGN)
-		return t;
-
-	if (t == CHAR)
-		return s == SIGNED ? SCHAR : UCHAR;
-	if (t == SHORT)
-		return s == SIGNED ? SHORT : USHORT;
-	if (t == INT)
-		return s == SIGNED ? INT : UINT;
-	if (t == LONG)
-		return s == SIGNED ? LONG : ULONG;
-	if (t == QUAD)
-		return s == SIGNED ? QUAD : UQUAD;
-	return t;
-}
-
-/*
  * Return the length of a type in bits.
  *
  * Printing a message if the outermost dimension of an array is 0 must



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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 23:42:50 UTC 2021

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

Log Message:
lint: replace switch statement in dcs_merge_declaration_specifiers

Grouping the rules by their abstract type took a lot of visual space.
Instead, move each of the rules from C11 6.7.2 into its own if
statement, so that the rules almost read like in the standard.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.204 -r1.205 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.204 src/usr.bin/xlint/lint1/decl.c:1.205
--- src/usr.bin/xlint/lint1/decl.c:1.204	Thu Jul 15 23:07:05 2021
+++ src/usr.bin/xlint/lint1/decl.c	Thu Jul 15 23:42:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.204 2021/07/15 23:07:05 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.205 2021/07/15 23:42:49 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.204 2021/07/15 23:07:05 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.205 2021/07/15 23:42:49 rillig Exp $");
 #endif
 
 #include 
@@ -746,7 +746,11 @@ dcs_adjust_storage_class(void)
 	}
 }
 
-/* Merge the declaration specifiers from dcs into dcs->d_type. */
+/*
+ * Merge the declaration specifiers from dcs into dcs->d_type.
+ *
+ * See C99 6.7.2 "Type specifiers".
+ */
 static void
 dcs_merge_declaration_specifiers(void)
 {
@@ -776,55 +780,34 @@ dcs_merge_declaration_specifiers(void)
 		return;
 	}
 
-	switch (t) {
-	case BOOL:
-		break;
-	case NOTSPEC:
+	if (t == NOTSPEC)
 		t = INT;
-		/* FALLTHROUGH */
-	case INT:
-		if (s == NOTSPEC)
-			s = SIGNED;
-		break;
-	case CHAR:
-		if (l != NOTSPEC) {
-			dcs->d_terr = true;
-			l = NOTSPEC;
-		}
-		break;
-	case FLOAT:
-		if (l == LONG) {
-			l = NOTSPEC;
-			t = DOUBLE;
-			if (!tflag)
-/* use 'double' instead of 'long float' */
-warning(6);
-		}
-		break;
-	case DOUBLE:
-		if (l != LONG)
-			break;
-		/* FALLTHROUGH */
-	case LDOUBLE:
+	if (s == NOTSPEC && t == INT)
+		s = SIGNED;
+	if (l != NOTSPEC && t == CHAR) {
+		dcs->d_terr = true;
+		l = NOTSPEC;
+	}
+	if (l == LONG && t == FLOAT) {
+		l = NOTSPEC;
+		t = DOUBLE;
+		if (!tflag)
+			/* use 'double' instead of 'long float' */
+			warning(6);
+	}
+	if ((l == LONG && t == DOUBLE) || t == LDOUBLE) {
 		l = NOTSPEC;
 		t = LDOUBLE;
-		if (tflag)
-			/* 'long double' is illegal in traditional C */
-			warning(266);
-		break;
-	case DCOMPLEX:
-		if (l == LONG) {
-			l = NOTSPEC;
-			t = LCOMPLEX;
-		}
-		break;
-	case VOID:
-	case FCOMPLEX:
-	case LCOMPLEX:
-		break;
-	default:
-		lint_assert(is_integer(t));
 	}
+	if (t == LDOUBLE && tflag) {
+		/* 'long double' is illegal in traditional C */
+		warning(266);
+	}
+	if (l == LONG && t == DCOMPLEX) {
+		l = NOTSPEC;
+		t = LCOMPLEX;
+	}
+
 	if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) {
 		dcs->d_terr = true;
 		l = s = NOTSPEC;



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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 22:47:17 UTC 2021

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

Log Message:
lint: clean up mix of 'case' and 'if'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 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.202 src/usr.bin/xlint/lint1/decl.c:1.203
--- src/usr.bin/xlint/lint1/decl.c:1.202	Thu Jul 15 22:42:46 2021
+++ src/usr.bin/xlint/lint1/decl.c	Thu Jul 15 22:47:17 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.202 2021/07/15 22:42:46 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.203 2021/07/15 22:47:17 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.202 2021/07/15 22:42:46 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.203 2021/07/15 22:47:17 rillig Exp $");
 #endif
 
 #include 
@@ -807,14 +807,15 @@ end_type(void)
 			}
 			break;
 		case DOUBLE:
-			if (l == LONG) {
+			if (l != LONG)
+break;
+			/* FALLTHROUGH */
 		case LDOUBLE:
-l = NOTSPEC;
-t = LDOUBLE;
-if (tflag)
-	/* 'long double' is illegal in ... */
-	warning(266);
-			}
+			l = NOTSPEC;
+			t = LDOUBLE;
+			if (tflag)
+/* 'long double' is illegal in ... */
+warning(266);
 			break;
 		case DCOMPLEX:
 			if (l == LONG) {



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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 22:42:46 UTC 2021

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

Log Message:
lint: remove warning about _Complex long double in traditional C

Complex types have been introduced in C99, so there is no danger of
anyone trying to use them in traditional C.


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 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.201 src/usr.bin/xlint/lint1/decl.c:1.202
--- src/usr.bin/xlint/lint1/decl.c:1.201	Thu Jul 15 21:56:51 2021
+++ src/usr.bin/xlint/lint1/decl.c	Thu Jul 15 22:42:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.201 2021/07/15 21:56:51 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.202 2021/07/15 22:42:46 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.201 2021/07/15 21:56:51 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.202 2021/07/15 22:42:46 rillig Exp $");
 #endif
 
 #include 
@@ -820,9 +820,6 @@ end_type(void)
 			if (l == LONG) {
 l = NOTSPEC;
 t = LCOMPLEX;
-if (tflag)
-	/* 'long double' is illegal in ... */
-	warning(266);
 			}
 			break;
 		case VOID:



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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 18:18:15 UTC 2021

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

Log Message:
lint: merge duplicate code in declarations

No functional change, code coverage outside cgram.y stays the same.


To generate a diff of this commit:
cvs rdiff -u -r1.326 -r1.327 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.326 src/usr.bin/xlint/lint1/cgram.y:1.327
--- src/usr.bin/xlint/lint1/cgram.y:1.326	Thu Jul 15 18:13:25 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Jul 15 18:18:15 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.327 2021/07/15 18:18:15 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.327 2021/07/15 18:18:15 rillig Exp $");
 #endif
 
 #include 
@@ -1912,27 +1912,7 @@ top_level_declaration:		/* C99 6.9 calls
 			warning(1);
 		}
 	  }
-	| begin_type_declmods end_type T_SEMI {
-		if (dcs->d_scl == TYPEDEF) {
-			/* typedef declares no type name */
-			warning(72);
-		} else {
-			/* empty declaration */
-			warning(2);
-		}
-	  }
-	| begin_type_declmods end_type notype_init_declarators T_SEMI
-	| begin_type_declaration_specifiers end_type T_SEMI {
-		if (dcs->d_scl == TYPEDEF) {
-			/* typedef declares no type name */
-			warning(72);
-		} else if (!dcs->d_nonempty_decl) {
-			/* empty declaration */
-			warning(2);
-		}
-	  }
-	| begin_type_declaration_specifiers end_type
-	type_init_declarators T_SEMI
+	| declaration
 	| error T_SEMI {
 		global_clean_up();
 	  }



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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 18:13:25 UTC 2021

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

Log Message:
lint: rename grammar rule 'declaration' to 'declaration_or_error'

This prepares for merging the duplicate code from top_level_declaration.
The code coverage outside cgram.y is exactly the same as before.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.325 -r1.326 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.114 -r1.115 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.325 src/usr.bin/xlint/lint1/cgram.y:1.326
--- src/usr.bin/xlint/lint1/cgram.y:1.325	Thu Jul 15 17:20:57 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Jul 15 18:13:25 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.325 2021/07/15 17:20:57 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.325 2021/07/15 17:20:57 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.326 2021/07/15 18:13:25 rillig Exp $");
 #endif
 
 #include 
@@ -181,7 +181,7 @@ anonymize(sym_t *s)
 
 /*
  * predefined type keywords (char, int, short, long, unsigned, signed,
- * float, double, void); see T_TYPENAME
+ * float, double, void); see T_TYPENAME for types from typedef
  */
 %token		T_TYPE
 
@@ -527,7 +527,7 @@ gcc_statement_expr_list:
 	;
 
 gcc_statement_expr_item:
-	  declaration {
+	  declaration_or_error {
 		clear_warning_flags();
 		$$ = NULL;
 	  }
@@ -720,6 +720,11 @@ constant_expr:			/* C99 6.6 */
 	  conditional_expression
 	;
 
+declaration_or_error:
+	  declaration
+	| error T_SEMI
+	;
+
 declaration:			/* C99 6.7 */
 	  begin_type_declmods end_type T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
@@ -742,7 +747,6 @@ declaration:			/* C99 6.7 */
 	  }
 	| begin_type_declaration_specifiers end_type
 	type_init_declarators T_SEMI
-	| error T_SEMI
 	;
 
 begin_type_declaration_specifiers:	/* see C99 6.7 */
@@ -1672,7 +1676,7 @@ block_item_list:		/* C99 6.8.2 */
 	;
 
 block_item:			/* C99 6.8.2 */
-	  declaration {
+	  declaration_or_error {
 		$$ = false;
 		restore_warning_flags();
 	  }

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.114 src/usr.bin/xlint/lint1/lint1.h:1.115
--- src/usr.bin/xlint/lint1/lint1.h:1.114	Sat Jul 10 17:35:54 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Thu Jul 15 18:13:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.114 2021/07/10 17:35:54 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.115 2021/07/15 18:13:25 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -209,11 +209,11 @@ typedef	enum {
 } symt_t;
 
 /*
- * storage classes
+ * storage classes and related things
  */
 typedef enum {
 	NOSCL,
-	EXTERN,		/* external symbols (indep. of decl_t) */
+	EXTERN,		/* external symbols (independent of decl_t) */
 	STATIC,		/* static symbols (local and global) */
 	AUTO,		/* automatic symbols (except register) */
 	REG,		/* register */



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

2021-07-15 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul 15 17:03:50 UTC 2021

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

Log Message:
lint: replace call to ttos with type_name

Since tyname.c 1.20 from 2021-01-02, type_name is as simple to use as
ttos and more expressive.  It can also be called multiple times without
invalidating the returned strings.

Used only in debug mode.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.117 -r1.118 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.314 -r1.315 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/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.45 src/usr.bin/xlint/lint1/emit1.c:1.46
--- src/usr.bin/xlint/lint1/emit1.c:1.45	Mon Jul  5 19:39:12 2021
+++ src/usr.bin/xlint/lint1/emit1.c	Thu Jul 15 17:03:50 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.45 2021/07/05 19:39:12 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.46 2021/07/15 17:03:50 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit1.c,v 1.45 2021/07/05 19:39:12 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.46 2021/07/15 17:03:50 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -158,35 +158,6 @@ outtype(const type_t *tp)
 }
 
 /*
- * type to string
- * used for debugging output
- *
- * it uses its own output buffer for conversion
- */
-const char *
-ttos(const type_t *tp)
-{
-	static	ob_t	tob;
-	ob_t	tmp;
-
-	if (tob.o_buf == NULL) {
-		tob.o_len = 64;
-		tob.o_buf = tob.o_next = xmalloc(tob.o_len);
-		tob.o_end = tob.o_buf + tob.o_len;
-	}
-
-	tmp = ob;
-	ob = tob;
-	ob.o_next = ob.o_buf;
-	outtype(tp);
-	outchar('\0');
-	tob = ob;
-	ob = tmp;
-
-	return tob.o_buf;
-}
-
-/*
  * write the name of a tag or typename
  *
  * if the tag is named, the name of the tag is written,

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.117 src/usr.bin/xlint/lint1/externs1.h:1.118
--- src/usr.bin/xlint/lint1/externs1.h:1.117	Wed Jul 14 17:07:24 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Thu Jul 15 17:03:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.117 2021/07/14 17:07:24 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.118 2021/07/15 17:03:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -314,7 +314,6 @@ extern	void	add_designator_subscript(ran
  * emit.c
  */
 extern	void	outtype(const type_t *);
-extern	const	char *ttos(const type_t *);
 extern	void	outsym(const sym_t *, scl_t, def_t);
 extern	void	outfdef(const sym_t *, const pos_t *, bool, bool,
 		const sym_t *);

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.314 src/usr.bin/xlint/lint1/tree.c:1.315
--- src/usr.bin/xlint/lint1/tree.c:1.314	Wed Jul 14 17:07:24 2021
+++ src/usr.bin/xlint/lint1/tree.c	Thu Jul 15 17:03:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.314 2021/07/14 17:07:24 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.315 2021/07/15 17:03:50 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.314 2021/07/14 17:07:24 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.315 2021/07/15 17:03:50 rillig Exp $");
 #endif
 
 #include 
@@ -3815,7 +3815,7 @@ display_expression(const tnode_t *tn, in
 		(void)printf("o=%d, l=%d ", tn->tn_type->t_foffs,
 			 tn->tn_type->t_flen);
 	}
-	(void)printf("%s\n", ttos(tn->tn_type));
+	(void)printf("%s\n", type_name(tn->tn_type));
 	if (tn->tn_op == NAME || tn->tn_op == CON || tn->tn_op == STRING)
 		return;
 	display_expression(tn->tn_left, offs + 2);



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

2021-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Jul 15 07:58:05 UTC 2021

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

Log Message:
PR port-sh3/56311

As a workaround for GCC bug, compile initdecl() with -O0 for sh3.


To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.200 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.199 src/usr.bin/xlint/lint1/decl.c:1.200
--- src/usr.bin/xlint/lint1/decl.c:1.199	Tue Jul 13 22:01:34 2021
+++ src/usr.bin/xlint/lint1/decl.c	Thu Jul 15 07:58:05 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.199 2021/07/13 22:01:34 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.200 2021/07/15 07:58:05 rin Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.199 2021/07/13 22:01:34 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.200 2021/07/15 07:58:05 rin Exp $");
 #endif
 
 #include 
@@ -86,6 +86,10 @@ static	void	check_global_variable_size(c
  * initializes all global vars used in declarations
  */
 void
+#ifdef __sh3__
+/* XXX port-sh3/56311 */
+__attribute__((optimize("O0")))
+#endif
 initdecl(void)
 {
 	int i;



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

2021-07-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 14 17:19:37 UTC 2021

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

Log Message:
lint: in the grammar, rename 'decl' to 'declarator'

For a casual reader, the abbreviation 'decl' was ambiguous since C has
both declarations and declarators.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.323 -r1.324 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.323 src/usr.bin/xlint/lint1/cgram.y:1.324
--- src/usr.bin/xlint/lint1/cgram.y:1.323	Wed Jul 14 17:07:24 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Wed Jul 14 17:19:37 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.323 2021/07/14 17:07:24 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.324 2021/07/14 17:19:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.323 2021/07/14 17:07:24 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.324 2021/07/14 17:19:37 rillig Exp $");
 #endif
 
 #include 
@@ -309,10 +309,10 @@ anonymize(sym_t *s)
 %type			struct_declaration_list_with_rbrace
 %type			struct_declaration_list
 %type			struct_declaration
-%type			notype_member_decls
-%type			type_member_decls
-%type			notype_member_decl
-%type			type_member_decl
+%type			notype_struct_declarators
+%type			type_struct_declarators
+%type			notype_struct_declarator
+%type			type_struct_declarator
 %type		enum_specifier
 %type			enum_declaration
 %type			enums_with_opt_comma
@@ -323,14 +323,14 @@ anonymize(sym_t *s)
 %type		asterisk
 %type		type_qualifier_list_opt
 %type		type_qualifier_list
-%type			notype_decl
-%type			type_decl
-%type			notype_direct_decl
-%type			type_direct_decl
-%type			type_param_decl
-%type			notype_param_decl
-%type			direct_param_decl
-%type			direct_notype_param_decl
+%type			notype_declarator
+%type			type_declarator
+%type			notype_direct_declarator
+%type			type_direct_declarator
+%type			type_param_declarator
+%type			notype_param_declarator
+%type			direct_param_declarator
+%type			direct_notype_param_declarator
 %type			param_list
 %type		array_size
 %type			identifier_list
@@ -348,7 +348,7 @@ anonymize(sym_t *s)
 %type	 block_item_list
 %type	 block_item
 %type		do_while_expr
-%type			func_decl
+%type			func_declarator
 
 %%
 
@@ -726,7 +726,7 @@ declaration:			/* C99 6.7 */
 			warning(2);
 		}
 	  }
-	| begin_type_declmods end_type notype_init_decls T_SEMI
+	| begin_type_declmods end_type notype_init_declarators T_SEMI
 	| begin_type_declaration_specifiers end_type T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
@@ -736,7 +736,8 @@ declaration:			/* C99 6.7 */
 			warning(2);
 		}
 	  }
-	| begin_type_declaration_specifiers end_type type_init_decls T_SEMI
+	| begin_type_declaration_specifiers end_type
+	type_init_declarators T_SEMI
 	| error T_SEMI
 	;
 
@@ -951,13 +952,13 @@ struct_declaration:		/* C99 6.7.2.1 */
 	  begin_type_noclass_declmods end_type {
 		/* too late, i know, but getsym() compensates it */
 		symtyp = FMEMBER;
-	  } notype_member_decls type_attribute_opt {
+	  } notype_struct_declarators type_attribute_opt {
 		symtyp = FVFT;
 		$$ = $4;
 	  }
 	| begin_type_noclass_declspecs end_type {
 		symtyp = FMEMBER;
-	  } type_member_decls type_attribute_opt {
+	  } type_struct_declarators type_attribute_opt {
 		symtyp = FVFT;
 		$$ = $4;
 	  }
@@ -987,32 +988,31 @@ struct_declaration:		/* C99 6.7.2.1 */
 	  }
 	;
 
-/* TODO: rename 'decls' to 'declarators', everywhere. */
-notype_member_decls:
-	  notype_member_decl {
+notype_struct_declarators:
+	  notype_struct_declarator {
 		$$ = declarator_1_struct_union($1);
 	  }
-	| notype_member_decls {
+	| notype_struct_declarators {
 		symtyp = FMEMBER;
-	  } T_COMMA type_member_decl {
+	  } T_COMMA type_struct_declarator {
 		$$ = lnklst($1, declarator_1_struct_union($4));
 	  }
 	;
 
-type_member_decls:
-	  type_member_decl {
+type_struct_declarators:
+	  type_struct_declarator {
 		$$ = declarator_1_struct_union($1);
 	  }
-	| type_member_decls {
+	| type_struct_declarators {
 		symtyp = FMEMBER;
-	  } T_COMMA type_member_decl {
+	  } T_COMMA type_struct_declarator {
 		$$ = lnklst($1, declarator_1_struct_union($4));
 	  }
 	;
 
-notype_member_decl:
-	  notype_decl
-	| notype_decl T_COLON constant_expr {		/* C99 6.7.2.1 */
+notype_struct_declarator:
+	  notype_declarator
+	| notype_declarator T_COLON constant_expr {		/* C99 6.7.2.1 */
 		$$ = bitfield($1, to_int_constant($3, true));
 	  }
 	| {
@@ -1022,9 +1022,9 @@ notype_member_decl:
 	  }
 	;
 
-type_member_decl:
-	  type_decl
-	| type_decl T_COLON constant_expr {
+type_struct_declarator:
+	  type_declarator
+	| type_declarator T_COLON constant_expr {
 		$$ = 

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

2021-07-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 14 17:07:24 UTC 2021

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

Log Message:
lint: extract build_member_access from the grammar

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.322 -r1.323 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.313 -r1.314 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.322 src/usr.bin/xlint/lint1/cgram.y:1.323
--- src/usr.bin/xlint/lint1/cgram.y:1.322	Wed Jul 14 16:59:39 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Wed Jul 14 17:07:24 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.322 2021/07/14 16:59:39 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.323 2021/07/14 17:07:24 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.322 2021/07/14 16:59:39 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.323 2021/07/14 17:07:24 rillig Exp $");
 #endif
 
 #include 
@@ -478,24 +478,7 @@ postfix_expression:
 		$$ = new_function_call_node($1, $3);
 	  }
 	| postfix_expression point_or_arrow T_NAME {
-		if ($1 != NULL) {
-			sym_t	*msym;
-			/*
-			 * XXX struct_or_union_member should be integrated
-			 * in build()
-			 */
-			if ($2 == ARROW) {
-/*
- * must do this before struct_or_union_member
- * is called
- */
-$1 = cconv($1);
-			}
-			msym = struct_or_union_member($1, $2, getsym($3));
-			$$ = build($2, $1, new_name_node(msym, 0));
-		} else {
-			$$ = NULL;
-		}
+		$$ = build_member_access($1, $2, $3);
 	  }
 	| postfix_expression T_INCDEC {
 		$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.116 src/usr.bin/xlint/lint1/externs1.h:1.117
--- src/usr.bin/xlint/lint1/externs1.h:1.116	Sat Jul 10 17:35:54 2021
+++ src/usr.bin/xlint/lint1/externs1.h	Wed Jul 14 17:07:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.116 2021/07/10 17:35:54 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.117 2021/07/14 17:07:24 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -212,6 +212,7 @@ extern	tnode_t	*build_generic_selection(
 		struct generic_association *);
 
 extern	tnode_t	*build(op_t, tnode_t *, tnode_t *);
+extern	tnode_t	*build_member_access(tnode_t *, op_t, sbuf_t *);
 extern	tnode_t	*cconv(tnode_t *);
 extern	bool	is_typeok_bool_operand(const tnode_t *);
 extern	bool	typeok(op_t, int, const tnode_t *, const tnode_t *);

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.313 src/usr.bin/xlint/lint1/tree.c:1.314
--- src/usr.bin/xlint/lint1/tree.c:1.313	Tue Jul  6 04:44:20 2021
+++ src/usr.bin/xlint/lint1/tree.c	Wed Jul 14 17:07:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.313 2021/07/06 04:44:20 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.314 2021/07/14 17:07:24 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.313 2021/07/06 04:44:20 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.314 2021/07/14 17:07:24 rillig Exp $");
 #endif
 
 #include 
@@ -687,6 +687,22 @@ build(op_t op, tnode_t *ln, tnode_t *rn)
 	return ntn;
 }
 
+tnode_t *
+build_member_access(tnode_t *ln, op_t op, sbuf_t *member)
+{
+	sym_t	*msym;
+
+	if (ln == NULL)
+		return NULL;
+
+	if (op == ARROW) {
+		/* must do this before struct_or_union_member is called */
+		ln = cconv(ln);
+	}
+	msym = struct_or_union_member(ln, op, getsym(member));
+	return build(op, ln, new_name_node(msym, 0));
+}
+
 /*
  * Perform class conversions.
  *



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

2021-07-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 14 16:59:39 UTC 2021

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

Log Message:
lint: rename grammar rule 'expr' to 'expression'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.321 -r1.322 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.321 src/usr.bin/xlint/lint1/cgram.y:1.322
--- src/usr.bin/xlint/lint1/cgram.y:1.321	Wed Jul 14 16:51:57 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Wed Jul 14 16:59:39 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.321 2021/07/14 16:51:57 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.322 2021/07/14 16:59:39 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.321 2021/07/14 16:51:57 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.322 2021/07/14 16:59:39 rillig Exp $");
 #endif
 
 #include 
@@ -295,8 +295,8 @@ anonymize(sym_t *s)
 %type		argument_expression_list
 %type		unary_expression
 %type		cast_expression
-%type		expr_opt
-%type		expr
+%type		expression_opt
+%type		expression
 %type		assignment_expression
 %type		constant_expr
 
@@ -419,7 +419,7 @@ primary_expression:
 	| string {
 		$$ = new_string_node($1);
 	  }
-	| T_LPAREN expr T_RPAREN {
+	| T_LPAREN expression T_RPAREN {
 		if ($2 != NULL)
 			$2->tn_parenthesized = true;
 		$$ = $2;
@@ -468,7 +468,7 @@ generic_association:
 /* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
 postfix_expression:
 	  primary_expression
-	| postfix_expression T_LBRACK expr T_RBRACK {
+	| postfix_expression T_LBRACK expression T_RBRACK {
 		$$ = build(INDIR, build(PLUS, $1, $3), NULL);
 	  }
 	| postfix_expression T_LPAREN T_RPAREN {
@@ -551,7 +551,7 @@ gcc_statement_expr_item:
 		$$ = expr_zalloc_tnode();
 		$$->tn_type = gettyp(VOID);
 	  }
-	| expr T_SEMI {
+	| expression T_SEMI {
 		if ($1 == NULL) {	/* in case of syntax errors */
 			$$ = expr_zalloc_tnode();
 			$$->tn_type = gettyp(VOID);
@@ -579,10 +579,10 @@ point_or_arrow:			/* helper for 'postfix
 
 /* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
 argument_expression_list:
-	  expr %prec T_COMMA {
+	  expression %prec T_COMMA {
 		$$ = new_function_argument_node(NULL, $1);
 	  }
-	| argument_expression_list T_COMMA expr {
+	| argument_expression_list T_COMMA expression {
 		$$ = new_function_argument_node($1, $3);
 	  }
 	;
@@ -645,11 +645,11 @@ cast_expression:
 	  }
 	;
 
-expr_opt:
+expression_opt:
 	  /* empty */ {
 		$$ = NULL;
 	  }
-	| expr
+	| expression
 	;
 
 /* 'expression' also implements 'multiplicative_expression'. */
@@ -664,52 +664,51 @@ expr_opt:
 /* 'expression' also implements 'logical_OR_expression'. */
 /* 'expression' also implements 'conditional_expression'. */
 /* 'expression' also implements 'assignment_expression'. */
-/* TODO: rename to 'expression' */
 /* K ???, C90 ???, C99 6.5.5 to 6.5.17, C11 ??? */
-expr:
-	  expr T_ASTERISK expr {
+expression:
+	  expression T_ASTERISK expression {
 		$$ = build(MULT, $1, $3);
 	  }
-	| expr T_MULTIPLICATIVE expr {
+	| expression T_MULTIPLICATIVE expression {
 		$$ = build($2, $1, $3);
 	  }
-	| expr T_ADDITIVE expr {
+	| expression T_ADDITIVE expression {
 		$$ = build($2, $1, $3);
 	  }
-	| expr T_SHIFT expr {
+	| expression T_SHIFT expression {
 		$$ = build($2, $1, $3);
 	  }
-	| expr T_RELATIONAL expr {
+	| expression T_RELATIONAL expression {
 		$$ = build($2, $1, $3);
 	  }
-	| expr T_EQUALITY expr {
+	| expression T_EQUALITY expression {
 		$$ = build($2, $1, $3);
 	  }
-	| expr T_AMPER expr {
+	| expression T_AMPER expression {
 		$$ = build(BITAND, $1, $3);
 	  }
-	| expr T_BITXOR expr {
+	| expression T_BITXOR expression {
 		$$ = build(BITXOR, $1, $3);
 	  }
-	| expr T_BITOR expr {
+	| expression T_BITOR expression {
 		$$ = build(BITOR, $1, $3);
 	  }
-	| expr T_LOGAND expr {
+	| expression T_LOGAND expression {
 		$$ = build(LOGAND, $1, $3);
 	  }
-	| expr T_LOGOR expr {
+	| expression T_LOGOR expression {
 		$$ = build(LOGOR, $1, $3);
 	  }
-	| expr T_QUEST expr T_COLON expr {
+	| expression T_QUEST expression T_COLON expression {
 		$$ = build(QUEST, $1, build(COLON, $3, $5));
 	  }
-	| expr T_ASSIGN expr {
+	| expression T_ASSIGN expression {
 		$$ = build(ASSIGN, $1, $3);
 	  }
-	| expr T_OPASSIGN expr {
+	| expression T_OPASSIGN expression {
 		$$ = build($2, $1, $3);
 	  }
-	| expr T_COMMA expr {
+	| expression T_COMMA expression {
 		$$ = build(COMMA, $1, $3);
 	  }
 	| cast_expression
@@ -717,7 +716,7 @@ expr:
 
 /* K ???, C90 ???, C99 6.5.16, C11 ??? */
 assignment_expression:
-	  expr %prec T_ASSIGN
+	  expression %prec T_ASSIGN
 	;
 
 constant_expr_list_opt:		/* helper for gcc_attribute */
@@ -731,7 +730,7 @@ constant_expr_list:		/* helper for gcc_a
 	;
 
 

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

2021-07-14 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Wed Jul 14 16:51:57 UTC 2021

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

Log Message:
lint: remove references to C18

The standard is called C17, not C18, and furthermore the section
numbering didn't change between C11 and C17.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.320 -r1.321 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.320 src/usr.bin/xlint/lint1/cgram.y:1.321
--- src/usr.bin/xlint/lint1/cgram.y:1.320	Mon Jul 12 22:02:44 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Wed Jul 14 16:51:57 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.320 2021/07/12 22:02:44 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.321 2021/07/14 16:51:57 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.320 2021/07/12 22:02:44 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.321 2021/07/14 16:51:57 rillig Exp $");
 #endif
 
 #include 
@@ -371,7 +371,7 @@ identifier_sym:			/* helper for struct/u
 	  }
 	;
 
-/* K ???, C90 ???, C99 6.4.2.1, C11 ???, C18 ??? */
+/* K ???, C90 ???, C99 6.4.2.1, C11 ??? */
 identifier:
 	  T_NAME {
 		$$ = $1;
@@ -405,7 +405,7 @@ string2:
 	  }
 	;
 
-/* K 7.1, C90 ???, C99 6.5.1, C11 6.5.1, C18 6.5.1 */
+/* K 7.1, C90 ???, C99 6.5.1, C11 6.5.1 */
 primary_expression:
 	  T_NAME {
 		/* XXX really necessary? */
@@ -432,7 +432,7 @@ primary_expression:
 	  }
 	;
 
-/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1 */
 generic_selection:
 	  T_GENERIC T_LPAREN assignment_expression T_COMMA
 	generic_assoc_list T_RPAREN {
@@ -442,7 +442,7 @@ generic_selection:
 	  }
 	;
 
-/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1 */
 generic_assoc_list:
 	  generic_association
 	| generic_assoc_list T_COMMA generic_association {
@@ -451,7 +451,7 @@ generic_assoc_list:
 	  }
 	;
 
-/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1 */
 generic_association:
 	  type_name T_COLON assignment_expression {
 		$$ = getblk(sizeof(*$$));
@@ -465,7 +465,7 @@ generic_association:
 	  }
 	;
 
-/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C18 6.5.2 */
+/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
 postfix_expression:
 	  primary_expression
 	| postfix_expression T_LBRACK expr T_RBRACK {
@@ -577,7 +577,7 @@ point_or_arrow:			/* helper for 'postfix
 	  }
 	;
 
-/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C18 6.5.2 */
+/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
 argument_expression_list:
 	  expr %prec T_COMMA {
 		$$ = new_function_argument_node(NULL, $1);
@@ -587,7 +587,7 @@ argument_expression_list:
 	  }
 	;
 
-/* K 7.2, C90 ???, C99 6.5.3, C11 6.5.3, C18 6.5.3 */
+/* K 7.2, C90 ???, C99 6.5.3, C11 6.5.3 */
 unary_expression:
 	  postfix_expression
 	| T_INCDEC unary_expression {
@@ -629,7 +629,7 @@ unary_expression:
 	| T_SIZEOF T_LPAREN type_name T_RPAREN {
 		$$ = build_sizeof($3);
 	  }
-	/* K ---, C90 ---, C99 ---, C11 6.5.3, C18 6.5.3 */
+	/* K ---, C90 ---, C99 ---, C11 6.5.3 */
 	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
 		$$ = build_alignof($3);
 	  }
@@ -637,7 +637,7 @@ unary_expression:
 
 /* The rule 'unary_operator' is inlined into unary_expression. */
 
-/* K 7.2, C90 ???, C99 6.5.4, C11 6.5.4, C18 6.5.4 */
+/* K 7.2, C90 ???, C99 6.5.4, C11 6.5.4 */
 cast_expression:
 	  unary_expression
 	| T_LPAREN type_name T_RPAREN cast_expression {
@@ -665,7 +665,7 @@ expr_opt:
 /* 'expression' also implements 'conditional_expression'. */
 /* 'expression' also implements 'assignment_expression'. */
 /* TODO: rename to 'expression' */
-/* K ???, C90 ???, C99 6.5.5 to 6.5.17, C11 ???, C18 ??? */
+/* K ???, C90 ???, C99 6.5.5 to 6.5.17, C11 ??? */
 expr:
 	  expr T_ASTERISK expr {
 		$$ = build(MULT, $1, $3);
@@ -715,7 +715,7 @@ expr:
 	| cast_expression
 	;
 
-/* K ???, C90 ???, C99 6.5.16, C11 ???, C18 ??? */
+/* K ???, C90 ???, C99 6.5.16, C11 ??? */
 assignment_expression:
 	  expr %prec T_ASSIGN
 	;



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

2021-07-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul 12 22:02:44 UTC 2021

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

Log Message:
lint: order type declarations in grammar, group by C99 section

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.319 -r1.320 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.319 src/usr.bin/xlint/lint1/cgram.y:1.320
--- src/usr.bin/xlint/lint1/cgram.y:1.319	Mon Jul 12 21:43:44 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Mon Jul 12 22:02:44 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.319 2021/07/12 21:43:44 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.320 2021/07/12 22:02:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.319 2021/07/12 21:43:44 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.320 2021/07/12 22:02:44 rillig Exp $");
 #endif
 
 #include 
@@ -279,25 +279,33 @@ anonymize(sym_t *s)
 %token			T_CON
 %token		T_STRING
 
+%type			identifier_sym
+%type		identifier
+%type		string
+%type		string2
+
 %type		primary_expression
+%type		generic_selection
+%type		generic_assoc_list
+%type		generic_association
 %type		postfix_expression
+%type		gcc_statement_expr_list
+%type		gcc_statement_expr_item
+%type			point_or_arrow
 %type		argument_expression_list
 %type		unary_expression
 %type		cast_expression
+%type		expr_opt
 %type		expr
+%type		assignment_expression
+%type		constant_expr
 
-%type			func_decl
-%type			notype_decl
-%type			type_decl
-%type		type_specifier
 %type		begin_type_typespec
+%type		type_specifier
 %type		notype_type_specifier
 %type		struct_or_union_specifier
-%type		enum_specifier
 %type		struct_or_union
 %type			braced_struct_declaration_list
-%type			identifier_sym
-%type		identifier
 %type			struct_declaration_list_with_rbrace
 %type			struct_declaration_list
 %type			struct_declaration
@@ -305,48 +313,42 @@ anonymize(sym_t *s)
 %type			type_member_decls
 %type			notype_member_decl
 %type			type_member_decl
-%type		constant_expr
-%type		array_size
+%type		enum_specifier
 %type			enum_declaration
 %type			enums_with_opt_comma
 %type			enumerator_list
 %type			enumerator
-%type			notype_direct_decl
-%type			type_direct_decl
+%type		type_qualifier
 %type		pointer
 %type		asterisk
+%type		type_qualifier_list_opt
+%type		type_qualifier_list
+%type			notype_decl
+%type			type_decl
+%type			notype_direct_decl
+%type			type_direct_decl
 %type			type_param_decl
-%type			param_list
-%type			abstract_decl_param_list
-%type			direct_param_decl
 %type			notype_param_decl
+%type			direct_param_decl
 %type			direct_notype_param_decl
-%type		type_qualifier_list_opt
-%type		type_qualifier_list
-%type		type_qualifier
+%type			param_list
+%type		array_size
 %type			identifier_list
+%type		type_name
+%type			abstract_declaration
 %type			abstract_declarator
 %type			direct_abstract_declarator
+%type			abstract_decl_param_list
 %type			vararg_parameter_type_list
 %type			parameter_type_list
 %type			parameter_declaration
-%type		assignment_expression
-%type		gcc_statement_expr_list
-%type		gcc_statement_expr_item
-%type		generic_selection
-%type			point_or_arrow
-%type		type_name
-%type			abstract_declaration
-%type		do_while_expr
-%type		expr_opt
-%type		string
-%type		string2
-%type		asm_or_symbolrename_opt
 %type		range
+%type		asm_or_symbolrename_opt
+
 %type	 block_item_list
 %type	 block_item
-%type		generic_assoc_list
-%type		generic_association
+%type		do_while_expr
+%type			func_decl
 
 %%
 



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

2021-07-12 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Jul 12 21:43:44 UTC 2021

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

Log Message:
lint: reorder grammar rules in the same way as in C99

The code coverage before and after this change is exactly the same,
except of course for cgram.y and cgram.c.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.318 -r1.319 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.318 src/usr.bin/xlint/lint1/cgram.y:1.319
--- src/usr.bin/xlint/lint1/cgram.y:1.318	Sun Jul 11 21:07:44 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Mon Jul 12 21:43:44 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.318 2021/07/11 21:07:44 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.319 2021/07/12 21:43:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.318 2021/07/11 21:07:44 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.319 2021/07/12 21:43:44 rillig Exp $");
 #endif
 
 #include 
@@ -363,159 +363,373 @@ program:
 	| translation_unit
 	;
 
-translation_unit:		/* C99 6.9 */
-	  external_declaration
-	| translation_unit external_declaration
+identifier_sym:			/* helper for struct/union/enum */
+	  identifier {
+		$$ = getsym($1);
+	  }
 	;
 
-external_declaration:		/* C99 6.9 */
-	  asm_statement
-	| function_definition {
-		global_clean_up_decl(false);
-		clear_warning_flags();
+/* K ???, C90 ???, C99 6.4.2.1, C11 ???, C18 ??? */
+identifier:
+	  T_NAME {
+		$$ = $1;
+		cgram_debug("name '%s'", $$->sb_name);
 	  }
-	| top_level_declaration {
-		global_clean_up_decl(false);
-		clear_warning_flags();
+	| T_TYPENAME {
+		$$ = $1;
+		cgram_debug("typename '%s'", $$->sb_name);
+	  }
+	;
+
+/* see C99 6.4.5, string literals are joined by 5.1.1.2 */
+string:
+	  T_STRING
+	| T_STRING string2 {
+		$$ = cat_strings($1, $2);
+	  }
+	;
+
+/* see C99 6.4.5, string literals are joined by 5.1.1.2 */
+string2:
+	  T_STRING {
+		if (tflag) {
+			/* concatenated strings are illegal in traditional C */
+			warning(219);
+		}
+		$$ = $1;
+	  }
+	| string2 T_STRING {
+		$$ = cat_strings($1, $2);
+	  }
+	;
+
+/* K 7.1, C90 ???, C99 6.5.1, C11 6.5.1, C18 6.5.1 */
+primary_expression:
+	  T_NAME {
+		/* XXX really necessary? */
+		if (yychar < 0)
+			yychar = yylex();
+		$$ = new_name_node(getsym($1), yychar);
+	  }
+	| T_CON {
+		$$ = expr_new_constant(gettyp($1->v_tspec), $1);
+	  }
+	| string {
+		$$ = new_string_node($1);
+	  }
+	| T_LPAREN expr T_RPAREN {
+		if ($2 != NULL)
+			$2->tn_parenthesized = true;
+		$$ = $2;
+	  }
+	| generic_selection
+	/* GCC primary-expression, see c_parser_postfix_expression */
+	| T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
+		symtyp = FMEMBER;
+		$$ = build_offsetof($3, getsym($5));
+	  }
+	;
+
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_selection:
+	  T_GENERIC T_LPAREN assignment_expression T_COMMA
+	generic_assoc_list T_RPAREN {
+	  	/* generic selection requires C11 or later */
+	  	c11ism(345);
+		$$ = build_generic_selection($3, $5);
+	  }
+	;
+
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_assoc_list:
+	  generic_association
+	| generic_assoc_list T_COMMA generic_association {
+		$3->ga_prev = $1;
+		$$ = $3;
+	  }
+	;
+
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_association:
+	  type_name T_COLON assignment_expression {
+		$$ = getblk(sizeof(*$$));
+		$$->ga_arg = $1;
+		$$->ga_result = $3;
+	  }
+	| T_DEFAULT T_COLON assignment_expression {
+		$$ = getblk(sizeof(*$$));
+		$$->ga_arg = NULL;
+		$$->ga_result = $3;
+	  }
+	;
+
+/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C18 6.5.2 */
+postfix_expression:
+	  primary_expression
+	| postfix_expression T_LBRACK expr T_RBRACK {
+		$$ = build(INDIR, build(PLUS, $1, $3), NULL);
+	  }
+	| postfix_expression T_LPAREN T_RPAREN {
+		$$ = new_function_call_node($1, NULL);
+	  }
+	| postfix_expression T_LPAREN argument_expression_list T_RPAREN {
+		$$ = new_function_call_node($1, $3);
+	  }
+	| postfix_expression point_or_arrow T_NAME {
+		if ($1 != NULL) {
+			sym_t	*msym;
+			/*
+			 * XXX struct_or_union_member should be integrated
+			 * in build()
+			 */
+			if ($2 == ARROW) {
+/*
+ * must do this before struct_or_union_member
+ * is called
+ */
+$1 = cconv($1);
+			}
+			msym = struct_or_union_member($1, $2, getsym($3));
+			$$ = build($2, $1, new_name_node(msym, 0));
+		} else {
+			$$ = NULL;
+		}
+	  }
+	| postfix_expression T_INCDEC {
+		$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
+	  }
+	| T_LPAREN type_name T_RPAREN {	/* C99 6.5.2.5 "Compound literals" */
+		sym_t *tmp = mktempsym($2);
+		begin_initialization(tmp);
+		

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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 21:07:44 UTC 2021

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

Log Message:
lint: reorder grammar rules for expressions according to C18

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.317 -r1.318 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.317 src/usr.bin/xlint/lint1/cgram.y:1.318
--- src/usr.bin/xlint/lint1/cgram.y:1.317	Sun Jul 11 20:37:21 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 21:07:44 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.317 2021/07/11 20:37:21 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.318 2021/07/11 21:07:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.317 2021/07/11 20:37:21 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.318 2021/07/11 21:07:44 rillig Exp $");
 #endif
 
 #include 
@@ -1728,7 +1728,8 @@ assignment_expression:		/* C99 6.5.16 */
 	  expr %prec T_ASSIGN
 	;
 
-primary_expression:		/* C99 6.5.1 */
+/* K 7.1, C90 ???, C99 6.5.1, C11 6.5.1, C18 6.5.1 */
+primary_expression:
 	  T_NAME {
 		/* XXX really necessary? */
 		if (yychar < 0)
@@ -1754,7 +1755,41 @@ primary_expression:		/* C99 6.5.1 */
 	  }
 	;
 
-postfix_expression:		/* C99 6.5.2 */
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_selection:
+	  T_GENERIC T_LPAREN assignment_expression T_COMMA
+	generic_assoc_list T_RPAREN {
+	  	/* generic selection requires C11 or later */
+	  	c11ism(345);
+		$$ = build_generic_selection($3, $5);
+	  }
+	;
+
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_assoc_list:
+	  generic_association
+	| generic_assoc_list T_COMMA generic_association {
+		$3->ga_prev = $1;
+		$$ = $3;
+	  }
+	;
+
+/* K ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_association:
+	  type_name T_COLON assignment_expression {
+		$$ = getblk(sizeof(*$$));
+		$$->ga_arg = $1;
+		$$->ga_result = $3;
+	  }
+	| T_DEFAULT T_COLON assignment_expression {
+		$$ = getblk(sizeof(*$$));
+		$$->ga_arg = NULL;
+		$$->ga_result = $3;
+	  }
+	;
+
+/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C18 6.5.2 */
+postfix_expression:
 	  primary_expression
 	| postfix_expression T_LBRACK expr T_RBRACK {
 		$$ = build(INDIR, build(PLUS, $1, $3), NULL);
@@ -1813,7 +1848,18 @@ postfix_expression:		/* C99 6.5.2 */
 	  }
 	;
 
-unary_expression:		/* C99 6.5.3 */
+/* K 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C18 6.5.2 */
+argument_expression_list:
+	  expr %prec T_COMMA {
+		$$ = new_function_argument_node(NULL, $1);
+	  }
+	| argument_expression_list T_COMMA expr {
+		$$ = new_function_argument_node($1, $3);
+	  }
+	;
+
+/* K 7.2, C90 ???, C99 6.5.3, C11 6.5.3, C18 6.5.3 */
+unary_expression:
 	  postfix_expression
 	| T_INCDEC unary_expression {
 		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
@@ -1854,57 +1900,20 @@ unary_expression:		/* C99 6.5.3 */
 	| T_SIZEOF T_LPAREN type_name T_RPAREN {
 		$$ = build_sizeof($3);
 	  }
-	| T_ALIGNOF T_LPAREN type_name T_RPAREN {	/* C11 6.5.3 */
+	/* K ---, C90 ---, C99 ---, C11 6.5.3, C18 6.5.3 */
+	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
 		$$ = build_alignof($3);
 	  }
 	;
 
-cast_expression:		/* see C99 6.5.1 */
+/* K 7.2, C90 ???, C99 6.5.4, C11 6.5.4, C18 6.5.4 */
+cast_expression:
 	  unary_expression
 	| T_LPAREN type_name T_RPAREN cast_expression {
 		$$ = cast($4, $2);
 	  }
 	;
 
-generic_selection:		/* C11 6.5.1.1 */
-	  T_GENERIC T_LPAREN assignment_expression T_COMMA
-	generic_assoc_list T_RPAREN {
-	  	/* generic selection requires C11 or later */
-	  	c11ism(345);
-		$$ = build_generic_selection($3, $5);
-	  }
-	;
-
-generic_assoc_list:		/* C11 6.5.1.1 */
-	  generic_association
-	| generic_assoc_list T_COMMA generic_association {
-		$3->ga_prev = $1;
-		$$ = $3;
-	  }
-	;
-
-generic_association:		/* C11 6.5.1.1 */
-	  type_name T_COLON assignment_expression {
-		$$ = getblk(sizeof(*$$));
-		$$->ga_arg = $1;
-		$$->ga_result = $3;
-	  }
-	| T_DEFAULT T_COLON assignment_expression {
-		$$ = getblk(sizeof(*$$));
-		$$->ga_arg = NULL;
-		$$->ga_result = $3;
-	  }
-	;
-
-argument_expression_list:	/* C99 6.5.2 */
-	  expr %prec T_COMMA {
-		$$ = new_function_argument_node(NULL, $1);
-	  }
-	| argument_expression_list T_COMMA expr {
-		$$ = new_function_argument_node($1, $3);
-	  }
-	;
-
 /*
  * The inner part of a GCC statement-expression of the form ({ ... }).
  *



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 20:25:54 UTC 2021

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

Log Message:
lint: rename grammar rule 'term' to 'cast_expression'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.315 -r1.316 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.315 src/usr.bin/xlint/lint1/cgram.y:1.316
--- src/usr.bin/xlint/lint1/cgram.y:1.315	Sun Jul 11 20:07:41 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 20:25:54 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.315 2021/07/11 20:07:41 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.316 2021/07/11 20:25:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.315 2021/07/11 20:07:41 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.316 2021/07/11 20:25:54 rillig Exp $");
 #endif
 
 #include 
@@ -281,7 +281,10 @@ anonymize(sym_t *s)
 
 %type		primary_expression
 %type		postfix_expression
+%type		argument_expression_list
 %type		unary_expression
+%type		cast_expression
+%type		expr
 
 %type			func_decl
 %type			notype_decl
@@ -327,13 +330,10 @@ anonymize(sym_t *s)
 %type			vararg_parameter_type_list
 %type			parameter_type_list
 %type			parameter_declaration
-%type		expr
 %type		assignment_expression
 %type		gcc_statement_expr_list
 %type		gcc_statement_expr_item
-%type		term
 %type		generic_selection
-%type		argument_expression_list
 %type			point_or_arrow
 %type		type_name
 %type			abstract_declaration
@@ -631,7 +631,7 @@ notype_type_specifier:
 	  T_TYPE {
 		$$ = gettyp($1);
 	  }
-	| T_TYPEOF term {
+	| T_TYPEOF cast_expression {	/* GCC extension */
 		$$ = $2->tn_type;
 	  }
 	| struct_or_union_specifier {
@@ -1353,7 +1353,7 @@ abstract_declarator:		/* C99 6.7.6 */
 	| pointer direct_abstract_declarator {
 		$$ = add_pointer($2, $1);
 	  }
-	| T_TYPEOF term {	/* GCC extension */
+	| T_TYPEOF cast_expression {	/* GCC extension */
 		$$ = mktempsym($2->tn_type);
 	  }
 	;
@@ -1721,8 +1721,8 @@ expr:/* C99 6.5 */
 	| expr T_COMMA expr {
 		$$ = build(COMMA, $1, $3);
 	  }
-	| term
-	| generic_selection
+	| cast_expression
+	| generic_selection	/* TODO: move to primary_expression */
 	;
 
 assignment_expression:		/* C99 6.5.16 */
@@ -1818,32 +1818,32 @@ unary_expression:		/* C99 6.5.3 */
 	| T_INCDEC unary_expression {
 		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
 	  }
-	| T_AMPER term {
+	| T_AMPER cast_expression {
 		$$ = build(ADDR, $2, NULL);
 	  }
-	| T_ASTERISK term {
+	| T_ASTERISK cast_expression {
 		$$ = build(INDIR, $2, NULL);
 	  }
-	| T_ADDITIVE term {
+	| T_ADDITIVE cast_expression {
 		if (tflag && $1 == PLUS) {
 			/* unary + is illegal in traditional C */
 			warning(100);
 		}
 		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
 	  }
-	| T_COMPLEMENT term {
+	| T_COMPLEMENT cast_expression {
 		$$ = build(COMPL, $2, NULL);
 	  }
-	| T_LOGNOT term {
+	| T_LOGNOT cast_expression {
 		$$ = build(NOT, $2, NULL);
 	  }
-	| T_REAL term {		/* GCC c_parser_unary_expression */
+	| T_REAL cast_expression {	/* GCC c_parser_unary_expression */
 		$$ = build(REAL, $2, NULL);
 	  }
-	| T_IMAG term {		/* GCC c_parser_unary_expression */
+	| T_IMAG cast_expression {	/* GCC c_parser_unary_expression */
 		$$ = build(IMAG, $2, NULL);
 	  }
-	| T_EXTENSION term {	/* GCC c_parser_unary_expression */
+	| T_EXTENSION cast_expression {	/* GCC c_parser_unary_expression */
 		$$ = $2;
 	  }
 	| T_SIZEOF unary_expression {
@@ -1859,9 +1859,9 @@ unary_expression:		/* C99 6.5.3 */
 	  }
 	;
 
-term:/* see C99 6.5.1 */
+cast_expression:		/* see C99 6.5.1 */
 	  unary_expression
-	| T_LPAREN type_name T_RPAREN term {
+	| T_LPAREN type_name T_RPAREN cast_expression {
 		$$ = cast($4, $2);
 	  }
 	;



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 20:07:42 UTC 2021

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

Log Message:
lint: reorganize grammar rules for unary expressions

According to GCC, __builtin_offsetof is a primary-expression.

According to GCC, __real__, __imag__ and __extension__ are
unary-operator, just like '!' and '~'.

According to C11, _Alignof is a unary-operator.


To generate a diff of this commit:
cvs rdiff -u -r1.314 -r1.315 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.314 src/usr.bin/xlint/lint1/cgram.y:1.315
--- src/usr.bin/xlint/lint1/cgram.y:1.314	Sun Jul 11 19:46:09 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 20:07:41 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.314 2021/07/11 19:46:09 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.315 2021/07/11 20:07:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.314 2021/07/11 19:46:09 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.315 2021/07/11 20:07:41 rillig Exp $");
 #endif
 
 #include 
@@ -1747,6 +1747,11 @@ primary_expression:		/* C99 6.5.1 */
 			$2->tn_parenthesized = true;
 		$$ = $2;
 	  }
+	/* GCC primary-expression, see c_parser_postfix_expression */
+	| T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
+		symtyp = FMEMBER;
+		$$ = build_offsetof($3, getsym($5));
+	  }
 	;
 
 postfix_expression:		/* C99 6.5.2 */
@@ -1802,10 +1807,10 @@ postfix_expression:		/* C99 6.5.2 */
 		block_level++;
 		/* ({ }) is a GCC extension */
 		gnuism(320);
-	 } compound_statement_rbrace T_RPAREN {
+	  } compound_statement_rbrace T_RPAREN {
 		$$ = new_name_node(*current_initsym(), 0);
 		end_initialization();
-	 }
+	  }
 	;
 
 unary_expression:		/* C99 6.5.3 */
@@ -1832,6 +1837,15 @@ unary_expression:		/* C99 6.5.3 */
 	| T_LOGNOT term {
 		$$ = build(NOT, $2, NULL);
 	  }
+	| T_REAL term {		/* GCC c_parser_unary_expression */
+		$$ = build(REAL, $2, NULL);
+	  }
+	| T_IMAG term {		/* GCC c_parser_unary_expression */
+		$$ = build(IMAG, $2, NULL);
+	  }
+	| T_EXTENSION term {	/* GCC c_parser_unary_expression */
+		$$ = $2;
+	  }
 	| T_SIZEOF unary_expression {
 		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
 		if ($$ != NULL)
@@ -1840,26 +1854,13 @@ unary_expression:		/* C99 6.5.3 */
 	| T_SIZEOF T_LPAREN type_name T_RPAREN {
 		$$ = build_sizeof($3);
 	  }
+	| T_ALIGNOF T_LPAREN type_name T_RPAREN {	/* C11 6.5.3 */
+		$$ = build_alignof($3);
+	  }
 	;
 
 term:/* see C99 6.5.1 */
 	  unary_expression
-	| T_REAL term {
-		$$ = build(REAL, $2, NULL);
-	  }
-	| T_IMAG term {
-		$$ = build(IMAG, $2, NULL);
-	  }
-	| T_EXTENSION term {
-		$$ = $2;
-	  }
-	| T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
-		symtyp = FMEMBER;
-		$$ = build_offsetof($3, getsym($5));
-	  }
-	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
-		$$ = build_alignof($3);
-	  }
 	| T_LPAREN type_name T_RPAREN term {
 		$$ = cast($4, $2);
 	  }



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 19:46:09 UTC 2021

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

Log Message:
lint: remove grammar conflict for __real__ and __imag__

The rules were redundant since a term can be parenthesized by itself,
there is no need for an extra rule.  The rules for '__real__(term)' and
'__imag__(term)' were never reduced since these cases were handled by
the rules '__real__ term' and '__imag__ term' a few lines above.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.313 -r1.314 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.313 src/usr.bin/xlint/lint1/cgram.y:1.314
--- src/usr.bin/xlint/lint1/cgram.y:1.313	Sun Jul 11 19:24:41 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 19:46:09 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.313 2021/07/11 19:24:41 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.314 2021/07/11 19:46:09 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.313 2021/07/11 19:24:41 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.314 2021/07/11 19:46:09 rillig Exp $");
 #endif
 
 #include 
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
 
 %}
 
-%expect 167
+%expect 165
 
 %union {
 	val_t	*y_val;
@@ -1853,12 +1853,6 @@ term:/* see C99 6.5.1 */
 	| T_EXTENSION term {
 		$$ = $2;
 	  }
-	| T_REAL T_LPAREN term T_RPAREN {
-		$$ = build(REAL, $3, NULL);
-	  }
-	| T_IMAG T_LPAREN term T_RPAREN {
-		$$ = build(IMAG, $3, NULL);
-	  }
 	| T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
 		symtyp = FMEMBER;
 		$$ = build_offsetof($3, getsym($5));



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 19:01:37 UTC 2021

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

Log Message:
lint: fix shift/reduce conflict for dangling else

The following line no longer occurs in the yacc output:
257: shift/reduce conflict (shift 427, reduce 270) on T_ELSE

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 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.311 src/usr.bin/xlint/lint1/cgram.y:1.312
--- src/usr.bin/xlint/lint1/cgram.y:1.311	Sun Jul 11 18:22:02 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 19:01:37 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.311 2021/07/11 18:22:02 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.312 2021/07/11 19:01:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.311 2021/07/11 18:22:02 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.312 2021/07/11 19:01:37 rillig Exp $");
 #endif
 
 #include 
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
 
 %}
 
-%expect 168
+%expect 167
 
 %union {
 	val_t	*y_val;
@@ -257,6 +257,8 @@ anonymize(sym_t *s)
 %token			T_AT_WARN_UNUSED_RESULT
 %token			T_AT_WEAK
 
+%left	T_THEN
+%left	T_ELSE
 %left	T_COMMA
 %right	T_ASSIGN T_OPASSIGN
 %right	T_QUEST T_COLON
@@ -1486,7 +1488,7 @@ expression_statement:		/* C99 6.8.3 */
 	;
 
 selection_statement:		/* C99 6.8.4 */
-	  if_without_else {
+	  if_without_else %prec T_THEN {
 		save_warning_flags();
 		if2();
 		if3(false);



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 18:22:03 UTC 2021

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

Log Message:
lint: resolve shift/reduce conflict in notype_direct_decl

When a notype_direct_decl was followed by a type_attribute_list, and the
next token was another type_attribute, the parser could either continue
the current type_attribute_list or start a new one.  Either way has the
same effect since type_attribute_list has no associated action.

This reduces the conflicts by 4, one for each of T_ALIGNAS, T_ATTRIBUTE,
T_NORETURN, T_PACKED.  There are several other conflicts involving these
4 tokens, but they are harder to fix.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 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.310 src/usr.bin/xlint/lint1/cgram.y:1.311
--- src/usr.bin/xlint/lint1/cgram.y:1.310	Sun Jul 11 18:03:47 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 18:22:02 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.311 2021/07/11 18:22:02 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.311 2021/07/11 18:22:02 rillig Exp $");
 #endif
 
 #include 
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
 
 %}
 
-%expect 172
+%expect 168
 
 %union {
 	val_t	*y_val;
@@ -979,7 +979,7 @@ notype_direct_decl:
 		end_declaration_level();
 		block_level--;
 	  }
-	| notype_direct_decl type_attribute_list
+	| notype_direct_decl type_attribute
 	;
 
 type_direct_decl:



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 18:03:47 UTC 2021

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

Log Message:
lint: use separate tokens for logical not and bitwise complement

The token T_UNARY was misleading since it only captured 2 of the 6
operators that C99 calls unary-operator.  Make the grammar easier to
understand by explicitly listing these 2 operators.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.309 -r1.310 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.134 -r1.135 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.309 src/usr.bin/xlint/lint1/cgram.y:1.310
--- src/usr.bin/xlint/lint1/cgram.y:1.309	Sun Jul 11 17:52:20 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 18:03:47 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.310 2021/07/11 18:03:47 rillig Exp $");
 #endif
 
 #include 
@@ -145,7 +145,7 @@ anonymize(sym_t *s)
 
 %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
 %token			T_POINT T_ARROW
-%token			T_UNARY
+%token			T_COMPLEMENT T_LOGNOT
 %token			T_INCDEC
 %token			T_SIZEOF
 %token			T_BUILTIN_OFFSETOF
@@ -1823,8 +1823,11 @@ unary_expression:		/* C99 6.5.3 */
 		}
 		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
 	  }
-	| T_UNARY term {
-		$$ = build($1, $2, NULL);
+	| T_COMPLEMENT term {
+		$$ = build(COMPL, $2, NULL);
+	  }
+	| T_LOGNOT term {
+		$$ = build(NOT, $2, NULL);
 	  }
 	| T_SIZEOF unary_expression {
 		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);

Index: src/usr.bin/xlint/lint1/scan.l
diff -u src/usr.bin/xlint/lint1/scan.l:1.134 src/usr.bin/xlint/lint1/scan.l:1.135
--- src/usr.bin/xlint/lint1/scan.l:1.134	Sun Jun 20 18:15:12 2021
+++ src/usr.bin/xlint/lint1/scan.l	Sun Jul 11 18:03:47 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: scan.l,v 1.134 2021/06/20 18:15:12 rillig Exp $ */
+/* $NetBSD: scan.l,v 1.135 2021/07/11 18:03:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.134 2021/06/20 18:15:12 rillig Exp $");
+__RCSID("$NetBSD: scan.l,v 1.135 2021/07/11 18:03:47 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -101,8 +101,8 @@ TL	([fFlL]?[i]?)
 "*"return T_ASTERISK;
 "/"return lex_operator(T_MULTIPLICATIVE, DIV);
 "%"return lex_operator(T_MULTIPLICATIVE, MOD);
-"!"return lex_operator(T_UNARY, NOT);
-"~"return lex_operator(T_UNARY, COMPL);
+"!"return T_LOGNOT;
+"~"return T_COMPLEMENT;
 "\""return lex_string();
 "L\""return lex_wide_string();
 ";"return T_SEMI;



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 17:52:20 UTC 2021

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

Log Message:
lint: remove redundant %prec from the grammar

Now that the precedence of the unary operators has been modeled via
separate rules, the precedence is no longer needed.

No change to the generated parser, with both yacc or Bison.


To generate a diff of this commit:
cvs rdiff -u -r1.308 -r1.309 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.308 src/usr.bin/xlint/lint1/cgram.y:1.309
--- src/usr.bin/xlint/lint1/cgram.y:1.308	Sun Jul 11 17:38:55 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 17:52:20 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $");
 #endif
 
 #include 
@@ -270,8 +270,6 @@ anonymize(sym_t *s)
 %left	T_SHIFT
 %left	T_ADDITIVE
 %left	T_ASTERISK T_MULTIPLICATIVE
-%right	T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG
-%left	T_LPAREN T_LBRACK T_POINT T_ARROW
 
 %token		T_NAME
 %token		T_TYPENAME
@@ -1833,7 +1831,7 @@ unary_expression:		/* C99 6.5.3 */
 		if ($$ != NULL)
 			check_expr_misc($2, false, false, false, false, false, true);
 	  }
-	| T_SIZEOF T_LPAREN type_name T_RPAREN %prec T_SIZEOF {
+	| T_SIZEOF T_LPAREN type_name T_RPAREN {
 		$$ = build_sizeof($3);
 	  }
 	;
@@ -1862,7 +1860,7 @@ term:/* see C99 6.5.1 */
 	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
 		$$ = build_alignof($3);
 	  }
-	| T_LPAREN type_name T_RPAREN term %prec T_UNARY {
+	| T_LPAREN type_name T_RPAREN term {
 		$$ = cast($4, $2);
 	  }
 	;



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 17:38:55 UTC 2021

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

Log Message:
lint: remove shift/reduce conflict for sizeof

According to the grammar, the expression 'sizeof(int)x' was ambiguous.
Since 'sizeof(int)' is a valid term, that could have been reduced,
which would have resulted in a parse error when trying to parse 'x'.

Now 'sizeof' takes a unary_expression instead of a term.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.307 -r1.308 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.307 src/usr.bin/xlint/lint1/cgram.y:1.308
--- src/usr.bin/xlint/lint1/cgram.y:1.307	Sun Jul 11 16:57:21 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 17:38:55 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.307 2021/07/11 16:57:21 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.307 2021/07/11 16:57:21 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $");
 #endif
 
 #include 
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
 
 %}
 
-%expect 173
+%expect 172
 
 %union {
 	val_t	*y_val;
@@ -280,6 +280,7 @@ anonymize(sym_t *s)
 
 %type		primary_expression
 %type		postfix_expression
+%type		unary_expression
 
 %type			func_decl
 %type			notype_decl
@@ -1806,19 +1807,16 @@ postfix_expression:		/* C99 6.5.2 */
 	 }
 	;
 
-term:/* see C99 6.5.1 */
+unary_expression:		/* C99 6.5.3 */
 	  postfix_expression
-	| T_INCDEC term {
+	| T_INCDEC unary_expression {
 		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
 	  }
-	| T_ASTERISK term {
-		$$ = build(INDIR, $2, NULL);
-	  }
 	| T_AMPER term {
 		$$ = build(ADDR, $2, NULL);
 	  }
-	| T_UNARY term {
-		$$ = build($1, $2, NULL);
+	| T_ASTERISK term {
+		$$ = build(INDIR, $2, NULL);
 	  }
 	| T_ADDITIVE term {
 		if (tflag && $1 == PLUS) {
@@ -1827,6 +1825,21 @@ term:/* see C99 6.5.1 */
 		}
 		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
 	  }
+	| T_UNARY term {
+		$$ = build($1, $2, NULL);
+	  }
+	| T_SIZEOF unary_expression {
+		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
+		if ($$ != NULL)
+			check_expr_misc($2, false, false, false, false, false, true);
+	  }
+	| T_SIZEOF T_LPAREN type_name T_RPAREN %prec T_SIZEOF {
+		$$ = build_sizeof($3);
+	  }
+	;
+
+term:/* see C99 6.5.1 */
+	  unary_expression
 	| T_REAL term {
 		$$ = build(REAL, $2, NULL);
 	  }
@@ -1846,14 +1859,6 @@ term:/* see C99 6.5.1 */
 		symtyp = FMEMBER;
 		$$ = build_offsetof($3, getsym($5));
 	  }
-	| T_SIZEOF term	{
-		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
-		if ($$ != NULL)
-			check_expr_misc($2, false, false, false, false, false, true);
-	  }
-	| T_SIZEOF T_LPAREN type_name T_RPAREN %prec T_SIZEOF {
-		$$ = build_sizeof($3);
-	  }
 	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
 		$$ = build_alignof($3);
 	  }



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

2021-07-11 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Jul 11 16:57:21 UTC 2021

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

Log Message:
lint: resolve shift/reduce conflicts for unary expressions

The grammar rule 'term' was ambiguous since both the prefix and postfix
increment operators were listed with the same precedence.  The
expression '++x++' was parsed as '++ (x++)', as expected, since
conflicts resolve towards shift.

Resolve these conflicts by structuring the grammar as in C99, with the
GCC extension of statement-expressions.  The resolved conflicts are:

134: shift/reduce conflict (shift 161, reduce 347) on T_LBRACK
134: shift/reduce conflict (shift 162, reduce 347) on T_LPAREN
134: shift/reduce conflict (shift 163, reduce 347) on T_POINT
134: shift/reduce conflict (shift 164, reduce 347) on T_ARROW
134: shift/reduce conflict (shift 165, reduce 347) on T_INCDEC
state 134
term : term . T_INCDEC  (335)
term : term . T_LBRACK expr T_RBRACK  (341)
term : term . T_LPAREN T_RPAREN  (342)
term : term . T_LPAREN argument_expression_list T_RPAREN  (343)
term : term . point_or_arrow T_NAME  (344)
term : T_EXTENSION term .  (347)

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.306 -r1.307 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.306 src/usr.bin/xlint/lint1/cgram.y:1.307
--- src/usr.bin/xlint/lint1/cgram.y:1.306	Sun Jul 11 15:07:39 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 16:57:21 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.306 2021/07/11 15:07:39 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.307 2021/07/11 16:57:21 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.306 2021/07/11 15:07:39 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.307 2021/07/11 16:57:21 rillig Exp $");
 #endif
 
 #include 
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
 
 %}
 
-%expect 178
+%expect 173
 
 %union {
 	val_t	*y_val;
@@ -278,6 +278,9 @@ anonymize(sym_t *s)
 %token			T_CON
 %token		T_STRING
 
+%type		primary_expression
+%type		postfix_expression
+
 %type			func_decl
 %type			notype_decl
 %type			type_decl
@@ -1724,24 +1727,71 @@ assignment_expression:		/* C99 6.5.16 */
 	  expr %prec T_ASSIGN
 	;
 
-term:/* see C99 6.5.1 */
+primary_expression:		/* C99 6.5.1 */
 	  T_NAME {
 		/* XXX really necessary? */
 		if (yychar < 0)
 			yychar = yylex();
 		$$ = new_name_node(getsym($1), yychar);
 	  }
-	| string {
-		$$ = new_string_node($1);
-	  }
 	| T_CON {
 		$$ = expr_new_constant(gettyp($1->v_tspec), $1);
 	  }
+	| string {
+		$$ = new_string_node($1);
+	  }
 	| T_LPAREN expr T_RPAREN {
 		if ($2 != NULL)
 			$2->tn_parenthesized = true;
 		$$ = $2;
 	  }
+	;
+
+postfix_expression:		/* C99 6.5.2 */
+	  primary_expression
+	| postfix_expression T_LBRACK expr T_RBRACK {
+		$$ = build(INDIR, build(PLUS, $1, $3), NULL);
+	  }
+	| postfix_expression T_LPAREN T_RPAREN {
+		$$ = new_function_call_node($1, NULL);
+	  }
+	| postfix_expression T_LPAREN argument_expression_list T_RPAREN {
+		$$ = new_function_call_node($1, $3);
+	  }
+	| postfix_expression point_or_arrow T_NAME {
+		if ($1 != NULL) {
+			sym_t	*msym;
+			/*
+			 * XXX struct_or_union_member should be integrated
+			 * in build()
+			 */
+			if ($2 == ARROW) {
+/*
+ * must do this before struct_or_union_member
+ * is called
+ */
+$1 = cconv($1);
+			}
+			msym = struct_or_union_member($1, $2, getsym($3));
+			$$ = build($2, $1, new_name_node(msym, 0));
+		} else {
+			$$ = NULL;
+		}
+	  }
+	| postfix_expression T_INCDEC {
+		$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
+	  }
+	| T_LPAREN type_name T_RPAREN {	/* C99 6.5.2.5 "Compound literals" */
+		sym_t *tmp = mktempsym($2);
+		begin_initialization(tmp);
+		cgram_declare(tmp, true, NULL);
+	  } init_lbrace initializer_list comma_opt init_rbrace {
+		if (!Sflag)
+			 /* compound literals are a C9X/GCC extension */
+			 gnuism(319);
+		$$ = new_name_node(*current_initsym(), 0);
+		end_initialization();
+	  }
 	| T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
 		block_level--;
 		mem_block_level--;
@@ -1754,9 +1804,10 @@ term:/* see C99 6.5.1 */
 		$$ = new_name_node(*current_initsym(), 0);
 		end_initialization();
 	 }
-	| term T_INCDEC {
-		$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
-	  }
+	;
+
+term:/* see C99 6.5.1 */
+	  postfix_expression
 	| T_INCDEC term {
 		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
 	  }
@@ -1776,35 +1827,6 @@ term:/* see C99 6.5.1 */
 		}
 		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
 	  }
-	| term T_LBRACK expr T_RBRACK {
-		$$ = build(INDIR, build(PLUS, $1, $3), NULL);
-	

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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 21:44:51 UTC 2021

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

Log Message:
lint: inline grammar rules declmod and qualifier_or_storage_class

The rule declmod had a confusing name since declmods was not exactly a
list of declmod.

Inlining the rules reduces the abstraction level.  There are still some
shift/reduce conflicts in that area, so make the rules as simple as
possible, in order to resolve these conflicts.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.303 -r1.304 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.303 src/usr.bin/xlint/lint1/cgram.y:1.304
--- src/usr.bin/xlint/lint1/cgram.y:1.303	Sat Jul 10 21:08:16 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 21:44:51 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.303 2021/07/10 21:08:16 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.304 2021/07/10 21:44:51 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.303 2021/07/10 21:08:16 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.304 2021/07/10 21:44:51 rillig Exp $");
 #endif
 
 #include 
@@ -535,23 +535,22 @@ declaration_specifiers:		/* C99 6.7 */
 	  add_type_specifier
 	| declmods add_type_specifier
 	| type_attribute declaration_specifiers
-	| declaration_specifiers declmod
+	| declaration_specifiers add_storage_class
 	| declaration_specifiers add_notype_type_specifier
+	| declaration_specifiers add_type_qualifier
+	| declaration_specifiers type_attribute
 	;
 
 declmods:
-	  qualifier_or_storage_class
-	| declmods declmod
+	  add_storage_class
+	| add_type_qualifier
+	| declmods add_storage_class
+	| declmods add_type_qualifier
+	| declmods type_attribute
 	;
 
-declmod:
-	  qualifier_or_storage_class
-	| type_attribute
-	;
-
-qualifier_or_storage_class:
-	  add_type_qualifier
-	| T_SCLASS {
+add_storage_class:
+	  T_SCLASS {
 		add_storage_class($1);
 	  }
 	;



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 21:08:16 UTC 2021

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

Log Message:
lint: merge duplicate code for struct and enum declarations

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 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.302 src/usr.bin/xlint/lint1/cgram.y:1.303
--- src/usr.bin/xlint/lint1/cgram.y:1.302	Sat Jul 10 20:58:35 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 21:08:16 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.302 2021/07/10 20:58:35 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.303 2021/07/10 21:08:16 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.302 2021/07/10 20:58:35 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.303 2021/07/10 21:08:16 rillig Exp $");
 #endif
 
 #include 
@@ -286,7 +286,7 @@ anonymize(sym_t *s)
 %type		struct_or_union_specifier
 %type		enum_specifier
 %type		struct_or_union
-%type			braced_struct_declaration_list
+%type			identifier_sym_opt
 %type			identifier_sym
 %type		identifier
 %type			struct_declaration_list_semi
@@ -298,7 +298,6 @@ anonymize(sym_t *s)
 %type			type_member_decl
 %type		constant_expr
 %type		array_size
-%type			enum_declaration
 %type			enumerator_list
 %type			enumerator
 %type			notype_direct_decl
@@ -629,15 +628,12 @@ struct_or_union_specifier:	/* C99 6.7.2.
 		 */
 		$$ = mktag($2, $1, false, yychar == T_SEMI);
 	  }
-	| struct_or_union identifier_sym {
+	| struct_or_union identifier_sym_opt {
 		dcs->d_tagtyp = mktag($2, $1, true, false);
-	  } braced_struct_declaration_list {
-		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
-	  }
-	| struct_or_union {
-		dcs->d_tagtyp = mktag(NULL, $1, true, false);
-	  } braced_struct_declaration_list {
-		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
+	  } T_LBRACE {
+		symtyp = FVFT;
+	  } struct_declaration_list_semi T_RBRACE {
+		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $6);
 	  }
 	| struct_or_union error {
 		symtyp = FVFT;
@@ -654,14 +650,6 @@ struct_or_union:		/* C99 6.7.2.1 */
 	  } type_attribute_list_opt
 	;
 
-braced_struct_declaration_list:
-	  T_LBRACE {
-		symtyp = FVFT;
-	  } struct_declaration_list_semi T_RBRACE {
-		$$ = $3;
-	  }
-	;
-
 struct_declaration_list_semi:
 	  /* empty */ {
 		$$ = NULL;
@@ -800,15 +788,13 @@ enum_specifier:		/* C99 6.7.2.2 */
 	  enum identifier_sym {
 		$$ = mktag($2, ENUM, false, false);
 	  }
-	| enum identifier_sym {
+	| enum identifier_sym_opt {
 		dcs->d_tagtyp = mktag($2, ENUM, true, false);
-	  } enum_declaration {
-		$$ = complete_tag_enum(dcs->d_tagtyp, $4);
-	  }
-	| enum {
-		dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
-	  } enum_declaration {
-		$$ = complete_tag_enum(dcs->d_tagtyp, $3);
+	  } T_LBRACE {
+		symtyp = FVFT;
+		enumval = 0;
+	  } enumerator_list enumerator_list_comma_opt T_RBRACE {
+		$$ = complete_tag_enum(dcs->d_tagtyp, $6);
 	  }
 	| enum error {
 		symtyp = FVFT;
@@ -823,15 +809,6 @@ enum:
 	  }
 	;
 
-enum_declaration:
-	  T_LBRACE {
-		symtyp = FVFT;
-		enumval = 0;
-	  } enumerator_list enumerator_list_comma_opt T_RBRACE {
-		$$ = $3;
-	  }
-	;
-
 enumerator_list:		/* C99 6.7.2.2 */
 	  enumerator
 	| enumerator_list T_COMMA enumerator {
@@ -1901,6 +1878,13 @@ point_or_arrow:
 	  }
 	;
 
+identifier_sym_opt:
+	  /* empty */ {
+		$$ = NULL;
+	  }
+	| identifier_sym
+	;
+
 identifier_sym:
 	  identifier {
 		$$ = getsym($1);



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 20:58:35 UTC 2021

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

Log Message:
lint: move type_attribute back into the main section

Type attributes are a standard feature since C11 and thus do not belong
in the GCC-specific section.  Only the GCC __attribute__ belongs there.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.301 -r1.302 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.301 src/usr.bin/xlint/lint1/cgram.y:1.302
--- src/usr.bin/xlint/lint1/cgram.y:1.301	Sat Jul 10 20:44:23 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 20:58:35 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.301 2021/07/10 20:44:23 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.302 2021/07/10 20:58:35 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.301 2021/07/10 20:44:23 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.302 2021/07/10 20:58:35 rillig Exp $");
 #endif
 
 #include 
@@ -563,6 +563,30 @@ add_type_specifier:
 	  }
 	;
 
+type_attribute_list_opt:
+	  /* empty */
+	| type_attribute_list
+	;
+
+type_attribute_list:
+	  type_attribute
+	| type_attribute_list type_attribute
+	;
+
+type_attribute_opt:
+	  /* empty */
+	| type_attribute
+	;
+
+type_attribute:			/* See C11 6.7 declaration-specifiers */
+	  gcc_attribute
+	| T_ALIGNAS T_LPAREN align_as T_RPAREN
+	| T_PACKED {
+		addpacked();
+	  }
+	| T_NORETURN
+	;
+
 type_specifier:			/* C99 6.7.2 */
 	  notype_type_specifier
 	| T_TYPENAME {
@@ -1901,30 +1925,6 @@ comma_opt:
 
 /* GCC extensions */
 
-type_attribute_list_opt:
-	  /* empty */
-	| type_attribute_list
-	;
-
-type_attribute_list:
-	  type_attribute
-	| type_attribute_list type_attribute
-	;
-
-type_attribute_opt:
-	  /* empty */
-	| type_attribute
-	;
-
-type_attribute:
-	  gcc_attribute
-	| T_ALIGNAS T_LPAREN align_as T_RPAREN
-	| T_PACKED {
-		addpacked();
-	  }
-	| T_NORETURN
-	;
-
 gcc_attribute_list_opt:
 	  /* empty */
 	| gcc_attribute_list



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 20:44:24 UTC 2021

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

Log Message:
lint: merge duplicate code for struct and enum tags

This is a tricky area.  Inlining identifier_sym did not work because of
the side-effects of getsym.  In situations where two identifiers of
different kinds follow each other, such as 'enum id1 id2', the timing is
crucial, and inlining identifier_sym would have led to an internal error
in getsym.  The symbol type has to be reset from FTAG to FVFT before
reading the next token.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 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.300 src/usr.bin/xlint/lint1/cgram.y:1.301
--- src/usr.bin/xlint/lint1/cgram.y:1.300	Sat Jul 10 19:29:28 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 20:44:23 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.300 2021/07/10 19:29:28 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.301 2021/07/10 20:44:23 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.300 2021/07/10 19:29:28 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.301 2021/07/10 20:44:23 rillig Exp $");
 #endif
 
 #include 
@@ -285,10 +285,9 @@ anonymize(sym_t *s)
 %type		notype_type_specifier
 %type		struct_or_union_specifier
 %type		enum_specifier
-%type			struct_tag
-%type			enum_tag
 %type		struct_or_union
 %type			braced_struct_declaration_list
+%type			identifier_sym
 %type		identifier
 %type			struct_declaration_list_semi
 %type			struct_declaration_list
@@ -302,7 +301,6 @@ anonymize(sym_t *s)
 %type			enum_declaration
 %type			enumerator_list
 %type			enumerator
-%type			enumeration_constant
 %type			notype_direct_decl
 %type			type_direct_decl
 %type		pointer
@@ -597,7 +595,7 @@ notype_type_specifier:
 	;
 
 struct_or_union_specifier:	/* C99 6.7.2.1 */
-	  struct_or_union struct_tag {
+	  struct_or_union identifier_sym {
 		/*
 		 * STDC requires that "struct a;" always introduces
 		 * a new tag if "a" is not declared at current level
@@ -607,7 +605,7 @@ struct_or_union_specifier:	/* C99 6.7.2.
 		 */
 		$$ = mktag($2, $1, false, yychar == T_SEMI);
 	  }
-	| struct_or_union struct_tag {
+	| struct_or_union identifier_sym {
 		dcs->d_tagtyp = mktag($2, $1, true, false);
 	  } braced_struct_declaration_list {
 		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
@@ -632,12 +630,6 @@ struct_or_union:		/* C99 6.7.2.1 */
 	  } type_attribute_list_opt
 	;
 
-struct_tag:
-	  identifier {
-		$$ = getsym($1);
-	  }
-	;
-
 braced_struct_declaration_list:
 	  T_LBRACE {
 		symtyp = FVFT;
@@ -781,10 +773,10 @@ type_member_decl:
 	;
 
 enum_specifier:		/* C99 6.7.2.2 */
-	  enum enum_tag {
+	  enum identifier_sym {
 		$$ = mktag($2, ENUM, false, false);
 	  }
-	| enum enum_tag {
+	| enum identifier_sym {
 		dcs->d_tagtyp = mktag($2, ENUM, true, false);
 	  } enum_declaration {
 		$$ = complete_tag_enum(dcs->d_tagtyp, $4);
@@ -807,12 +799,6 @@ enum:
 	  }
 	;
 
-enum_tag:
-	  identifier {
-		$$ = getsym($1);
-	  }
-	;
-
 enum_declaration:
 	  T_LBRACE {
 		symtyp = FVFT;
@@ -846,20 +832,14 @@ enumerator_list_comma_opt:
 	;
 
 enumerator:			/* C99 6.7.2.2 */
-	  enumeration_constant {
+	  identifier_sym {
 		$$ = enumeration_constant($1, enumval, true);
 	  }
-	| enumeration_constant T_ASSIGN constant_expr {
+	| identifier_sym T_ASSIGN constant_expr {
 		$$ = enumeration_constant($1, to_int_constant($3, true), false);
 	  }
 	;
 
-enumeration_constant:		/* C99 6.4.4.3 */
-	  identifier {
-		$$ = getsym($1);
-	  }
-	;
-
 
 /*
  * For an explanation of 'notype' in the following rules, see the Bison
@@ -1897,6 +1877,12 @@ point_or_arrow:
 	  }
 	;
 
+identifier_sym:
+	  identifier {
+		$$ = getsym($1);
+	  }
+	;
+
 identifier:			/* C99 6.4.2.1 */
 	  T_NAME {
 		$$ = $1;



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 19:29:28 UTC 2021

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

Log Message:
lint: rename grammar rules to align with C99

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 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.299 src/usr.bin/xlint/lint1/cgram.y:1.300
--- src/usr.bin/xlint/lint1/cgram.y:1.299	Sat Jul 10 18:56:54 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 19:29:28 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.299 2021/07/10 18:56:54 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.300 2021/07/10 19:29:28 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.299 2021/07/10 18:56:54 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.300 2021/07/10 19:29:28 rillig Exp $");
 #endif
 
 #include 
@@ -281,18 +281,18 @@ anonymize(sym_t *s)
 %type			func_decl
 %type			notype_decl
 %type			type_decl
-%type		typespec
-%type		notype_typespec
-%type		struct_spec
-%type		enum_spec
+%type		type_specifier
+%type		notype_type_specifier
+%type		struct_or_union_specifier
+%type		enum_specifier
 %type			struct_tag
 %type			enum_tag
-%type		struct
-%type			struct_declaration
+%type		struct_or_union
+%type			braced_struct_declaration_list
 %type		identifier
-%type			member_declaration_list_semi
-%type			member_declaration_list
-%type			member_declaration
+%type			struct_declaration_list_semi
+%type			struct_declaration_list
+%type			struct_declaration
 %type			notype_member_decls
 %type			type_member_decls
 %type			notype_member_decl
@@ -535,11 +535,11 @@ end_type:
 	;
 
 declaration_specifiers:		/* C99 6.7 */
-	  add_typespec
-	| declmods add_typespec
+	  add_type_specifier
+	| declmods add_type_specifier
 	| type_attribute declaration_specifiers
 	| declaration_specifiers declmod
-	| declaration_specifiers add_notype_typespec
+	| declaration_specifiers add_notype_type_specifier
 	;
 
 declmods:
@@ -559,44 +559,45 @@ qualifier_or_storage_class:
 	  }
 	;
 
-add_typespec:
-	  typespec {
+add_type_specifier:
+	  type_specifier {
 		add_type($1);
 	  }
 	;
 
-typespec:
-	  notype_typespec
+type_specifier:			/* C99 6.7.2 */
+	  notype_type_specifier
 	| T_TYPENAME {
 		$$ = getsym($1)->s_type;
 	  }
 	;
 
-add_notype_typespec:
-	  notype_typespec {
+add_notype_type_specifier:
+	  notype_type_specifier {
 		add_type($1);
 	  }
 	;
 
-notype_typespec:
+/* Like type_specifier, but without typedef-name. */
+notype_type_specifier:
 	  T_TYPE {
 		$$ = gettyp($1);
 	  }
 	| T_TYPEOF term {
 		$$ = $2->tn_type;
 	  }
-	| struct_spec {
+	| struct_or_union_specifier {
 		end_declaration_level();
 		$$ = $1;
 	  }
-	| enum_spec {
+	| enum_specifier {
 		end_declaration_level();
 		$$ = $1;
 	  }
 	;
 
-struct_spec:
-	  struct struct_tag {
+struct_or_union_specifier:	/* C99 6.7.2.1 */
+	  struct_or_union struct_tag {
 		/*
 		 * STDC requires that "struct a;" always introduces
 		 * a new tag if "a" is not declared at current level
@@ -606,23 +607,23 @@ struct_spec:
 		 */
 		$$ = mktag($2, $1, false, yychar == T_SEMI);
 	  }
-	| struct struct_tag {
+	| struct_or_union struct_tag {
 		dcs->d_tagtyp = mktag($2, $1, true, false);
-	  } struct_declaration {
+	  } braced_struct_declaration_list {
 		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
 	  }
-	| struct {
+	| struct_or_union {
 		dcs->d_tagtyp = mktag(NULL, $1, true, false);
-	  } struct_declaration {
+	  } braced_struct_declaration_list {
 		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
 	  }
-	| struct error {
+	| struct_or_union error {
 		symtyp = FVFT;
 		$$ = gettyp(INT);
 	  }
 	;
 
-struct:
+struct_or_union:		/* C99 6.7.2.1 */
 	  T_STRUCT_OR_UNION {
 		symtyp = FTAG;
 		begin_declaration_level($1 == STRUCT ? MOS : MOU);
@@ -637,20 +638,20 @@ struct_tag:
 	  }
 	;
 
-struct_declaration:
+braced_struct_declaration_list:
 	  T_LBRACE {
 		symtyp = FVFT;
-	  } member_declaration_list_semi T_RBRACE {
+	  } struct_declaration_list_semi T_RBRACE {
 		$$ = $3;
 	  }
 	;
 
-member_declaration_list_semi:
+struct_declaration_list_semi:
 	  /* empty */ {
 		$$ = NULL;
 	  }
-	| member_declaration_list T_SEMI
-	| member_declaration_list {
+	| struct_declaration_list T_SEMI
+	| struct_declaration_list {
 		if (sflag) {
 			/* syntax req. ';' after last struct/union member */
 			error(66);
@@ -662,14 +663,14 @@ member_declaration_list_semi:
 	  }
 	;
 
-member_declaration_list:
-	  member_declaration
-	| member_declaration_list T_SEMI member_declaration {
+struct_declaration_list:
+	  struct_declaration
+	| struct_declaration_list T_SEMI struct_declaration {
 		$$ = lnklst($1, $3);
 	  }
 	;
 
-member_declaration:

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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 18:56:55 UTC 2021

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

Log Message:
lint: merge duplicate code for typespec and notype_typespec

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.298 -r1.299 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.298 src/usr.bin/xlint/lint1/cgram.y:1.299
--- src/usr.bin/xlint/lint1/cgram.y:1.298	Sat Jul 10 18:13:06 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 18:56:54 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.298 2021/07/10 18:13:06 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.299 2021/07/10 18:56:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.298 2021/07/10 18:13:06 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.299 2021/07/10 18:56:54 rillig Exp $");
 #endif
 
 #include 
@@ -535,17 +535,11 @@ end_type:
 	;
 
 declaration_specifiers:		/* C99 6.7 */
-	  typespec {
-		add_type($1);
-	  }
-	| declmods typespec {
-		add_type($2);
-	  }
+	  add_typespec
+	| declmods add_typespec
 	| type_attribute declaration_specifiers
 	| declaration_specifiers declmod
-	| declaration_specifiers notype_typespec {
-		add_type($2);
-	  }
+	| declaration_specifiers add_notype_typespec
 	;
 
 declmods:
@@ -559,14 +553,18 @@ declmod:
 	;
 
 qualifier_or_storage_class:
-	  T_QUAL {
-		add_qualifier($1);
-	  }
+	  add_type_qualifier
 	| T_SCLASS {
 		add_storage_class($1);
 	  }
 	;
 
+add_typespec:
+	  typespec {
+		add_type($1);
+	  }
+	;
+
 typespec:
 	  notype_typespec
 	| T_TYPENAME {
@@ -574,6 +572,12 @@ typespec:
 	  }
 	;
 
+add_notype_typespec:
+	  notype_typespec {
+		add_type($1);
+	  }
+	;
+
 notype_typespec:
 	  T_TYPE {
 		$$ = gettyp($1);
@@ -711,18 +715,10 @@ noclass_declspecs:
 	;
 
 noclass_declspecs_postfix:
-	  typespec {
-		add_type($1);
-	  }
-	| add_type_qualifier_list typespec {
-		add_type($2);
-	  }
-	| noclass_declspecs_postfix T_QUAL {
-		add_qualifier($2);
-	  }
-	| noclass_declspecs_postfix notype_typespec {
-		add_type($2);
-	  }
+	  add_typespec
+	| add_type_qualifier_list add_typespec
+	| noclass_declspecs_postfix add_type_qualifier
+	| noclass_declspecs_postfix add_notype_typespec
 	| noclass_declspecs_postfix type_attribute
 	;
 



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 18:13:06 UTC 2021

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

Log Message:
lint: rename func_arg_list to align with C99

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.297 -r1.298 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.297 src/usr.bin/xlint/lint1/cgram.y:1.298
--- src/usr.bin/xlint/lint1/cgram.y:1.297	Sat Jul 10 17:46:55 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 18:13:06 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.297 2021/07/10 17:46:55 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.298 2021/07/10 18:13:06 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.297 2021/07/10 17:46:55 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.298 2021/07/10 18:13:06 rillig Exp $");
 #endif
 
 #include 
@@ -329,7 +329,7 @@ anonymize(sym_t *s)
 %type		gcc_statement_expr_item
 %type		term
 %type		generic_selection
-%type		func_arg_list
+%type		argument_expression_list
 %type			point_or_arrow
 %type		type_name
 %type			abstract_declaration
@@ -1731,7 +1731,7 @@ term:/* see C99 6.5.1 */
 	| term T_LPAREN T_RPAREN {
 		$$ = new_function_call_node($1, NULL);
 	  }
-	| term T_LPAREN func_arg_list T_RPAREN {
+	| term T_LPAREN argument_expression_list T_RPAREN {
 		$$ = new_function_call_node($1, $3);
 	  }
 	| term point_or_arrow T_NAME {
@@ -1824,6 +1824,15 @@ generic_association:		/* C11 6.5.1.1 */
 	  }
 	;
 
+argument_expression_list:	/* C99 6.5.2 */
+	  expr %prec T_COMMA {
+		$$ = new_function_argument_node(NULL, $1);
+	  }
+	| argument_expression_list T_COMMA expr {
+		$$ = new_function_argument_node($1, $3);
+	  }
+	;
+
 /*
  * The inner part of a GCC statement-expression of the form ({ ... }).
  *
@@ -1880,15 +1889,6 @@ string2:
 	  }
 	;
 
-func_arg_list:
-	  expr %prec T_COMMA {
-		$$ = new_function_argument_node(NULL, $1);
-	  }
-	| func_arg_list T_COMMA expr {
-		$$ = new_function_argument_node($1, $3);
-	  }
-	;
-
 point_or_arrow:
 	  T_POINT {
 		symtyp = FMEMBER;



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 17:46:55 UTC 2021

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

Log Message:
lint: rename y_sb to y_name

That buffer is only used for names of identifiers, so be more specific.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.53 -r1.54 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/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.296 src/usr.bin/xlint/lint1/cgram.y:1.297
--- src/usr.bin/xlint/lint1/cgram.y:1.296	Sat Jul 10 17:35:54 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 17:46:55 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.296 2021/07/10 17:35:54 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.297 2021/07/10 17:46:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.296 2021/07/10 17:35:54 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.297 2021/07/10 17:46:55 rillig Exp $");
 #endif
 
 #include 
@@ -121,13 +121,14 @@ anonymize(sym_t *s)
 	for ( ; s != NULL; s = s->s_next)
 		s->s_styp = NULL;
 }
+
 %}
 
 %expect 136
 
 %union {
 	val_t	*y_val;
-	sbuf_t	*y_sb;
+	sbuf_t	*y_name;
 	sym_t	*y_sym;
 	op_t	y_op;
 	scl_t	y_scl;
@@ -272,8 +273,8 @@ anonymize(sym_t *s)
 %right	T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG
 %left	T_LPAREN T_LBRACK T_POINT T_ARROW
 
-%token			T_NAME
-%token			T_TYPENAME
+%token		T_NAME
+%token		T_TYPENAME
 %token			T_CON
 %token		T_STRING
 
@@ -288,7 +289,7 @@ anonymize(sym_t *s)
 %type			enum_tag
 %type		struct
 %type			struct_declaration
-%type			identifier
+%type		identifier
 %type			member_declaration_list_semi
 %type			member_declaration_list
 %type			member_declaration
@@ -335,7 +336,7 @@ anonymize(sym_t *s)
 %type		expr_opt
 %type		string
 %type		string2
-%type			asm_or_symbolrename_opt
+%type		asm_or_symbolrename_opt
 %type		range
 %type	 block_item_list
 %type	 block_item

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.53 src/usr.bin/xlint/lint1/lex.c:1.54
--- src/usr.bin/xlint/lint1/lex.c:1.53	Thu Jul  8 03:10:39 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sat Jul 10 17:46:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.53 2021/07/08 03:10:39 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.54 2021/07/10 17:46:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.53 2021/07/08 03:10:39 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.54 2021/07/10 17:46:55 rillig Exp $");
 #endif
 
 #include 
@@ -440,7 +440,7 @@ lex_name(const char *yytext, size_t yyle
 		tok = T_NAME;
 	}
 
-	yylval.y_sb = sb;
+	yylval.y_name = sb;
 	return tok;
 }
 



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 17:17:06 UTC 2021

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

Log Message:
lint: extract clrtyp from noclass_declspecs

Finally each clrtyp pairs up with its corresponding deftyp, which makes
the grammar much easier to understand.  The many grammar rules that
contain these actions now all look the same.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.294 -r1.295 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.294 src/usr.bin/xlint/lint1/cgram.y:1.295
--- src/usr.bin/xlint/lint1/cgram.y:1.294	Sat Jul 10 17:06:56 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 17:17:05 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.294 2021/07/10 17:06:56 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.295 2021/07/10 17:17:05 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.294 2021/07/10 17:06:56 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.295 2021/07/10 17:17:05 rillig Exp $");
 #endif
 
 #include 
@@ -672,18 +672,18 @@ member_declaration:
 		symtyp = FVFT;
 		$$ = $5;
 	  }
-	| noclass_declspecs deftyp {
+	| clrtyp noclass_declspecs deftyp {
 		symtyp = FMEMBER;
 	  } type_member_decls type_attribute_opt {
 		symtyp = FVFT;
-		$$ = $4;
+		$$ = $5;
 	  }
 	| clrtyp add_type_qualifier_list deftyp type_attribute_opt {
 		/* syntax error '%s' */
 		error(249, "member without type");
 		$$ = NULL;
 	  }
-	| noclass_declspecs deftyp type_attribute_opt {
+	| clrtyp noclass_declspecs deftyp type_attribute_opt {
 		symtyp = FVFT;
 		if (!Sflag)
 			/* anonymous struct/union members is a C9X feature */
@@ -709,13 +709,12 @@ noclass_declspecs:
 	| type_attribute noclass_declspecs_postfix
 	;
 
-/* TODO: pair up clrtyp with deftyp */
 noclass_declspecs_postfix:
-	  clrtyp typespec {
-		add_type($2);
+	  typespec {
+		add_type($1);
 	  }
-	| clrtyp add_type_qualifier_list typespec {
-		add_type($3);
+	| add_type_qualifier_list typespec {
+		add_type($2);
 	  }
 	| noclass_declspecs_postfix T_QUAL {
 		add_qualifier($2);
@@ -1272,14 +1271,14 @@ abstract_declaration:
 	  clrtyp add_type_qualifier_list deftyp {
 		$$ = declare_1_abstract(abstract_name());
 	  }
-	| noclass_declspecs deftyp {
+	| clrtyp noclass_declspecs deftyp {
 		$$ = declare_1_abstract(abstract_name());
 	  }
 	| clrtyp add_type_qualifier_list deftyp abstract_declarator {
 		$$ = declare_1_abstract($4);
 	  }
-	| noclass_declspecs deftyp abstract_declarator {
-		$$ = declare_1_abstract($3);
+	| clrtyp noclass_declspecs deftyp abstract_declarator {
+		$$ = declare_1_abstract($4);
 	  }
 	;
 



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 17:06:56 UTC 2021

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

Log Message:
lint: extract clrtyp from declaration_specifiers

This makes the grammar more uniform and thereby easier to understand.
The actions clrtyp and deftyp now come in pairs almost everywhere.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.293 -r1.294 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.293 src/usr.bin/xlint/lint1/cgram.y:1.294
--- src/usr.bin/xlint/lint1/cgram.y:1.293	Sat Jul 10 16:54:40 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 17:06:56 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.293 2021/07/10 16:54:40 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.294 2021/07/10 17:06:56 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.293 2021/07/10 16:54:40 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.294 2021/07/10 17:06:56 rillig Exp $");
 #endif
 
 #include 
@@ -447,8 +447,8 @@ func_decl:
 	| clrtyp declmods deftyp notype_decl {
 		$$ = $4;
 	  }
-	| declaration_specifiers deftyp type_decl {
-		$$ = $3;
+	| clrtyp declaration_specifiers deftyp type_decl {
+		$$ = $4;
 	  }
 	;
 
@@ -474,7 +474,7 @@ arg_declaration:
 		warning(2);
 	  }
 	| clrtyp declmods deftyp notype_init_decls T_SEMI
-	| declaration_specifiers deftyp T_SEMI {
+	| clrtyp declaration_specifiers deftyp T_SEMI {
 		if (!dcs->d_nonempty_decl) {
 			/* empty declaration */
 			warning(2);
@@ -483,14 +483,14 @@ arg_declaration:
 			warning(3, type_name(dcs->d_type));
 		}
 	  }
-	| declaration_specifiers deftyp type_init_decls T_SEMI {
+	| clrtyp declaration_specifiers deftyp type_init_decls T_SEMI {
 		if (dcs->d_nonempty_decl) {
 			/* '%s' declared in argument declaration list */
 			warning(3, type_name(dcs->d_type));
 		}
 	  }
 	| clrtyp declmods error
-	| declaration_specifiers error
+	| clrtyp declaration_specifiers error
 	;
 
 declaration:			/* C99 6.7 */
@@ -509,7 +509,7 @@ declaration_noerror:		/* see C99 6.7 'de
 		}
 	  }
 	| clrtyp declmods deftyp notype_init_decls T_SEMI
-	| declaration_specifiers deftyp T_SEMI {
+	| clrtyp declaration_specifiers deftyp T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
 			warning(72);
@@ -518,7 +518,7 @@ declaration_noerror:		/* see C99 6.7 'de
 			warning(2);
 		}
 	  }
-	| declaration_specifiers deftyp type_init_decls T_SEMI
+	| clrtyp declaration_specifiers deftyp type_init_decls T_SEMI
 	;
 
 clrtyp:
@@ -534,11 +534,11 @@ deftyp:
 	;
 
 declaration_specifiers:		/* C99 6.7 */
-	  clrtyp typespec {
-		add_type($2);
+	  typespec {
+		add_type($1);
 	  }
-	| clrtyp declmods typespec {
-		add_type($3);
+	| declmods typespec {
+		add_type($2);
 	  }
 	| type_attribute declaration_specifiers
 	| declaration_specifiers declmod
@@ -709,6 +709,7 @@ noclass_declspecs:
 	| type_attribute noclass_declspecs_postfix
 	;
 
+/* TODO: pair up clrtyp with deftyp */
 noclass_declspecs_postfix:
 	  clrtyp typespec {
 		add_type($2);
@@ -1153,20 +1154,20 @@ parameter_declaration:
 	  clrtyp declmods deftyp {
 		$$ = declare_argument(abstract_name(), false);
 	  }
-	| declaration_specifiers deftyp {
+	| clrtyp declaration_specifiers deftyp {
 		$$ = declare_argument(abstract_name(), false);
 	  }
 	| clrtyp declmods deftyp notype_param_decl {
 		$$ = declare_argument($4, false);
 	  }
-	| declaration_specifiers deftyp type_param_decl {
-		$$ = declare_argument($3, false);
+	| clrtyp declaration_specifiers deftyp type_param_decl {
+		$$ = declare_argument($4, false);
 	  }
 	| clrtyp declmods deftyp abstract_declarator {
 		$$ = declare_argument($4, false);
 	  }
-	| declaration_specifiers deftyp abstract_declarator {
-		$$ = declare_argument($3, false);
+	| clrtyp declaration_specifiers deftyp abstract_declarator {
+		$$ = declare_argument($4, false);
 	  }
 	;
 
@@ -1539,11 +1540,13 @@ for_start:			/* see C99 6.8.5 */
 	;
 
 for_exprs:			/* see C99 6.8.5 */
-	  for_start declaration_specifiers deftyp notype_init_decls T_SEMI
-	expr_opt T_SEMI expr_opt T_RPAREN {
+	  for_start
+	clrtyp declaration_specifiers deftyp notype_init_decls T_SEMI
+	expr_opt T_SEMI
+	expr_opt T_RPAREN {
 		/* variable declaration in for loop */
 		c99ism(325);
-		for1(NULL, $6, $8);
+		for1(NULL, $7, $9);
 		clear_warning_flags();
 	}
 	  | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN {



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 16:54:40 UTC 2021

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

Log Message:
lint: split grammar rule clrtyp_declmods

By extracting clrtyp from that rule, clrtyp and deftyp pair up nicely in
most of the grammar rules.  These two actions delimit the common part of
a declaration that declares multiple identifiers.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 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.292 src/usr.bin/xlint/lint1/cgram.y:1.293
--- src/usr.bin/xlint/lint1/cgram.y:1.292	Sat Jul 10 16:41:51 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 16:54:40 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.292 2021/07/10 16:41:51 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.293 2021/07/10 16:54:40 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.292 2021/07/10 16:41:51 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.293 2021/07/10 16:54:40 rillig Exp $");
 #endif
 
 #include 
@@ -444,8 +444,8 @@ func_decl:
 	  clrtyp deftyp notype_decl {
 		$$ = $3;
 	  }
-	| clrtyp_declmods deftyp notype_decl {
-		$$ = $3;
+	| clrtyp declmods deftyp notype_decl {
+		$$ = $4;
 	  }
 	| declaration_specifiers deftyp type_decl {
 		$$ = $3;
@@ -469,11 +469,11 @@ arg_declaration_list:		/* C99 6.9.1p13 e
  * needs other error handling.
  */
 arg_declaration:
-	  clrtyp_declmods deftyp T_SEMI {
+	  clrtyp declmods deftyp T_SEMI {
 		/* empty declaration */
 		warning(2);
 	  }
-	| clrtyp_declmods deftyp notype_init_decls T_SEMI
+	| clrtyp declmods deftyp notype_init_decls T_SEMI
 	| declaration_specifiers deftyp T_SEMI {
 		if (!dcs->d_nonempty_decl) {
 			/* empty declaration */
@@ -489,7 +489,7 @@ arg_declaration:
 			warning(3, type_name(dcs->d_type));
 		}
 	  }
-	| clrtyp_declmods error
+	| clrtyp declmods error
 	| declaration_specifiers error
 	;
 
@@ -499,7 +499,7 @@ declaration:			/* C99 6.7 */
 	;
 
 declaration_noerror:		/* see C99 6.7 'declaration' */
-	  clrtyp_declmods deftyp T_SEMI {
+	  clrtyp declmods deftyp T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
 			warning(72);
@@ -508,7 +508,7 @@ declaration_noerror:		/* see C99 6.7 'de
 			warning(2);
 		}
 	  }
-	| clrtyp_declmods deftyp notype_init_decls T_SEMI
+	| clrtyp declmods deftyp notype_init_decls T_SEMI
 	| declaration_specifiers deftyp T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
@@ -537,8 +537,8 @@ declaration_specifiers:		/* C99 6.7 */
 	  clrtyp typespec {
 		add_type($2);
 	  }
-	| clrtyp_declmods typespec {
-		add_type($2);
+	| clrtyp declmods typespec {
+		add_type($3);
 	  }
 	| type_attribute declaration_specifiers
 	| declaration_specifiers declmod
@@ -547,9 +547,9 @@ declaration_specifiers:		/* C99 6.7 */
 	  }
 	;
 
-clrtyp_declmods:
-	  clrtyp qualifier_or_storage_class
-	| clrtyp_declmods declmod
+declmods:
+	  qualifier_or_storage_class
+	| declmods declmod
 	;
 
 declmod:
@@ -1150,20 +1150,20 @@ parameter_type_list:
 
 /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
 parameter_declaration:
-	  clrtyp_declmods deftyp {
+	  clrtyp declmods deftyp {
 		$$ = declare_argument(abstract_name(), false);
 	  }
 	| declaration_specifiers deftyp {
 		$$ = declare_argument(abstract_name(), false);
 	  }
-	| clrtyp_declmods deftyp notype_param_decl {
-		$$ = declare_argument($3, false);
+	| clrtyp declmods deftyp notype_param_decl {
+		$$ = declare_argument($4, false);
 	  }
 	| declaration_specifiers deftyp type_param_decl {
 		$$ = declare_argument($3, false);
 	  }
-	| clrtyp_declmods deftyp abstract_declarator {
-		$$ = declare_argument($3, false);
+	| clrtyp declmods deftyp abstract_declarator {
+		$$ = declare_argument($4, false);
 	  }
 	| declaration_specifiers deftyp abstract_declarator {
 		$$ = declare_argument($3, false);



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 16:41:51 UTC 2021

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

Log Message:
lint: inline grammar rule clrtyp_typespec

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.291 -r1.292 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.291 src/usr.bin/xlint/lint1/cgram.y:1.292
--- src/usr.bin/xlint/lint1/cgram.y:1.291	Sat Jul 10 16:39:43 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 16:41:51 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.291 2021/07/10 16:39:43 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.292 2021/07/10 16:41:51 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.291 2021/07/10 16:39:43 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.292 2021/07/10 16:41:51 rillig Exp $");
 #endif
 
 #include 
@@ -281,7 +281,6 @@ anonymize(sym_t *s)
 %type			notype_decl
 %type			type_decl
 %type		typespec
-%type		clrtyp_typespec
 %type		notype_typespec
 %type		struct_spec
 %type		enum_spec
@@ -535,8 +534,8 @@ deftyp:
 	;
 
 declaration_specifiers:		/* C99 6.7 */
-	  clrtyp_typespec {
-		add_type($1);
+	  clrtyp typespec {
+		add_type($2);
 	  }
 	| clrtyp_declmods typespec {
 		add_type($2);
@@ -567,12 +566,6 @@ qualifier_or_storage_class:
 	  }
 	;
 
-clrtyp_typespec:
-	  clrtyp typespec {
-		$$ = $2;
-	  }
-	;
-
 typespec:
 	  notype_typespec
 	| T_TYPENAME {
@@ -717,8 +710,8 @@ noclass_declspecs:
 	;
 
 noclass_declspecs_postfix:
-	  clrtyp_typespec {
-		add_type($1);
+	  clrtyp typespec {
+		add_type($2);
 	  }
 	| clrtyp add_type_qualifier_list typespec {
 		add_type($3);



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 16:39:43 UTC 2021

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

Log Message:
lint: merge duplicate code from grammar rule clrtyp_typespec

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.290 -r1.291 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.290 src/usr.bin/xlint/lint1/cgram.y:1.291
--- src/usr.bin/xlint/lint1/cgram.y:1.290	Sat Jul 10 15:04:07 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 16:39:43 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.290 2021/07/10 15:04:07 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.291 2021/07/10 16:39:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.290 2021/07/10 15:04:07 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.291 2021/07/10 16:39:43 rillig Exp $");
 #endif
 
 #include 
@@ -568,12 +568,9 @@ qualifier_or_storage_class:
 	;
 
 clrtyp_typespec:
-	  clrtyp notype_typespec {
+	  clrtyp typespec {
 		$$ = $2;
 	  }
-	| clrtyp T_TYPENAME {
-		$$ = getsym($2)->s_type;
-	  }
 	;
 
 typespec:



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 15:04:07 UTC 2021

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

Log Message:
lint: swap order in grammar rule clrtyp_typespec

It should not make a difference whether the rule says 'T_TYPENAME
clrtyp' or 'clrtyp T_TYPENAME'.  The latter order is more consistent
with the name of the rule, though.

According to the code, these two tokens take completely distinct
actions.  The code coverage outside of cgram.y and cgram.c stays exactly
the same, at least for lint's test suite.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 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.289 src/usr.bin/xlint/lint1/cgram.y:1.290
--- src/usr.bin/xlint/lint1/cgram.y:1.289	Sat Jul 10 14:45:15 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 15:04:07 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.289 2021/07/10 14:45:15 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.290 2021/07/10 15:04:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.289 2021/07/10 14:45:15 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.290 2021/07/10 15:04:07 rillig Exp $");
 #endif
 
 #include 
@@ -571,8 +571,8 @@ clrtyp_typespec:
 	  clrtyp notype_typespec {
 		$$ = $2;
 	  }
-	| T_TYPENAME clrtyp {
-		$$ = getsym($1)->s_type;
+	| clrtyp T_TYPENAME {
+		$$ = getsym($2)->s_type;
 	  }
 	;
 



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 14:45:15 UTC 2021

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

Log Message:
lint: rename grammar rule declmods to clrtyp_declmods

It wasn't obvious from the name 'declmods' that this rule starts a new
type declaration.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 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.288 src/usr.bin/xlint/lint1/cgram.y:1.289
--- src/usr.bin/xlint/lint1/cgram.y:1.288	Sat Jul 10 11:22:19 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 14:45:15 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.288 2021/07/10 11:22:19 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.289 2021/07/10 14:45:15 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.288 2021/07/10 11:22:19 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.289 2021/07/10 14:45:15 rillig Exp $");
 #endif
 
 #include 
@@ -445,7 +445,7 @@ func_decl:
 	  clrtyp deftyp notype_decl {
 		$$ = $3;
 	  }
-	| declmods deftyp notype_decl {
+	| clrtyp_declmods deftyp notype_decl {
 		$$ = $3;
 	  }
 	| declaration_specifiers deftyp type_decl {
@@ -470,11 +470,11 @@ arg_declaration_list:		/* C99 6.9.1p13 e
  * needs other error handling.
  */
 arg_declaration:
-	  declmods deftyp T_SEMI {
+	  clrtyp_declmods deftyp T_SEMI {
 		/* empty declaration */
 		warning(2);
 	  }
-	| declmods deftyp notype_init_decls T_SEMI
+	| clrtyp_declmods deftyp notype_init_decls T_SEMI
 	| declaration_specifiers deftyp T_SEMI {
 		if (!dcs->d_nonempty_decl) {
 			/* empty declaration */
@@ -490,7 +490,7 @@ arg_declaration:
 			warning(3, type_name(dcs->d_type));
 		}
 	  }
-	| declmods error
+	| clrtyp_declmods error
 	| declaration_specifiers error
 	;
 
@@ -500,7 +500,7 @@ declaration:			/* C99 6.7 */
 	;
 
 declaration_noerror:		/* see C99 6.7 'declaration' */
-	  declmods deftyp T_SEMI {
+	  clrtyp_declmods deftyp T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
 			warning(72);
@@ -509,7 +509,7 @@ declaration_noerror:		/* see C99 6.7 'de
 			warning(2);
 		}
 	  }
-	| declmods deftyp notype_init_decls T_SEMI
+	| clrtyp_declmods deftyp notype_init_decls T_SEMI
 	| declaration_specifiers deftyp T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
@@ -538,7 +538,7 @@ declaration_specifiers:		/* C99 6.7 */
 	  clrtyp_typespec {
 		add_type($1);
 	  }
-	| declmods typespec {
+	| clrtyp_declmods typespec {
 		add_type($2);
 	  }
 	| type_attribute declaration_specifiers
@@ -548,9 +548,9 @@ declaration_specifiers:		/* C99 6.7 */
 	  }
 	;
 
-declmods:
+clrtyp_declmods:
 	  clrtyp qualifier_or_storage_class
-	| declmods declmod
+	| clrtyp_declmods declmod
 	;
 
 declmod:
@@ -1160,19 +1160,19 @@ parameter_type_list:
 
 /* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
 parameter_declaration:
-	  declmods deftyp {
+	  clrtyp_declmods deftyp {
 		$$ = declare_argument(abstract_name(), false);
 	  }
 	| declaration_specifiers deftyp {
 		$$ = declare_argument(abstract_name(), false);
 	  }
-	| declmods deftyp notype_param_decl {
+	| clrtyp_declmods deftyp notype_param_decl {
 		$$ = declare_argument($3, false);
 	  }
 	| declaration_specifiers deftyp type_param_decl {
 		$$ = declare_argument($3, false);
 	  }
-	| declmods deftyp abstract_declarator {
+	| clrtyp_declmods deftyp abstract_declarator {
 		$$ = declare_argument($3, false);
 	  }
 	| declaration_specifiers deftyp abstract_declarator {



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 12:17:31 UTC 2021

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

Log Message:
lint: flush stdout before an internal error

Previously, the internal error may have appeared too early in the
output.  Provoking internal errors and assertion failures is still easy,
just run afl-fuzz for a few seconds.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/xlint/lint1/err.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/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.126 src/usr.bin/xlint/lint1/err.c:1.127
--- src/usr.bin/xlint/lint1/err.c:1.126	Mon Jul  5 19:53:43 2021
+++ src/usr.bin/xlint/lint1/err.c	Sat Jul 10 12:17:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.126 2021/07/05 19:53:43 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.127 2021/07/10 12:17:31 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.126 2021/07/05 19:53:43 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.127 2021/07/10 12:17:31 rillig Exp $");
 #endif
 
 #include 
@@ -569,6 +569,7 @@ internal_error(const char *file, int lin
 	const	char *fn;
 
 	fn = lbasename(curr_pos.p_file);
+	fflush(stdout);
 	(void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ",
 	file, line, fn, curr_pos.p_line);
 	va_start(ap, msg);
@@ -585,6 +586,7 @@ assert_failed(const char *file, int line
 	const	char *fn;
 
 	fn = lbasename(curr_pos.p_file);
+	fflush(stdout);
 	(void)fprintf(stderr,
 	"lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
 	cond, func, file, line, fn, curr_pos.p_line);



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 09:53:00 UTC 2021

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

Log Message:
lint: merge duplicate code in grammar for 'for' loops

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 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.284 src/usr.bin/xlint/lint1/cgram.y:1.285
--- src/usr.bin/xlint/lint1/cgram.y:1.284	Sat Jul 10 09:48:41 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 09:53:00 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.284 2021/07/10 09:48:41 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.285 2021/07/10 09:53:00 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.284 2021/07/10 09:48:41 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.285 2021/07/10 09:53:00 rillig Exp $");
 #endif
 
 #include 
@@ -1513,7 +1513,7 @@ iteration_statement:		/* C99 6.8.5 */
 	  T_WHILE T_LPAREN expr T_RPAREN {
 		while1($3);
 		clear_warning_flags();
-	  } while_body {
+	  } iteration_body {
 		clear_warning_flags();
 		while2();
 	  }
@@ -1527,13 +1527,7 @@ iteration_statement:		/* C99 6.8.5 */
 		clear_warning_flags();
 		do2(NULL);
 	  }
-	| for_exprs statement {
-		clear_warning_flags();
-		for2();
-		end_declaration_level();
-		block_level--;
-	  }
-	| for_exprs error {
+	| for_exprs iteration_body {
 		clear_warning_flags();
 		for2();
 		end_declaration_level();
@@ -1541,7 +1535,7 @@ iteration_statement:		/* C99 6.8.5 */
 	  }
 	;
 
-while_body:
+iteration_body:
 	  statement
 	| error
 	;



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 09:48:41 UTC 2021

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

Log Message:
lint: clean up grammar for do-while statements

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.283 -r1.284 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.283 src/usr.bin/xlint/lint1/cgram.y:1.284
--- src/usr.bin/xlint/lint1/cgram.y:1.283	Sat Jul 10 09:40:12 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 09:48:41 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.283 2021/07/10 09:40:12 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.284 2021/07/10 09:48:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.283 2021/07/10 09:40:12 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.284 2021/07/10 09:48:41 rillig Exp $");
 #endif
 
 #include 
@@ -333,7 +333,6 @@ anonymize(sym_t *s)
 %type			point_or_arrow
 %type		type_name
 %type			abstract_declaration
-%type		do_while_expr
 %type		expr_opt
 %type		string
 %type		string2
@@ -1510,12 +1509,6 @@ switch_expr:			/* see C99 6.8.4 */
 	  }
 	;
 
-do_statement:			/* C99 6.8.5 */
-	  do statement {
-		clear_warning_flags();
-	  }
-	;
-
 iteration_statement:		/* C99 6.8.5 */
 	  T_WHILE T_LPAREN expr T_RPAREN {
 		while1($3);
@@ -1524,8 +1517,10 @@ iteration_statement:		/* C99 6.8.5 */
 		clear_warning_flags();
 		while2();
 	  }
-	| do_statement do_while_expr {
-		do2($2);
+	| do statement {
+		clear_warning_flags();
+	  } T_WHILE T_LPAREN expr T_RPAREN T_SEMI {
+		do2($6);
 		seen_fallthrough = false;
 	  }
 	| do error {
@@ -1557,12 +1552,6 @@ do:/* see C99 6.8.5 */
 	  }
 	;
 
-do_while_expr:			/* see C99 6.8.5 */
-	  T_WHILE T_LPAREN expr T_RPAREN T_SEMI {
-		$$ = $3;
-	  }
-	;
-
 for_start:			/* see C99 6.8.5 */
 	  T_FOR T_LPAREN {
 		begin_declaration_level(AUTO);



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 09:40:12 UTC 2021

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

Log Message:
lint: merge duplicate code in grammar for 'while' statements

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.282 -r1.283 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.282 src/usr.bin/xlint/lint1/cgram.y:1.283
--- src/usr.bin/xlint/lint1/cgram.y:1.282	Sat Jul 10 05:42:29 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 09:40:12 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.282 2021/07/10 05:42:29 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.283 2021/07/10 09:40:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.282 2021/07/10 05:42:29 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.283 2021/07/10 09:40:12 rillig Exp $");
 #endif
 
 #include 
@@ -1517,11 +1517,10 @@ do_statement:			/* C99 6.8.5 */
 	;
 
 iteration_statement:		/* C99 6.8.5 */
-	  while_expr statement {
+	  T_WHILE T_LPAREN expr T_RPAREN {
+		while1($3);
 		clear_warning_flags();
-		while2();
-	  }
-	| while_expr error {
+	  } while_body {
 		clear_warning_flags();
 		while2();
 	  }
@@ -1547,11 +1546,9 @@ iteration_statement:		/* C99 6.8.5 */
 	  }
 	;
 
-while_expr:			/* see C99 6.8.5 */
-	  T_WHILE T_LPAREN expr T_RPAREN {
-		while1($3);
-		clear_warning_flags();
-	  }
+while_body:
+	  statement
+	| error
 	;
 
 do:/* see C99 6.8.5 */



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

2021-07-10 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 09:14:38 UTC 2021

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

Log Message:
tests/lint: when adding a new test, set an invalid option

This forces the test author to think about whether any custom options
are really needed.  While here, mention the other possible
customizations as well.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/xlint/lint1/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/lint1/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.78 src/usr.bin/xlint/lint1/Makefile:1.79
--- src/usr.bin/xlint/lint1/Makefile:1.78	Mon Jul  5 10:34:26 2021
+++ src/usr.bin/xlint/lint1/Makefile	Sat Jul 10 09:14:38 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.78 2021/07/05 10:34:26 hgutch Exp $
+#	$NetBSD: Makefile,v 1.79 2021/07/10 09:14:38 rillig Exp $
 
 .include 
 
@@ -74,7 +74,10 @@ add-test: .PHONY
 		' * TODO: Explain the purpose of the test.' \
 		' */' \
 		'' \
-		'/* lint1-extra-flags: -p */' \
+		'/* lint1-extra-flags: -Z */' \
+		'/* lint1-flags: -Z */' \
+		'/* lint1-only-if: schar uchar ilp32 lp64 int long */' \
+		'/* lint1-skip-if: ldbl-64 ldbl-96 ldbl-128 */' \
 		'' \
 		'// TODO: Add some code that passes.' \
 		'// TODO: Add some code that fails.' \



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 05:42:30 UTC 2021

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

Log Message:
lint: do not allow __packed or _Alignas in statement

When the rule 'statement: type_attribute T_SEMI' was added in cgram.y
1.214 from 2021-04-14, type_attribute was the closest match since there
was no definition for gcc_attribute yet.


To generate a diff of this commit:
cvs rdiff -u -r1.281 -r1.282 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.281 src/usr.bin/xlint/lint1/cgram.y:1.282
--- src/usr.bin/xlint/lint1/cgram.y:1.281	Sat Jul 10 05:03:03 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 05:42:29 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.281 2021/07/10 05:03:03 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.282 2021/07/10 05:42:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.281 2021/07/10 05:03:03 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.282 2021/07/10 05:42:29 rillig Exp $");
 #endif
 
 #include 
@@ -1365,7 +1365,7 @@ array_size:
 	;
 
 non_expr_statement:
-	  type_attribute T_SEMI
+	  gcc_attribute T_SEMI
 	| labeled_statement
 	| compound_statement
 	| selection_statement



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 05:03:03 UTC 2021

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

Log Message:
lint: reduce shift/reduce conflicts in direct_abstract_declarator

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.280 -r1.281 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.280 src/usr.bin/xlint/lint1/cgram.y:1.281
--- src/usr.bin/xlint/lint1/cgram.y:1.280	Sat Jul 10 04:57:41 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 05:03:03 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.280 2021/07/10 04:57:41 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.281 2021/07/10 05:03:03 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.280 2021/07/10 04:57:41 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.281 2021/07/10 05:03:03 rillig Exp $");
 #endif
 
 #include 
@@ -123,7 +123,7 @@ anonymize(sym_t *s)
 }
 %}
 
-%expect 142
+%expect 136
 
 %union {
 	val_t	*y_val;
@@ -319,6 +319,7 @@ anonymize(sym_t *s)
 %type			identifier_list
 %type			abstract_declarator
 %type			direct_abstract_declarator
+%type			direct_abstract_declarator_postfix
 %type			vararg_parameter_type_list
 %type			parameter_type_list
 %type			parameter_declaration
@@ -1310,12 +1311,14 @@ abstract_declarator:		/* C99 6.7.6 */
 	  }
 	;
 
-/*
- * XXX: shift/reduce conflict, caused by:
- *	type_attribute direct_abstract_declarator
- *	direct_abstract_declarator type_attribute
- */
 direct_abstract_declarator:		/* C99 6.7.6 */
+	  direct_abstract_declarator_postfix
+	| type_attribute direct_abstract_declarator_postfix {
+		$$ = $2;
+	  }
+	;
+
+direct_abstract_declarator_postfix:	/* C99 6.7.6 */
 	  T_LPAREN abstract_declarator T_RPAREN {
 		$$ = $2;
 	  }
@@ -1325,16 +1328,14 @@ direct_abstract_declarator:		/* C99 6.7.
 	| T_LBRACK array_size T_RBRACK {
 		$$ = add_array(abstract_name(), true, to_int_constant($2, false));
 	  }
-	| type_attribute direct_abstract_declarator {
-		$$ = $2;
-	  }
-	| direct_abstract_declarator T_LBRACK T_RBRACK {
+	| direct_abstract_declarator_postfix T_LBRACK T_RBRACK {
 		$$ = add_array($1, false, 0);
 	  }
-	| direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */
+	| direct_abstract_declarator_postfix
+	T_LBRACK T_ASTERISK T_RBRACK {	/* C99 */
 		$$ = add_array($1, false, 0);
 	  }
-	| direct_abstract_declarator T_LBRACK array_size T_RBRACK {
+	| direct_abstract_declarator_postfix T_LBRACK array_size T_RBRACK {
 		$$ = add_array($1, true, to_int_constant($3, false));
 	  }
 	| abstract_decl_param_list asm_or_symbolrename_opt {
@@ -1342,12 +1343,13 @@ direct_abstract_declarator:		/* C99 6.7.
 		end_declaration_level();
 		block_level--;
 	  }
-	| direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt {
+	| direct_abstract_declarator_postfix abstract_decl_param_list
+	asm_or_symbolrename_opt {
 		$$ = add_function(symbolrename($1, $3), $2);
 		end_declaration_level();
 		block_level--;
 	  }
-	| direct_abstract_declarator type_attribute
+	| direct_abstract_declarator_postfix type_attribute
 	;
 
 array_size:



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 04:57:41 UTC 2021

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

Log Message:
lint: remove 8 of the grammar conflicts, 142 remaining

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 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.279 src/usr.bin/xlint/lint1/cgram.y:1.280
--- src/usr.bin/xlint/lint1/cgram.y:1.279	Sat Jul 10 04:47:25 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 04:57:41 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.279 2021/07/10 04:47:25 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.280 2021/07/10 04:57:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.279 2021/07/10 04:47:25 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.280 2021/07/10 04:57:41 rillig Exp $");
 #endif
 
 #include 
@@ -123,7 +123,7 @@ anonymize(sym_t *s)
 }
 %}
 
-%expect 150
+%expect 142
 
 %union {
 	val_t	*y_val;
@@ -721,26 +721,25 @@ member_declaration:
 	  }
 	;
 
-/*
- * XXX: shift/reduce conflict, caused by:
- *	type_attribute noclass_declspecs
- *	noclass_declspecs type_attribute
- */
 noclass_declspecs:
+	  noclass_declspecs_postfix
+	| type_attribute noclass_declspecs_postfix
+	;
+
+noclass_declspecs_postfix:
 	  clrtyp_typespec {
 		add_type($1);
 	  }
-	| type_attribute noclass_declspecs
 	| noclass_declmods typespec {
 		add_type($2);
 	  }
-	| noclass_declspecs T_QUAL {
+	| noclass_declspecs_postfix T_QUAL {
 		add_qualifier($2);
 	  }
-	| noclass_declspecs notype_typespec {
+	| noclass_declspecs_postfix notype_typespec {
 		add_type($2);
 	  }
-	| noclass_declspecs type_attribute
+	| noclass_declspecs_postfix type_attribute
 	;
 
 noclass_declmods:



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 04:47:25 UTC 2021

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

Log Message:
lint: merge duplicate code in declmods and declmod

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.278 -r1.279 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.278 src/usr.bin/xlint/lint1/cgram.y:1.279
--- src/usr.bin/xlint/lint1/cgram.y:1.278	Sat Jul 10 04:25:47 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 04:47:25 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.279 2021/07/10 04:47:25 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.279 2021/07/10 04:47:25 rillig Exp $");
 #endif
 
 #include 
@@ -549,23 +549,22 @@ declaration_specifiers:		/* C99 6.7 */
 	;
 
 declmods:
-	  clrtyp T_QUAL {
-		add_qualifier($2);
-	  }
-	| clrtyp T_SCLASS {
-		add_storage_class($2);
-	  }
+	  clrtyp qualifier_or_storage_class
 	| declmods declmod
 	;
 
 declmod:
+	  qualifier_or_storage_class
+	| type_attribute
+	;
+
+qualifier_or_storage_class:
 	  T_QUAL {
 		add_qualifier($1);
 	  }
 	| T_SCLASS {
 		add_storage_class($1);
 	  }
-	| type_attribute
 	;
 
 clrtyp_typespec:



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Jul 10 04:25:47 UTC 2021

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

Log Message:
lint: remove duplicate code for parsing declarations

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 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.277 src/usr.bin/xlint/lint1/cgram.y:1.278
--- src/usr.bin/xlint/lint1/cgram.y:1.277	Fri Jul  9 20:51:27 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 04:25:47 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.277 2021/07/09 20:51:27 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.277 2021/07/09 20:51:27 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $");
 #endif
 
 #include 
@@ -403,26 +403,7 @@ top_level_declaration:		/* C99 6.9 calls
 			warning(1);
 		}
 	  }
-	| declmods deftyp T_SEMI {
-		if (dcs->d_scl == TYPEDEF) {
-			/* typedef declares no type name */
-			warning(72);
-		} else {
-			/* empty declaration */
-			warning(2);
-		}
-	  }
-	| declmods deftyp notype_init_decls T_SEMI
-	| declaration_specifiers deftyp T_SEMI {
-		if (dcs->d_scl == TYPEDEF) {
-			/* typedef declares no type name */
-			warning(72);
-		} else if (!dcs->d_nonempty_decl) {
-			/* empty declaration */
-			warning(2);
-		}
-	  }
-	| declaration_specifiers deftyp type_init_decls T_SEMI
+	| declaration_noerror
 	| error T_SEMI {
 		global_clean_up();
 	  }
@@ -514,6 +495,11 @@ arg_declaration:
 	;
 
 declaration:			/* C99 6.7 */
+	  declaration_noerror
+	| error T_SEMI
+	;
+
+declaration_noerror:		/* see C99 6.7 'declaration' */
 	  declmods deftyp T_SEMI {
 		if (dcs->d_scl == TYPEDEF) {
 			/* typedef declares no type name */
@@ -534,7 +520,6 @@ declaration:			/* C99 6.7 */
 		}
 	  }
 	| declaration_specifiers deftyp type_init_decls T_SEMI
-	| error T_SEMI
 	;
 
 clrtyp:



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul  9 20:51:27 UTC 2021

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

Log Message:
lint: remove 6 conflicts from the grammar, in type_direct_decl

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 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.276 src/usr.bin/xlint/lint1/cgram.y:1.277
--- src/usr.bin/xlint/lint1/cgram.y:1.276	Fri Jul  9 20:36:34 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Jul  9 20:51:27 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.276 2021/07/09 20:36:34 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.277 2021/07/09 20:51:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.276 2021/07/09 20:36:34 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.277 2021/07/09 20:51:27 rillig Exp $");
 #endif
 
 #include 
@@ -123,7 +123,7 @@ anonymize(sym_t *s)
 }
 %}
 
-%expect 156
+%expect 150
 
 %union {
 	val_t	*y_val;
@@ -949,9 +949,12 @@ notype_decl:
 	;
 
 type_decl:
-	  type_direct_decl
-	| pointer type_direct_decl {
-		$$ = add_pointer($2, $1);
+	/* TODO: removing type_attribute_list_opt here removes another 16 conflicts */
+	  type_attribute_list_opt type_direct_decl {
+		$$ = $2;
+	  }
+	| pointer type_attribute_list_opt type_direct_decl {
+		$$ = add_pointer($3, $1);
 	  }
 	;
 
@@ -976,11 +979,6 @@ notype_direct_decl:
 	| notype_direct_decl type_attribute
 	;
 
-/*
- * XXX: shift/reduce conflict, caused by:
- *	type_attribute type_direct_decl
- *	type_direct_decl type_attribute
- */
 type_direct_decl:
 	  identifier {
 		$$ = declarator_name(getsym($1));
@@ -988,9 +986,6 @@ type_direct_decl:
 	| T_LPAREN type_decl T_RPAREN {
 		$$ = $2;
 	  }
-	| type_attribute type_direct_decl {
-		$$ = $2;
-	  }
 	| type_direct_decl T_LBRACK T_RBRACK {
 		$$ = add_array($1, false, 0);
 	  }



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul  9 20:36:34 UTC 2021

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

Log Message:
lint: remove 6 of the remaining 162 conflicts from the grammar

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.275 -r1.276 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.275 src/usr.bin/xlint/lint1/cgram.y:1.276
--- src/usr.bin/xlint/lint1/cgram.y:1.275	Fri Jul  9 06:37:11 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Jul  9 20:36:34 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.275 2021/07/09 06:37:11 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.276 2021/07/09 20:36:34 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.275 2021/07/09 06:37:11 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.276 2021/07/09 20:36:34 rillig Exp $");
 #endif
 
 #include 
@@ -123,7 +123,7 @@ anonymize(sym_t *s)
 }
 %}
 
-%expect 162
+%expect 156
 
 %union {
 	val_t	*y_val;
@@ -939,9 +939,12 @@ type_init_decl:
 	;
 
 notype_decl:
-	  notype_direct_decl
-	| pointer notype_direct_decl {
-		$$ = add_pointer($2, $1);
+	/* TODO: removing type_attribute_list_opt here removes another 18 conflicts */
+	  type_attribute_list_opt notype_direct_decl {
+		$$ = $2;
+	  }
+	| pointer type_attribute_list_opt notype_direct_decl {
+		$$ = add_pointer($3, $1);
 	  }
 	;
 
@@ -952,11 +955,6 @@ type_decl:
 	  }
 	;
 
-/*
- * XXX: shift/reduce conflict, caused by:
- *	type_attribute notype_direct_decl
- *	notype_direct_decl type_attribute
- */
 notype_direct_decl:
 	  T_NAME {
 		$$ = declarator_name(getsym($1));
@@ -964,9 +962,6 @@ notype_direct_decl:
 	| T_LPAREN type_decl T_RPAREN {
 		$$ = $2;
 	  }
-	| type_attribute notype_direct_decl {
-		$$ = $2;
-	  }
 	| notype_direct_decl T_LBRACK T_RBRACK {
 		$$ = add_array($1, false, 0);
 	  }



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

2021-07-09 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Jul  9 06:37:11 UTC 2021

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

Log Message:
lint: indent grammar actions properly

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 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.274 src/usr.bin/xlint/lint1/cgram.y:1.275
--- src/usr.bin/xlint/lint1/cgram.y:1.274	Thu Jul  8 19:08:03 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Jul  9 06:37:11 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.274 2021/07/08 19:08:03 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.275 2021/07/09 06:37:11 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.274 2021/07/08 19:08:03 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.275 2021/07/09 06:37:11 rillig Exp $");
 #endif
 
 #include 
@@ -2012,9 +2012,9 @@ gcc_attribute_list:
 /* https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html */
 gcc_attribute:
 	  T_ATTRIBUTE T_LPAREN T_LPAREN {
-	attron = true;
+		attron = true;
 	  } gcc_attribute_spec_list {
-	attron = false;
+		attron = false;
 	  } T_RPAREN T_RPAREN
 	;
 



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

2021-07-08 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Jul  8 19:08:03 UTC 2021

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

Log Message:
lint: fix assignment to midrule in grammar (since today)

When compiling the grammar with Bison, it complains:

error: $$ for the midrule at $2 of 'struct' has no declared type

Yacc does not complain, instead it assumes that a midrule has the same
type as the rule itself.

The assignment '$$ = $1' in the midrule action does not influence the $$
of the whole rule, it only assigns to $2.  The assignment to $$ was done
via the default action, therefore everything worked as expected.  Any
missing assignment in this rule would have been caught quickly by the
strict assertion in mktag.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.273 -r1.274 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.273 src/usr.bin/xlint/lint1/cgram.y:1.274
--- src/usr.bin/xlint/lint1/cgram.y:1.273	Thu Jul  8 18:53:57 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Jul  8 19:08:03 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.273 2021/07/08 18:53:57 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.274 2021/07/08 19:08:03 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.273 2021/07/08 18:53:57 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.274 2021/07/08 19:08:03 rillig Exp $");
 #endif
 
 #include 
@@ -649,7 +649,6 @@ struct:
 		begin_declaration_level($1 == STRUCT ? MOS : MOU);
 		dcs->d_offset = 0;
 		dcs->d_sou_align_in_bits = CHAR_SIZE;
-		$$ = $1;
 	  } type_attribute_list_opt
 	;
 



  1   2   3   4   5   6   7   8   >