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: do not error out of a struct is in...
details: https://anonhg.NetBSD.org/src/rev/57db8b7466d1
branches: trunk
changeset: 982115:57db8b7466d1
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Apr 01 14:20:30 2021 +0000
description:
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.
diffstat:
tests/usr.bin/xlint/lint1/d_c99_init.c | 6 +++---
tests/usr.bin/xlint/lint1/d_c99_init.exp | 1 -
usr.bin/xlint/lint1/init.c | 18 +++++++++---------
3 files changed, 12 insertions(+), 13 deletions(-)
diffs (94 lines):
diff -r df1be5e6047b -r 57db8b7466d1 tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c Thu Apr 01 10:35:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c Thu Apr 01 14:20:30 2021 +0000
@@ -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 @@
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] = {
diff -r df1be5e6047b -r 57db8b7466d1 tests/usr.bin/xlint/lint1/d_c99_init.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_init.exp Thu Apr 01 10:35:24 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.exp Thu Apr 01 14:20:30 2021 +0000
@@ -9,7 +9,6 @@
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]
diff -r df1be5e6047b -r 57db8b7466d1 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Thu Apr 01 10:35:24 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Thu Apr 01 14:20:30 2021 +0000
@@ -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 @@
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 @@
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 @@
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 @@
* 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;
}
Home |
Main Index |
Thread Index |
Old Index