Module Name: src
Committed By: rillig
Date: Thu Apr 1 14:20:30 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp
src/usr.bin/xlint/lint1: init.c
Log Message:
lint: do not error out of a struct is initialized without braces
This allows to process lib/libc/gen/sysctl.c 1.38 from 2021-03-30, as
well as its precedessor 1.37, which had a workaround just for lint.
While unusual, C99 allows these.
To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.23 -r1.24 src/tests/usr.bin/xlint/lint1/d_c99_init.exp
cvs rdiff -u -r1.184 -r1.185 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.29 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.30
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.29 Tue Mar 30 19:45:04 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c Thu Apr 1 14:20:30 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_init.c,v 1.29 2021/03/30 19:45:04 rillig Exp $ */
+/* $NetBSD: d_c99_init.c,v 1.30 2021/04/01 14:20:30 rillig Exp $ */
# 3 "d_c99_init.c"
/*
@@ -275,8 +275,8 @@ int c99_6_7_8_p27_example4[4][3] = {
struct {
int a[3], b;
} c99_6_7_8_p28_example5[] = {
- { 1 },
- 2, /* XXX *//* expect: cannot initialize */
+ { 1 }, /* just parsed, not checked in detail */
+ 2, /* just parsed, not checked in detail */
};
short c99_6_7_8_p29_example6a[4][3][2] = {
Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.23 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.24
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.23 Tue Mar 30 19:45:04 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp Thu Apr 1 14:20:30 2021
@@ -9,7 +9,6 @@ d_c99_init.c(221): error: array subscrip
d_c99_init.c(230): error: too many struct/union initializers [172]
d_c99_init.c(236): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
d_c99_init.c(240): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
-d_c99_init.c(279): error: cannot initialize 'struct <unnamed>' from 'int' [185]
d_c99_init.c(321): error: duplicate case in switch: 0 [199]
d_c99_init.c(330): error: type 'struct point' does not have member 'r' [101]
d_c99_init.c(337): error: type 'struct point' does not have member 'r' [101]
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.184 src/usr.bin/xlint/lint1/init.c:1.185
--- src/usr.bin/xlint/lint1/init.c:1.184 Tue Mar 30 20:23:30 2021
+++ src/usr.bin/xlint/lint1/init.c Thu Apr 1 14:20:30 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.184 2021/03/30 20:23:30 rillig Exp $ */
+/* $NetBSD: init.c,v 1.185 2021/04/01 14:20:30 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.184 2021/03/30 20:23:30 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.185 2021/04/01 14:20:30 rillig Exp $");
#endif
#include <stdlib.h>
@@ -126,7 +126,7 @@ struct brace_level {
size_t bl_array_next_subscript;
bool bl_array_of_unknown_size: 1;
bool bl_scalar_done: 1; /* for scalars */
- bool bl_omitted_braces: 1; /* skip further checks */
+ bool bl_confused: 1; /* skip further checks */
struct designation bl_designation; /* .member[123].member */
struct brace_level *bl_enclosing;
};
@@ -608,8 +608,7 @@ static const type_t *
brace_level_sub_type_array(const struct brace_level *bl)
{
- if (!bl->bl_type->t_incomplete_array &&
- !bl->bl_omitted_braces &&
+ if (!bl->bl_confused && !bl->bl_type->t_incomplete_array &&
bl->bl_array_next_subscript >= (size_t)bl->bl_type->t_dim) {
/* too many array initializers, expected %d */
error(173, bl->bl_type->t_dim);
@@ -939,7 +938,7 @@ initialization_expr(struct initializatio
return;
bl = in->in_brace_level;
- if (bl != NULL && bl->bl_omitted_braces)
+ if (bl != NULL && bl->bl_confused)
return;
debug_enter();
@@ -967,12 +966,13 @@ initialization_expr(struct initializatio
* Hack to accept initializations with omitted braces, see
* c99_6_7_8_p28_example5 in test d_c99_init.c. Since both GCC and
* Clang already warn about this at level -Wall, there is no point
- * in letting lint check this again.
+ * in repeating the same check in lint. If needed, support for these
+ * edge cases could be added, but that would increase the complexity.
*/
if (is_scalar(tn->tn_type->t_tspec) &&
- tp->t_tspec == ARRAY &&
+ (tp->t_tspec == ARRAY || is_struct_or_union(tp->t_tspec)) &&
bl != NULL) {
- bl->bl_omitted_braces = true;
+ bl->bl_confused = true;
goto done;
}