Module Name: src
Committed By: rillig
Date: Sun Feb 21 14:19:27 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c
src/usr.bin/xlint/common: tyname.c
src/usr.bin/xlint/lint1: init.c
Log Message:
lint: add debug logging for initializing an array of unknown size
It is possible that the type name 'array[unknown_size]' may spill into
the user-visible diagnostics. The current test suite does not cover
such a case. Anyway, saying 'array[unknown_size]' is still better than
saying 'array[0]', which would be misleading.
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.84 -r1.85 src/usr.bin/xlint/lint1/init.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.5 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.6
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.5 Sun Feb 21 13:10:57 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c Sun Feb 21 14:19:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_init.c,v 1.5 2021/02/21 13:10:57 rillig Exp $ */
+/* $NetBSD: d_c99_init.c,v 1.6 2021/02/21 14:19:27 rillig Exp $ */
# 3 "d_c99_init.c"
/*
@@ -50,3 +50,6 @@ initialization_with_redundant_braces(any
// FIXME: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".
use(&arg);
}
+
+// See initstack_push, 'extending array of unknown size'.
+const int primes[] = { 2, 3, 5, 7, 9 };
Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.30 src/usr.bin/xlint/common/tyname.c:1.31
--- src/usr.bin/xlint/common/tyname.c:1.30 Sun Feb 21 10:28:32 2021
+++ src/usr.bin/xlint/common/tyname.c Sun Feb 21 14:19:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $ */
+/* $NetBSD: tyname.c,v 1.31 2021/02/21 14:19:27 rillig Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.31 2021/02/21 14:19:27 rillig Exp $");
#endif
#include <limits.h>
@@ -366,7 +366,14 @@ type_name(const type_t *tp)
buf_add(&buf, " of ");
buf_add(&buf, type_name(tp->t_subt));
buf_add(&buf, "[");
+#ifdef t_str /* lint1 */
+ if (tp->t_incomplete_array)
+ buf_add(&buf, "unknown_size");
+ else
+ buf_add_int(&buf, tp->t_dim);
+#else
buf_add_int(&buf, tp->t_dim);
+#endif
buf_add(&buf, "]");
break;
case FUNC:
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.84 src/usr.bin/xlint/lint1/init.c:1.85
--- src/usr.bin/xlint/lint1/init.c:1.84 Sun Feb 21 14:02:36 2021
+++ src/usr.bin/xlint/lint1/init.c Sun Feb 21 14:19:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.84 2021/02/21 14:02:36 rillig Exp $ */
+/* $NetBSD: init.c,v 1.85 2021/02/21 14:19:27 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.84 2021/02/21 14:02:36 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.85 2021/02/21 14:19:27 rillig Exp $");
#endif
#include <stdlib.h>
@@ -466,16 +466,18 @@ initstack_push(void)
/* Extend an incomplete array type by one element */
if (istk->i_remaining == 0) {
- debug_step("(extend) %s", type_name(istk->i_type));
/*
* Inside of other aggregate types must not be an incomplete
* type.
*/
lint_assert(istk->i_enclosing->i_enclosing == NULL);
- istk->i_remaining = 1;
lint_assert(istk->i_type->t_tspec == ARRAY);
+ debug_step("extending array of unknown size '%s'",
+ type_name(istk->i_type));
+ istk->i_remaining = 1;
istk->i_type->t_dim++;
setcomplete(istk->i_type, true);
+ debug_step("extended type is '%s'", type_name(istk->i_type));
}
lint_assert(istk->i_remaining > 0);