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: properly initialize unnamed struct...



details:   https://anonhg.NetBSD.org/src/rev/7dafc71482ae
branches:  trunk
changeset: 377516:7dafc71482ae
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 15 15:38:03 2023 +0000

description:
lint: properly initialize unnamed struct/union members

Previously, their 'containing type' was not initialized.  The code for
initializing them is adapted from declarator_name.

diffstat:

 usr.bin/xlint/lint1/decl.c |  9 +++++----
 usr.bin/xlint/lint1/tree.c |  6 ++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diffs (58 lines):

diff -r d5796ddc6247 -r 7dafc71482ae usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jul 15 14:54:31 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jul 15 15:38:03 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.358 2023/07/15 13:35:24 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.359 2023/07/15 15:38:03 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.358 2023/07/15 13:35:24 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.359 2023/07/15 15:38:03 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1045,9 +1045,10 @@ declare_unnamed_member(void)
        sym_t *mem = block_zero_alloc(sizeof(*mem), "sym");
        mem->s_name = unnamed;
        mem->s_kind = FMEMBER;
-       mem->s_scl = STRUCT_MEMBER;
+       mem->s_scl = dcs->d_kind == DLK_STRUCT ? STRUCT_MEMBER : UNION_MEMBER;
+       mem->s_block_level = -1;
        mem->s_type = dcs->d_type;
-       mem->s_block_level = -1;
+       mem->u.s_member.sm_containing_type = dcs->d_tag_type->t_sou;
 
        dcs_add_member(mem);
        suppress_bitfieldtype = false;
diff -r d5796ddc6247 -r 7dafc71482ae usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jul 15 14:54:31 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jul 15 15:38:03 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.571 2023/07/15 14:54:31 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.572 2023/07/15 15:38:03 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.571 2023/07/15 14:54:31 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.572 2023/07/15 15:38:03 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1875,6 +1875,8 @@ find_member(const type_t *tp, const char
 {
        for (sym_t *mem = tp->t_sou->sou_first_member;
             mem != NULL; mem = mem->s_next) {
+               lint_assert(is_member(mem));
+               lint_assert(mem->u.s_member.sm_containing_type == tp->t_sou);
                if (strcmp(mem->s_name, name) == 0)
                        return mem;
        }



Home | Main Index | Thread Index | Old Index