diff options
| author | rillig <rillig@NetBSD.org> | 2023-07-01 06:09:24 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-07-01 06:09:24 +0000 |
| commit | 1a25258bf644fbb8b7ffc0aba7b345f87a14ebfa (patch) | |
| tree | c246bcfc2c145b3bd0c254bd5bcd07a31d438df5 | |
| parent | 1d123bfcd7076836e1bfeef9542d2ddb0bd4ffd7 (diff) | |
lint: fix initialization of unnamed union member
| -rw-r--r-- | tests/usr.bin/xlint/lint1/init_braces.c | 7 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/externs1.h | 3 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/init.c | 18 | ||||
| -rw-r--r-- | usr.bin/xlint/lint1/tree.c | 6 |
4 files changed, 11 insertions, 23 deletions
diff --git a/tests/usr.bin/xlint/lint1/init_braces.c b/tests/usr.bin/xlint/lint1/init_braces.c index 84868b586be..9f5821ddda7 100644 --- a/tests/usr.bin/xlint/lint1/init_braces.c +++ b/tests/usr.bin/xlint/lint1/init_braces.c @@ -1,4 +1,4 @@ -/* $NetBSD: init_braces.c,v 1.6 2023/06/30 22:27:47 rillig Exp $ */ +/* $NetBSD: init_braces.c,v 1.7 2023/07/01 06:09:24 rillig Exp $ */ # 3 "init_braces.c" /* @@ -97,7 +97,8 @@ init_anonymous_struct_and_union(void) return var.times.t0.ns; } -// Minimized example taken from jemalloc.c, init_lock. +// Initializers may designate members from unnamed struct/union members. +// Example code adapted from jemalloc 5.1.0, jemalloc.c, init_lock. unsigned char init_unnamed_union(void) { @@ -121,8 +122,6 @@ init_unnamed_union(void) { .padded_union = { .pad1 = { 0, 0, 0 }, -/* FIXME: Allow access to unnamed struct/union members. */ -/* expect+1: error: type 'struct padded_union' does not have member 'u1' [101] */ .u1 = 0, .pad2 = { 0, 0, 0 }, }, diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index d5d0a5900dc..d68dfce3cec 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.183 2023/06/30 21:39:54 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.184 2023/07/01 06:09:24 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -275,6 +275,7 @@ void check_expr_misc(const tnode_t *, bool, bool, bool, bool, bool, bool); bool constant_addr(const tnode_t *, const sym_t **, ptrdiff_t *); strg_t *cat_strings(strg_t *, strg_t *); unsigned int type_size_in_bits(const type_t *); +sym_t *find_member(const type_t *, const char *); void begin_statement_expr(void); void do_statement_expr(tnode_t *); diff --git a/usr.bin/xlint/lint1/init.c b/usr.bin/xlint/lint1/init.c index ba7e7d5475f..e0c676bded1 100644 --- a/usr.bin/xlint/lint1/init.c +++ b/usr.bin/xlint/lint1/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.243 2023/06/30 21:06:18 rillig Exp $ */ +/* $NetBSD: init.c,v 1.244 2023/07/01 06:09:24 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: init.c,v 1.243 2023/06/30 21:06:18 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.244 2023/07/01 06:09:24 rillig Exp $"); #endif #include <stdlib.h> @@ -234,18 +234,6 @@ first_named_member(const type_t *tp) return skip_unnamed(tp->t_sou->sou_first_member); } -static const sym_t * -look_up_member(const type_t *tp, const char *name) -{ - const sym_t *m; - - lint_assert(is_struct_or_union(tp->t_tspec)); - for (m = tp->t_sou->sou_first_member; m != NULL; m = m->s_next) - if (strcmp(m->s_name, name) == 0) - return m; - return NULL; -} - /* * C99 6.7.8p22 says that the type of an array of unknown size becomes known * at the end of its initializer list. @@ -862,7 +850,7 @@ initialization_add_designator_member(initialization *in, const char *name) } proceed:; - const sym_t *member = look_up_member(tp, name); + const sym_t *member = find_member(tp, name); if (member == NULL) { /* type '%s' does not have member '%s' */ error(101, type_name(tp), name); diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 3ae9af04d48..cd3dbef3c39 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.538 2023/06/30 21:39:54 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.539 2023/07/01 06:09:24 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tree.c,v 1.538 2023/06/30 21:39:54 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.539 2023/07/01 06:09:24 rillig Exp $"); #endif #include <float.h> @@ -1882,7 +1882,7 @@ all_members_compatible(const sym_t *msym) return true; } -static sym_t * +sym_t * find_member(const type_t *tp, const char *name) { for (sym_t *mem = tp->t_sou->sou_first_member; |
