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 of unnamed unio...



details:   https://anonhg.NetBSD.org/src/rev/6fd259b7d1bc
branches:  trunk
changeset: 377211:6fd259b7d1bc
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 01 06:09:24 2023 +0000

description:
lint: fix initialization of unnamed union member

diffstat:

 tests/usr.bin/xlint/lint1/init_braces.c |   7 +++----
 usr.bin/xlint/lint1/externs1.h          |   3 ++-
 usr.bin/xlint/lint1/init.c              |  18 +++---------------
 usr.bin/xlint/lint1/tree.c              |   6 +++---
 4 files changed, 11 insertions(+), 23 deletions(-)

diffs (118 lines):

diff -r 8086d8bdf99e -r 6fd259b7d1bc tests/usr.bin/xlint/lint1/init_braces.c
--- a/tests/usr.bin/xlint/lint1/init_braces.c   Fri Jun 30 23:36:47 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/init_braces.c   Sat Jul 01 06:09:24 2023 +0000
@@ -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 -r 8086d8bdf99e -r 6fd259b7d1bc usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Fri Jun 30 23:36:47 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Jul 01 06:09:24 2023 +0000
@@ -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 *, bo
 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 -r 8086d8bdf99e -r 6fd259b7d1bc usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Fri Jun 30 23:36:47 2023 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sat Jul 01 06:09:24 2023 +0000
@@ -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(ini
        }
 
 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 -r 8086d8bdf99e -r 6fd259b7d1bc usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Jun 30 23:36:47 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jul 01 06:09:24 2023 +0000
@@ -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;



Home | Main Index | Thread Index | Old Index