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: improve initialization of arrays w...
details: https://anonhg.NetBSD.org/src/rev/99d73fb69e43
branches: trunk
changeset: 953955:99d73fb69e43
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Mar 25 22:15:38 2021 +0000
description:
lint: improve initialization of arrays with designators
Initialization is still buggy but better than before. The remaining bug
is that only the first designator determines the array size, and after
that, the array is no longer considered of unknown size. This
contradicts C99. More improvements to come.
diffstat:
tests/usr.bin/xlint/lint1/msg_168.c | 4 ++--
tests/usr.bin/xlint/lint1/msg_168.exp | 4 ++--
usr.bin/xlint/lint1/init.c | 21 +++++++++++++++++++--
3 files changed, 23 insertions(+), 6 deletions(-)
diffs (79 lines):
diff -r 00accbf47850 -r 99d73fb69e43 tests/usr.bin/xlint/lint1/msg_168.c
--- a/tests/usr.bin/xlint/lint1/msg_168.c Thu Mar 25 21:51:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_168.c Thu Mar 25 22:15:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_168.c,v 1.3 2021/03/07 16:40:20 rillig Exp $ */
+/* $NetBSD: msg_168.c,v 1.4 2021/03/25 22:15:38 rillig Exp $ */
# 3 "msg_168.c"
// Test for message: array subscript cannot be > %d: %ld [168]
@@ -9,7 +9,7 @@
void
example(void)
{
- char buf[20] = {};
+ char buf[20] = {}; /* empty initializer is a GCC extension */
print_string(buf + 19); /* inside the array */
diff -r 00accbf47850 -r 99d73fb69e43 tests/usr.bin/xlint/lint1/msg_168.exp
--- a/tests/usr.bin/xlint/lint1/msg_168.exp Thu Mar 25 21:51:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_168.exp Thu Mar 25 22:15:38 2021 +0000
@@ -1,3 +1,3 @@
msg_168.c(28): warning: array subscript cannot be > 19: 20 [168]
-msg_168.c(40): warning: array subscript cannot be > 2: 57 [168]
-msg_168.c(41): warning: array subscript cannot be > 2: 58 [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]
diff -r 00accbf47850 -r 99d73fb69e43 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Thu Mar 25 21:51:55 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Thu Mar 25 22:15:38 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.131 2021/03/25 21:51:55 rillig Exp $ */
+/* $NetBSD: init.c,v 1.132 2021/03/25 22:15:38 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.131 2021/03/25 21:51:55 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.132 2021/03/25 22:15:38 rillig Exp $");
#endif
#include <stdlib.h>
@@ -517,9 +517,21 @@
void
designation_add_subscript(range_t range)
{
+ initstack_element *istk;
+
debug_enter();
debug_step("subscript range is %zu ... %zu", range.lo, range.hi);
debug_initstack();
+
+ istk = initstk_lvalue;
+ if (istk->i_array_of_unknown_size) {
+ int auto_dim = (int)(range.hi + 1);
+ 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;
+ }
+ }
+
debug_leave();
}
@@ -1280,6 +1292,11 @@
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