Module Name: src
Committed By: rillig
Date: Sun Apr 3 10:05:23 UTC 2022
Modified Files:
src/tests/usr.bin/xlint/lint1: decl.c decl.exp
src/usr.bin/xlint/lint1: decl.c
Log Message:
lint: fix crash after syntax error in array declaration
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/decl.exp
cvs rdiff -u -r1.267 -r1.268 src/usr.bin/xlint/lint1/decl.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/decl.c
diff -u src/tests/usr.bin/xlint/lint1/decl.c:1.12 src/tests/usr.bin/xlint/lint1/decl.c:1.13
--- src/tests/usr.bin/xlint/lint1/decl.c:1.12 Sun Jul 25 22:03:42 2021
+++ src/tests/usr.bin/xlint/lint1/decl.c Sun Apr 3 10:05:23 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.12 2021/07/25 22:03:42 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.13 2022/04/03 10:05:23 rillig Exp $ */
# 3 "decl.c"
/*
@@ -170,3 +170,11 @@ static
cover_func_declarator(void)
{
}
+
+/*
+ * Before decl.c 1.268 from 2022-04-03, lint ran into an assertion failure for
+ * "elsz > 0" in 'length'.
+ */
+/* expect+2: error: syntax error 'goto' [249] */
+/* expect+1: warning: empty array declaration: void_array_error [190] */
+void void_array_error[] goto;
Index: src/tests/usr.bin/xlint/lint1/decl.exp
diff -u src/tests/usr.bin/xlint/lint1/decl.exp:1.8 src/tests/usr.bin/xlint/lint1/decl.exp:1.9
--- src/tests/usr.bin/xlint/lint1/decl.exp:1.8 Sun Jul 25 22:03:42 2021
+++ src/tests/usr.bin/xlint/lint1/decl.exp Sun Apr 3 10:05:23 2022
@@ -11,5 +11,7 @@ decl.c(72): warning: converting 'pointer
decl.c(80): error: syntax error '"' [249]
decl.c(163): error: syntax error 'int' [249]
decl.c(166): error: syntax error 'int' [249]
+decl.c(180): error: syntax error 'goto' [249]
decl.c(114): warning: static function unused unused [236]
decl.c(170): warning: static function cover_func_declarator unused [236]
+decl.c(180): warning: empty array declaration: void_array_error [190]
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.267 src/usr.bin/xlint/lint1/decl.c:1.268
--- src/usr.bin/xlint/lint1/decl.c:1.267 Sat Apr 2 22:38:45 2022
+++ src/usr.bin/xlint/lint1/decl.c Sun Apr 3 10:05:22 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.267 2022/04/02 22:38:45 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.268 2022/04/03 10:05:22 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.267 2022/04/02 22:38:45 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.268 2022/04/03 10:05:22 rillig Exp $");
#endif
#include <sys/param.h>
@@ -873,6 +873,14 @@ length(const type_t *tp, const char *nam
/* FALLTHROUGH */
default:
elsz = size_in_bits(tp->t_tspec);
+ /*
+ * Workaround until the type parser (see add_function,
+ * add_array, add_pointer) does not construct the invalid
+ * intermediate declaration 'void b[4]' for the legitimate
+ * declaration 'void *b[4]'.
+ */
+ if (sytxerr > 0 && elsz == 0)
+ elsz = CHAR_SIZE;
lint_assert(elsz > 0);
break;
}
@@ -1328,6 +1336,23 @@ block_derive_array(type_t *stp, bool dim
tp = block_derive_type(stp, ARRAY);
tp->t_dim = len;
+#if 0
+ /*
+ * As of 2022-04-03, the implementation of the type parser (see
+ * add_function, add_array, add_pointer) is strange. When it sees
+ * the type 'void *b[4]', it first creates 'void b[4]' and only later
+ * inserts the '*' in the middle of the type. Once created, a type
+ * should not be modified anymore.
+ *
+ * Since the intermediate type would be an array of void, but the
+ * final type is valid, this check cannot be enabled yet.
+ */
+ if (stp->t_tspec == VOID) {
+ /* array of incomplete type */
+ error(301);
+ tp->t_subt = gettyp(CHAR);
+ }
+#endif
if (len < 0) {
/* negative array dimension (%d) */
error(20, len);