Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: fix initialization for arrays with...
details: https://anonhg.NetBSD.org/src/rev/97b354397ff6
branches: trunk
changeset: 981909:97b354397ff6
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Mar 25 22:53:05 2021 +0000
description:
lint: fix initialization for arrays with designators
>From the previous commit, there was an off-by-one error left, which was
due to the interaction between designation_add_subscript and
extend_if_array_of_unknown_size.
The other crucial point was to call initstack_pop_nobrace before
accessing the "current initialization stack element". Without this
call, in msg_168.c the "current element" would point to the initializer
level for 'const char *' instead of the one for 'array of const char *'.
One more step towards supporting C99.
diffstat:
tests/usr.bin/xlint/lint1/msg_168.c | 4 ++--
tests/usr.bin/xlint/lint1/msg_168.exp | 3 +--
usr.bin/xlint/lint1/init.c | 22 ++++++++++++++--------
3 files changed, 17 insertions(+), 12 deletions(-)
diffs (91 lines):
diff -r 608726fda378 -r 97b354397ff6 tests/usr.bin/xlint/lint1/msg_168.c
--- a/tests/usr.bin/xlint/lint1/msg_168.c Thu Mar 25 22:15:38 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_168.c Thu Mar 25 22:53:05 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_168.c,v 1.4 2021/03/25 22:15:38 rillig Exp $ */
+/* $NetBSD: msg_168.c,v 1.5 2021/03/25 22:53:05 rillig Exp $ */
# 3 "msg_168.c"
// Test for message: array subscript cannot be > %d: %ld [168]
@@ -37,6 +37,6 @@
['9'] = "IX"
};
- print_string(to_roman['9']); /*FIXME*//* expect: 168 */
+ print_string(to_roman['9']);
print_string(to_roman[':']); /* expect: 168 */
}
diff -r 608726fda378 -r 97b354397ff6 tests/usr.bin/xlint/lint1/msg_168.exp
--- a/tests/usr.bin/xlint/lint1/msg_168.exp Thu Mar 25 22:15:38 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_168.exp Thu Mar 25 22:53:05 2021 +0000
@@ -1,3 +1,2 @@
msg_168.c(28): warning: array subscript cannot be > 19: 20 [168]
-msg_168.c(40): warning: array subscript cannot be > 51: 57 [168]
-msg_168.c(41): warning: array subscript cannot be > 51: 58 [168]
+msg_168.c(41): warning: array subscript cannot be > 57: 58 [168]
diff -r 608726fda378 -r 97b354397ff6 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Thu Mar 25 22:15:38 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Thu Mar 25 22:53:05 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.132 2021/03/25 22:15:38 rillig Exp $ */
+/* $NetBSD: init.c,v 1.133 2021/03/25 22:53:05 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.132 2021/03/25 22:15:38 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.133 2021/03/25 22:53:05 rillig Exp $");
#endif
#include <stdlib.h>
@@ -497,6 +497,9 @@
debug_designation();
}
+/* TODO: Move the function body up here, to avoid the forward declaration. */
+static void initstack_pop_nobrace(void);
+
/*
* A sub-object of an array is initialized using a designator. This does not
* have to be an array element directly, it can also be used to initialize
@@ -523,9 +526,12 @@
debug_step("subscript range is %zu ... %zu", range.lo, range.hi);
debug_initstack();
+ initstack_pop_nobrace();
+
istk = initstk_lvalue;
if (istk->i_array_of_unknown_size) {
- int auto_dim = (int)(range.hi + 1);
+ /* No +1 here, extend_if_array_of_unknown_size will add it. */
+ int auto_dim = (int)range.hi;
if (auto_dim > istk->i_type->t_dim) {
debug_step("setting the array size to %d", auto_dim);
istk->i_type->t_dim = auto_dim;
@@ -734,6 +740,11 @@
if (istk->i_remaining != 0)
return;
+ /*
+ * XXX: According to the function name, there should be a 'return' if
+ * i_array_of_unknown_size is false. There's probably a test missing
+ * for that case.
+ */
/*
* The only place where an incomplete array may appear is at the
@@ -1292,11 +1303,6 @@
len = strg->st_len;
if (istk->i_array_of_unknown_size) {
- /*
- * FIXME: C99 6.7.8p22 explicitly says that only "at the end
- * of its initializer list, the array no longer has incomplete
- * type".
- */
istk->i_array_of_unknown_size = false;
istk->i_type->t_dim = len + 1;
setcomplete(istk->i_type, true);
Home |
Main Index |
Thread Index |
Old Index