Module Name: src Committed By: rillig Date: Sat Mar 9 13:20:55 UTC 2024
Modified Files: src/usr.bin/xlint/common: tyname.c src/usr.bin/xlint/lint1: debug.c decl.c emit1.c func.c init.c lint1.h tree.c Log Message: lint: inline accessor macros for type_t To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 src/usr.bin/xlint/common/tyname.c cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.395 -r1.396 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.90 -r1.91 src/usr.bin/xlint/lint1/emit1.c cvs rdiff -u -r1.182 -r1.183 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.261 -r1.262 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.219 -r1.220 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.610 -r1.611 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/xlint/common/tyname.c diff -u src/usr.bin/xlint/common/tyname.c:1.61 src/usr.bin/xlint/common/tyname.c:1.62 --- src/usr.bin/xlint/common/tyname.c:1.61 Fri Feb 2 16:25:58 2024 +++ src/usr.bin/xlint/common/tyname.c Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tyname.c,v 1.61 2024/02/02 16:25:58 rillig Exp $ */ +/* $NetBSD: tyname.c,v 1.62 2024/03/09 13:20:55 rillig Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: tyname.c,v 1.61 2024/02/02 16:25:58 rillig Exp $"); +__RCSID("$NetBSD: tyname.c,v 1.62 2024/03/09 13:20:55 rillig Exp $"); #endif #include <assert.h> @@ -165,7 +165,7 @@ type_name_of_function(buffer *buf, const buf_add(buf, "("); if (tp->t_proto) { #if IS_LINT1 - const sym_t *param = tp->t_params; + const sym_t *param = tp->u.params; if (param == NULL) buf_add(buf, "void"); for (; param != NULL; param = param->s_next) { @@ -197,12 +197,12 @@ type_name_of_struct_or_union(buffer *buf { buf_add(buf, " "); #if IS_LINT1 - if (tp->t_sou->sou_tag->s_name == unnamed && - tp->t_sou->sou_first_typedef != NULL) { + if (tp->u.sou->sou_tag->s_name == unnamed && + tp->u.sou->sou_first_typedef != NULL) { buf_add(buf, "typedef "); - buf_add(buf, tp->t_sou->sou_first_typedef->s_name); + buf_add(buf, tp->u.sou->sou_first_typedef->s_name); } else { - buf_add(buf, tp->t_sou->sou_tag->s_name); + buf_add(buf, tp->u.sou->sou_tag->s_name); } #else buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name); @@ -214,12 +214,12 @@ type_name_of_enum(buffer *buf, const typ { buf_add(buf, " "); #if IS_LINT1 - if (tp->t_enum->en_tag->s_name == unnamed && - tp->t_enum->en_first_typedef != NULL) { + if (tp->u.enumer->en_tag->s_name == unnamed && + tp->u.enumer->en_first_typedef != NULL) { buf_add(buf, "typedef "); - buf_add(buf, tp->t_enum->en_first_typedef->s_name); + buf_add(buf, tp->u.enumer->en_first_typedef->s_name); } else { - buf_add(buf, tp->t_enum->en_tag->s_name); + buf_add(buf, tp->u.enumer->en_tag->s_name); } #else buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name); @@ -234,7 +234,7 @@ type_name_of_array(buffer *buf, const ty if (tp->t_incomplete_array) buf_add(buf, "unknown_size"); else - buf_add_int(buf, tp->t_dim); + buf_add_int(buf, tp->u.dimension); #else buf_add_int(buf, tp->t_dim); #endif @@ -263,7 +263,7 @@ type_name(const type_t *tp) buf_add(&buf, "volatile "); #if IS_LINT1 - if (is_struct_or_union(t) && tp->t_sou->sou_incomplete) + if (is_struct_or_union(t) && tp->u.sou->sou_incomplete) buf_add(&buf, "incomplete "); #endif buf_add(&buf, tspec_name(t)); Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.71 src/usr.bin/xlint/lint1/debug.c:1.72 --- src/usr.bin/xlint/lint1/debug.c:1.71 Mon Feb 5 23:11:22 2024 +++ src/usr.bin/xlint/lint1/debug.c Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.71 2024/02/05 23:11:22 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.72 2024/03/09 13:20:55 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.71 2024/02/05 23:11:22 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.72 2024/03/09 13:20:55 rillig Exp $"); #endif #include <stdlib.h> @@ -156,10 +156,10 @@ debug_type_details(const type_t *tp) if (is_struct_or_union(tp->t_tspec)) { debug_indent_inc(); debug_step("size %u bits, align %u bits, %s", - tp->t_sou->sou_size_in_bits, tp->t_sou->sou_align_in_bits, - tp->t_sou->sou_incomplete ? "incomplete" : "complete"); + tp->u.sou->sou_size_in_bits, tp->u.sou->sou_align_in_bits, + tp->u.sou->sou_incomplete ? "incomplete" : "complete"); - for (const sym_t *mem = tp->t_sou->sou_first_member; + for (const sym_t *mem = tp->u.sou->sou_first_member; mem != NULL; mem = mem->s_next) { debug_sym("", mem, "\n"); debug_type_details(mem->s_type); @@ -168,7 +168,7 @@ debug_type_details(const type_t *tp) } if (tp->t_is_enum) { debug_indent_inc(); - for (const sym_t *en = tp->t_enum->en_first_enumerator; + for (const sym_t *en = tp->u.enumer->en_first_enumerator; en != NULL; en = en->s_next) { debug_sym("", en, "\n"); } Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.395 src/usr.bin/xlint/lint1/decl.c:1.396 --- src/usr.bin/xlint/lint1/decl.c:1.395 Sat Mar 9 10:41:11 2024 +++ src/usr.bin/xlint/lint1/decl.c Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.395 2024/03/09 10:41:11 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.396 2024/03/09 13:20:55 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.395 2024/03/09 10:41:11 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.396 2024/03/09 13:20:55 rillig Exp $"); #endif #include <sys/param.h> @@ -146,8 +146,8 @@ expr_unqualified_type(const type_t *tp) * In case of a struct or union type, the members should lose their * qualifiers as well, but that would require a deep copy of the struct * or union type. This in turn would defeat the type comparison in - * types_compatible, which simply tests whether tp1->t_sou == - * tp2->t_sou. + * types_compatible, which simply tests whether tp1->u.sou == + * tp2->u.sou. */ debug_step("%s '%s'", __func__, type_name(ntp)); @@ -168,9 +168,9 @@ is_incomplete(const type_t *tp) if (t == ARRAY) return tp->t_incomplete_array; if (is_struct_or_union(t)) - return tp->t_sou->sou_incomplete; + return tp->u.sou->sou_incomplete; if (t == ENUM) - return tp->t_enum->en_incomplete; + return tp->u.enumer->en_incomplete; return false; } @@ -406,10 +406,10 @@ set_first_typedef(type_t *tp, sym_t *sym { tspec_t t = tp->t_tspec; - if (is_struct_or_union(t) && tp->t_sou->sou_first_typedef == NULL) - tp->t_sou->sou_first_typedef = sym; - if (t == ENUM && tp->t_enum->en_first_typedef == NULL) - tp->t_enum->en_first_typedef = sym; + if (is_struct_or_union(t) && tp->u.sou->sou_first_typedef == NULL) + tp->u.sou->sou_first_typedef = sym; + if (t == ENUM && tp->u.enumer->en_first_typedef == NULL) + tp->u.enumer->en_first_typedef = sym; } static unsigned int @@ -441,7 +441,7 @@ pack_struct_or_union(type_t *tp) unsigned int bits = 0; bool named = false; - for (const sym_t *mem = tp->t_sou->sou_first_member; + for (const sym_t *mem = tp->u.sou->sou_first_member; mem != NULL; mem = mem->s_next) { // TODO: Maybe update mem->u.s_member.sm_offset_in_bits. if (mem->s_type->t_bitfield) { @@ -455,7 +455,7 @@ pack_struct_or_union(type_t *tp) else if (mem_bits > bits) bits = mem_bits; } - tp->t_sou->sou_size_in_bits = bits; + tp->u.sou->sou_size_in_bits = bits; debug_dcs(); } @@ -748,7 +748,7 @@ length_in_bits(const type_t *tp, const c unsigned int elem = 1; while (tp->t_tspec == ARRAY) { - elem *= tp->t_dim; + elem *= tp->u.dimension; tp = tp->t_subt; } @@ -756,7 +756,7 @@ length_in_bits(const type_t *tp, const c if (is_incomplete(tp) && name != NULL) /* '%s' has incomplete type '%s' */ error(31, name, type_name(tp)); - return (int)(elem * tp->t_sou->sou_size_in_bits); + return (int)(elem * tp->u.sou->sou_size_in_bits); } if (tp->t_tspec == ENUM && is_incomplete(tp) && name != NULL) @@ -790,7 +790,7 @@ alignment_in_bits(const type_t *tp) tspec_t t = tp->t_tspec; unsigned int a; if (is_struct_or_union(t)) - a = tp->t_sou->sou_align_in_bits; + a = tp->u.sou->sou_align_in_bits; else { lint_assert(t != FUNC); if ((a = size_in_bits(t)) == 0) @@ -870,7 +870,7 @@ check_type(sym_t *sym) *tpp = gettyp(INT); return; } - if (t == ARRAY && tp->t_dim == 0) { + if (t == ARRAY && tp->u.dimension == 0) { /* null dimension */ error(17); return; @@ -1050,7 +1050,7 @@ declare_unnamed_member(void) mem->s_scl = dcs->d_kind == DLK_STRUCT ? STRUCT_MEMBER : UNION_MEMBER; mem->s_block_level = -1; mem->s_type = dcs->d_type; - mem->u.s_member.sm_containing_type = dcs->d_tag_type->t_sou; + mem->u.s_member.sm_containing_type = dcs->d_tag_type->u.sou; dcs_add_member(mem); suppress_bitfieldtype = false; @@ -1094,7 +1094,7 @@ declare_member(sym_t *dsym) * type the bit-field is packed in (it's ok) */ int sz = length_in_bits(dsym->s_type, dsym->s_name); - if (sz == 0 && t == ARRAY && dsym->s_type->t_dim == 0) + if (sz == 0 && t == ARRAY && dsym->s_type->u.dimension == 0) /* zero-sized array '%s' in struct requires C99 or later */ c99ism(39, dsym->s_name); @@ -1118,8 +1118,8 @@ set_bit_field_width(sym_t *dsym, int bit dsym->s_scl = STRUCT_MEMBER; dsym->s_type = gettyp(UINT); dsym->s_block_level = -1; - lint_assert(dcs->d_tag_type->t_sou != NULL); - dsym->u.s_member.sm_containing_type = dcs->d_tag_type->t_sou; + lint_assert(dcs->d_tag_type->u.sou != NULL); + dsym->u.s_member.sm_containing_type = dcs->d_tag_type->u.sou; } dsym->s_type = block_dup_type(dsym->s_type); dsym->s_type->t_bitfield = true; @@ -1209,7 +1209,7 @@ block_derive_array(type_t *stp, bool dim { type_t *tp = block_derive_type(stp, ARRAY); - tp->t_dim = len; + tp->u.dimension = len; #if 0 /* @@ -1272,7 +1272,7 @@ block_derive_function(type_t *ret, bool type_t *tp = block_derive_type(ret, FUNC); tp->t_proto = proto; if (proto) - tp->t_params = params; + tp->u.params = params; tp->t_vararg = vararg; debug_step("%s: '%s'", __func__, type_name(tp)); return tp; @@ -1431,7 +1431,7 @@ declarator_name(sym_t *sym) switch (dcs->d_kind) { case DLK_STRUCT: case DLK_UNION: - sym->u.s_member.sm_containing_type = dcs->d_tag_type->t_sou; + sym->u.s_member.sm_containing_type = dcs->d_tag_type->u.sou; sym->s_def = DEF; sc = dcs->d_kind == DLK_STRUCT ? STRUCT_MEMBER : UNION_MEMBER; break; @@ -1638,17 +1638,17 @@ make_tag_type(sym_t *tag, tspec_t kind, if (tp->t_tspec == NO_TSPEC) { tp->t_tspec = kind; if (kind != ENUM) { - tp->t_sou = block_zero_alloc(sizeof(*tp->t_sou), + tp->u.sou = block_zero_alloc(sizeof(*tp->u.sou), "struct_or_union"); - tp->t_sou->sou_align_in_bits = CHAR_SIZE; - tp->t_sou->sou_tag = tag; - tp->t_sou->sou_incomplete = true; + tp->u.sou->sou_align_in_bits = CHAR_SIZE; + tp->u.sou->sou_tag = tag; + tp->u.sou->sou_incomplete = true; } else { tp->t_is_enum = true; - tp->t_enum = block_zero_alloc(sizeof(*tp->t_enum), - "enumeration"); - tp->t_enum->en_tag = tag; - tp->t_enum->en_incomplete = true; + tp->u.enumer = block_zero_alloc( + sizeof(*tp->u.enumer), "enumeration"); + tp->u.enumer->en_tag = tag; + tp->u.enumer->en_incomplete = true; } } debug_printf("%s: '%s'", __func__, type_name(tp)); @@ -1659,7 +1659,7 @@ make_tag_type(sym_t *tag, tspec_t kind, static bool has_named_member(const type_t *tp) { - for (const sym_t *mem = tp->t_sou->sou_first_member; + for (const sym_t *mem = tp->u.sou->sou_first_member; mem != NULL; mem = mem->s_next) { if (mem->s_name != unnamed) return true; @@ -1680,7 +1680,7 @@ complete_struct_or_union(sym_t *first_me dcs_align(dcs->d_sou_align_in_bits, 0); - struct_or_union *sou = tp->t_sou; + struct_or_union *sou = tp->u.sou; sou->sou_align_in_bits = dcs->d_sou_align_in_bits; sou->sou_incomplete = false; sou->sou_first_member = first_member; @@ -1704,8 +1704,8 @@ complete_enum(sym_t *first_enumerator) { type_t *tp = dcs->d_tag_type; - tp->t_enum->en_incomplete = false; - tp->t_enum->en_first_enumerator = first_enumerator; + tp->u.enumer->en_incomplete = false; + tp->u.enumer->en_first_enumerator = first_enumerator; debug_step("%s: '%s'", __func__, type_name(tp)); return tp; } @@ -1832,7 +1832,7 @@ check_old_style_definition(const sym_t * { const sym_t *old_params = rdsym->u.s_old_style_params; - const sym_t *proto_params = dsym->s_type->t_params; + const sym_t *proto_params = dsym->s_type->u.params; bool msg = false; @@ -2137,8 +2137,8 @@ prototypes_compatible(const type_t *tp1, if (tp1->t_vararg != tp2->t_vararg) return false; - const sym_t *p1 = tp1->t_params; - const sym_t *p2 = tp2->t_params; + const sym_t *p1 = tp1->u.params; + const sym_t *p2 = tp2->u.params; for (; p1 != NULL && p2 != NULL; p1 = p1->s_next, p2 = p2->s_next) { if (!types_compatible(p1->s_type, p2->s_type, @@ -2164,7 +2164,7 @@ matches_no_arg_function(const type_t *tp if (tp->t_vararg && dowarn != NULL) *dowarn = true; - for (const sym_t *p = tp->t_params; p != NULL; p = p->s_next) { + for (const sym_t *p = tp->u.params; p != NULL; p = p->s_next) { tspec_t t = p->s_type->t_tspec; if (t == FLOAT || t == CHAR || t == SCHAR || t == UCHAR || @@ -2214,13 +2214,13 @@ types_compatible(const type_t *tp1, cons return false; if (is_struct_or_union(t)) - return tp1->t_sou == tp2->t_sou; + return tp1->u.sou == tp2->u.sou; if (t == ENUM && eflag) - return tp1->t_enum == tp2->t_enum; + return tp1->u.enumer == tp2->u.enumer; - if (t == ARRAY && tp1->t_dim != tp2->t_dim) { - if (tp1->t_dim != 0 && tp2->t_dim != 0) + if (t == ARRAY && tp1->u.dimension != tp2->u.dimension) { + if (tp1->u.dimension != 0 && tp2->u.dimension != 0) return false; } @@ -2267,16 +2267,16 @@ complete_type(sym_t *dsym, sym_t *ssym) lint_assert(src != NULL); lint_assert(dst->t_tspec == src->t_tspec); if (dst->t_tspec == ARRAY) { - if (dst->t_dim == 0 && src->t_dim != 0) { + if (dst->u.dimension == 0 && src->u.dimension != 0) { *dstp = dst = block_dup_type(dst); - dst->t_dim = src->t_dim; + dst->u.dimension = src->u.dimension; dst->t_incomplete_array = false; } } else if (dst->t_tspec == FUNC) { if (!dst->t_proto && src->t_proto) { *dstp = dst = block_dup_type(dst); dst->t_proto = true; - dst->t_params = src->t_params; + dst->u.params = src->u.params; } } dstp = &dst->t_subt; @@ -2472,7 +2472,7 @@ void check_func_old_style_parameters(void) { sym_t *old_params = funcsym->u.s_old_style_params; - sym_t *proto_params = funcsym->s_type->t_params; + sym_t *proto_params = funcsym->s_type->u.params; for (sym_t *arg = old_params; arg != NULL; arg = arg->s_next) { if (arg->s_defparam) { @@ -2795,7 +2795,7 @@ check_size(const sym_t *dsym) dsym->s_type->t_tspec != FUNC && length_in_bits(dsym->s_type, dsym->s_name) == 0 && dsym->s_type->t_tspec == ARRAY && - dsym->s_type->t_dim == 0) { + dsym->s_type->u.dimension == 0) { if (!allow_c90) /* empty array declaration for '%s' */ warning(190, dsym->s_name); @@ -3017,7 +3017,7 @@ check_global_variable_size(const sym_t * curr_pos = cpos; if (len_in_bits == 0 && - sym->s_type->t_tspec == ARRAY && sym->s_type->t_dim == 0) { + sym->s_type->t_tspec == ARRAY && sym->s_type->u.dimension == 0) { /* TODO: C99 6.7.5.2p1 defines this as an error as well. */ if (!allow_c90 || (sym->s_scl == EXTERN && (allow_trad || allow_c99))) { Index: src/usr.bin/xlint/lint1/emit1.c diff -u src/usr.bin/xlint/lint1/emit1.c:1.90 src/usr.bin/xlint/lint1/emit1.c:1.91 --- src/usr.bin/xlint/lint1/emit1.c:1.90 Sun Mar 3 16:09:01 2024 +++ src/usr.bin/xlint/lint1/emit1.c Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: emit1.c,v 1.90 2024/03/03 16:09:01 rillig Exp $ */ +/* $NetBSD: emit1.c,v 1.91 2024/03/09 13:20:55 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: emit1.c,v 1.90 2024/03/03 16:09:01 rillig Exp $"); +__RCSID("$NetBSD: emit1.c,v 1.91 2024/03/09 13:20:55 rillig Exp $"); #endif #include <stdlib.h> @@ -113,20 +113,22 @@ outtype(const type_t *tp) outchar(tt[ts]); if (ts == ARRAY) { - outint(tp->t_dim); + outint(tp->u.dimension); } else if (ts == ENUM) { - outtt(tp->t_enum->en_tag, tp->t_enum->en_first_typedef); + outtt(tp->u.enumer->en_tag, + tp->u.enumer->en_first_typedef); } else if (is_struct_or_union(ts)) { - outtt(tp->t_sou->sou_tag, tp->t_sou->sou_first_typedef); + outtt(tp->u.sou->sou_tag, + tp->u.sou->sou_first_typedef); } else if (ts == FUNC && tp->t_proto) { na = 0; - for (const sym_t *param = tp->t_params; + for (const sym_t *param = tp->u.params; param != NULL; param = param->s_next) na++; if (tp->t_vararg) na++; outint(na); - for (const sym_t *param = tp->t_params; + for (const sym_t *param = tp->u.params; param != NULL; param = param->s_next) outtype(param->s_type); if (tp->t_vararg) Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.182 src/usr.bin/xlint/lint1/func.c:1.183 --- src/usr.bin/xlint/lint1/func.c:1.182 Sat Mar 9 10:54:12 2024 +++ src/usr.bin/xlint/lint1/func.c Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $ */ +/* $NetBSD: func.c,v 1.183 2024/03/09 13:20:55 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: func.c,v 1.182 2024/03/09 10:54:12 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.183 2024/03/09 13:20:55 rillig Exp $"); #endif #include <stdlib.h> @@ -253,7 +253,7 @@ begin_function(sym_t *fsym) * is already removed from the list of parameters.) */ int n = 1; - for (const sym_t *param = fsym->s_type->t_params; + for (const sym_t *param = fsym->s_type->u.params; param != NULL; param = param->s_next) { if (param->s_scl == ABSTRACT) { lint_assert(param->s_name == unnamed); @@ -421,7 +421,7 @@ check_case_label_enum(const tnode_t *tn, if (!(tn->tn_type->t_is_enum || cs->c_switch_type->t_is_enum)) return; if (tn->tn_type->t_is_enum && cs->c_switch_type->t_is_enum && - tn->tn_type->t_enum == cs->c_switch_type->t_enum) + tn->tn_type->u.enumer == cs->c_switch_type->u.enumer) return; #if 0 /* not yet ready, see msg_130.c */ @@ -639,7 +639,7 @@ stmt_switch_expr(tnode_t *tn) if (tn != NULL) { tp->t_tspec = tn->tn_type->t_tspec; if ((tp->t_is_enum = tn->tn_type->t_is_enum) != false) - tp->t_enum = tn->tn_type->t_enum; + tp->u.enumer = tn->tn_type->u.enumer; } else { tp->t_tspec = INT; } @@ -673,8 +673,8 @@ stmt_switch_expr_stmt(void) * number of enumerators. */ nenum = nclab = 0; - lint_assert(cstmt->c_switch_type->t_enum != NULL); - for (esym = cstmt->c_switch_type->t_enum->en_first_enumerator; + lint_assert(cstmt->c_switch_type->u.enumer != NULL); + for (esym = cstmt->c_switch_type->u.enumer->en_first_enumerator; esym != NULL; esym = esym->s_next) { nenum++; } Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.261 src/usr.bin/xlint/lint1/init.c:1.262 --- src/usr.bin/xlint/lint1/init.c:1.261 Sun Mar 3 16:09:01 2024 +++ src/usr.bin/xlint/lint1/init.c Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.261 2024/03/03 16:09:01 rillig Exp $ */ +/* $NetBSD: init.c,v 1.262 2024/03/09 13:20:55 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.261 2024/03/03 16:09:01 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.262 2024/03/09 13:20:55 rillig Exp $"); #endif #include <stdlib.h> @@ -195,7 +195,7 @@ first_named_member(const type_t *tp) { lint_assert(is_struct_or_union(tp->t_tspec)); - return skip_unnamed(tp->t_sou->sou_first_member); + return skip_unnamed(tp->u.sou->sou_first_member); } /* @@ -207,7 +207,7 @@ update_type_of_array_of_unknown_size(sym { type_t *tp = block_dup_type(sym->s_type); - tp->t_dim = (int)size; + tp->u.dimension = (int)size; tp->t_incomplete_array = false; sym->s_type = tp; debug_step("completed array type is '%s'", type_name(sym->s_type)); @@ -327,7 +327,8 @@ designator_type(const designator *dr, co "designator '.member' is only for struct/union"); } if (!tp->t_incomplete_array) - lint_assert(dr->dr_subscript < (size_t)tp->t_dim); + lint_assert( + dr->dr_subscript < (size_t)tp->u.dimension); return tp->t_subt; default: if (dr->dr_kind != DK_SCALAR) @@ -533,7 +534,7 @@ brace_level_advance(brace_level *bl, siz dr->dr_subscript > *max_subscript) *max_subscript = dr->dr_subscript; if (!tp->t_incomplete_array && - dr->dr_subscript >= (size_t)tp->t_dim) + dr->dr_subscript >= (size_t)tp->u.dimension) dr->dr_done = true; break; default: @@ -555,7 +556,7 @@ warn_too_many_initializers(designator_ki lint_assert(tp->t_tspec == ARRAY); lint_assert(!tp->t_incomplete_array); /* too many array initializers, expected %d */ - error(173, tp->t_dim); + error(173, tp->u.dimension); } else /* too many initializers */ error(174); @@ -717,7 +718,7 @@ initialization_lbrace(initialization *in /* initialization of union is illegal in traditional C */ warning(238); - if (is_struct_or_union(tp->t_tspec) && tp->t_sou->sou_incomplete) { + if (is_struct_or_union(tp->t_tspec) && tp->u.sou->sou_incomplete) { /* initialization of incomplete type '%s' */ error(175, type_name(tp)); in->in_err = true; @@ -804,7 +805,7 @@ initialization_add_designator_member(ini return; proceed:; - const sym_t *member = find_member(tp->t_sou, name); + const sym_t *member = find_member(tp->u.sou, name); if (member == NULL) { /* type '%s' does not have member '%s' */ error(101, type_name(tp), name); @@ -833,9 +834,9 @@ initialization_add_designator_subscript( return; } - if (!tp->t_incomplete_array && subscript >= (size_t)tp->t_dim) { + if (!tp->t_incomplete_array && subscript >= (size_t)tp->u.dimension) { /* array subscript cannot be > %d: %ld */ - error(168, tp->t_dim - 1, (long)subscript); + error(168, tp->u.dimension - 1, (long)subscript); subscript = 0; /* suppress further errors */ } @@ -891,9 +892,10 @@ initialization_init_array_from_string(in continue; } - if (!tp->t_incomplete_array && (size_t)tp->t_dim < len) + if (!tp->t_incomplete_array && (size_t)tp->u.dimension < len) /* string literal too long (%lu) for target array (%lu) */ - warning(187, (unsigned long)len, (unsigned long)tp->t_dim); + warning(187, (unsigned long)len, + (unsigned long)tp->u.dimension); brace_level *bl = in->in_brace_level; if (bl != NULL && bl->bl_designation.dn_len == 0) Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.219 src/usr.bin/xlint/lint1/lint1.h:1.220 --- src/usr.bin/xlint/lint1/lint1.h:1.219 Sat Mar 9 11:05:05 2024 +++ src/usr.bin/xlint/lint1/lint1.h Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.219 2024/03/09 11:05:05 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.220 2024/03/09 13:20:55 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -129,7 +129,7 @@ struct lint1_type { bool t_incomplete_array:1; bool t_const:1; bool t_volatile:1; - bool t_proto:1; /* function prototype (t_params valid) */ + bool t_proto:1; /* function prototype (u.params valid) */ bool t_vararg:1; /* prototype with '...' */ bool t_typedef:1; /* type defined with typedef */ bool t_typeof:1; /* type defined with GCC's __typeof__ */ @@ -137,16 +137,16 @@ struct lint1_type { /* * Either the type is currently an enum (having t_tspec ENUM), or it * is an integer type (typically INT) that has been implicitly - * converted from an enum type. In both cases, t_enum is valid. + * converted from an enum type. In both cases, u.enumer is valid. */ bool t_is_enum:1; bool t_packed:1; union { - int _t_dim; /* dimension (if ARRAY) */ - struct_or_union *_t_sou; - enumeration *_t_enum; - sym_t *_t_params; /* parameters (if t_proto) */ - } t_u; + int dimension; /* if ARRAY */ + struct_or_union *sou; + enumeration *enumer; + sym_t *params; /* if t_proto */ + } u; unsigned int t_bit_field_width:8; unsigned int t_bit_field_offset:24; struct lint1_type *t_subt; /*- element type (if ARRAY), @@ -154,12 +154,6 @@ struct lint1_type { * target type (if PTR) */ }; -#define t_dim t_u._t_dim -#define t_sou t_u._t_sou -#define t_enum t_u._t_enum -#define t_params t_u._t_params - - typedef enum { SK_VCFT, /* variable, constant, function, type */ SK_MEMBER, /* member of a struct or union */ @@ -365,8 +359,8 @@ typedef struct decl_level { bool d_asm:1; /* set if d_ctx == AUTO and asm() present */ bool d_packed:1; bool d_used:1; - type_t *d_tag_type; /* during a member declaration, the tag type to - * which the member belongs */ + type_t *d_tag_type; /* during a member or enumerator declaration, + * the tag type to which the member belongs */ sym_t *d_func_params; /* during a function declaration, the * parameters, stored in the enclosing level */ pos_t d_func_def_pos; /* position of the function definition */ Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.610 src/usr.bin/xlint/lint1/tree.c:1.611 --- src/usr.bin/xlint/lint1/tree.c:1.610 Sat Mar 9 10:47:16 2024 +++ src/usr.bin/xlint/lint1/tree.c Sat Mar 9 13:20:55 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.610 2024/03/09 10:47:16 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.611 2024/03/09 13:20:55 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.610 2024/03/09 10:47:16 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.611 2024/03/09 13:20:55 rillig Exp $"); #endif #include <float.h> @@ -420,7 +420,7 @@ fallback_symbol(sym_t *sym) /* C11 6.4.2.2 */ sym->s_type = block_derive_type(gettyp(CHAR), ARRAY); sym->s_type->t_const = true; - sym->s_type->t_dim = (int)strlen(funcsym->s_name) + 1; + sym->s_type->u.dimension = (int)strlen(funcsym->s_name) + 1; return; } @@ -537,7 +537,7 @@ build_string(buffer *lit) type_t *tp = expr_zero_alloc(sizeof(*tp), "type"); tp->t_tspec = ARRAY; tp->t_subt = gettyp(lit->data != NULL ? CHAR : WCHAR_TSPEC); - tp->t_dim = (int)(value_len + 1); + tp->u.dimension = (int)(value_len + 1); tnode_t *n = expr_alloc_tnode(); n->tn_op = STRING; @@ -982,7 +982,7 @@ subt_size_in_bytes(type_t *tp) int elem = 1; while (tp->t_tspec == ARRAY) { - elem *= tp->t_dim; + elem *= tp->u.dimension; tp = tp->t_subt; } @@ -998,7 +998,7 @@ subt_size_in_bytes(type_t *tp) break; case STRUCT: case UNION: - if ((elsz_in_bits = (int)tp->t_sou->sou_size_in_bits) == 0) + if ((elsz_in_bits = (int)tp->u.sou->sou_size_in_bits) == 0) /* cannot do pointer arithmetic on operand of ... */ error(136); break; @@ -1055,7 +1055,7 @@ check_enum_array_index(const tnode_t *ln return; const type_t *rtp = rn->tn_left->tn_type; - const sym_t *ec = rtp->t_enum->en_first_enumerator; + const sym_t *ec = rtp->u.enumer->en_first_enumerator; const sym_t *max_ec = ec; lint_assert(ec != NULL); for (ec = ec->s_next; ec != NULL; ec = ec->s_next) @@ -1065,7 +1065,7 @@ check_enum_array_index(const tnode_t *ln int64_t max_enum_value = max_ec->u.s_enum_constant; lint_assert(INT_MIN <= max_enum_value && max_enum_value <= INT_MAX); - int max_array_index = ltp->t_dim - 1; + int max_array_index = ltp->u.dimension - 1; if (max_enum_value == max_array_index) return; @@ -1197,7 +1197,7 @@ build_colon(bool sys, tnode_t *ln, tnode tp = gettyp(VOID); else if (is_struct_or_union(lt)) { lint_assert(is_struct_or_union(rt)); - lint_assert(ln->tn_type->t_sou == rn->tn_type->t_sou); + lint_assert(ln->tn_type->u.sou == rn->tn_type->u.sou); if (is_incomplete(ln->tn_type)) { /* unknown operand size, op '%s' */ error(138, op_name(COLON)); @@ -1316,7 +1316,7 @@ build_assignment(op_t op, bool sys, tnod if ((op == ASSIGN || op == RETURN || op == INIT) && (lt == STRUCT || rt == STRUCT)) { lint_assert(lt == rt); - lint_assert(ln->tn_type->t_sou == rn->tn_type->t_sou); + lint_assert(ln->tn_type->u.sou == rn->tn_type->u.sou); if (is_incomplete(ln->tn_type)) { if (op == RETURN) /* cannot return incomplete type */ @@ -1857,7 +1857,7 @@ find_member(const struct_or_union *sou, if (is_struct_or_union(mem->s_type->t_tspec) && mem->s_name == unnamed) { sym_t *nested_mem = - find_member(mem->s_type->t_sou, name); + find_member(mem->s_type->u.sou, name); if (nested_mem != NULL) return nested_mem; } @@ -1905,7 +1905,7 @@ struct_or_union_member(tnode_t *tn, op_t if (op == ARROW && tn->tn_type->t_tspec == PTR && is_struct_or_union(tn->tn_type->t_subt->t_tspec)) tp = tn->tn_type->t_subt; - struct_or_union *sou = tp != NULL ? tp->t_sou : NULL; + struct_or_union *sou = tp != NULL ? tp->u.sou : NULL; if (sou != NULL) { sym_t *nested_mem = find_member(sou, msym->s_name); @@ -2416,9 +2416,9 @@ typeok_colon(const tnode_t *ln, const ty if (lt == BOOL && rt == BOOL) return true; - if (lt == STRUCT && rt == STRUCT && ltp->t_sou == rtp->t_sou) + if (lt == STRUCT && rt == STRUCT && ltp->u.sou == rtp->u.sou) return true; - if (lt == UNION && rt == UNION && ltp->t_sou == rtp->t_sou) + if (lt == UNION && rt == UNION && ltp->u.sou == rtp->u.sou) return true; if (lt == PTR && is_null_pointer(rn)) @@ -2457,7 +2457,7 @@ has_constant_member(const type_t *tp) { lint_assert(is_struct_or_union(tp->t_tspec)); - for (sym_t *m = tp->t_sou->sou_first_member; + for (sym_t *m = tp->u.sou->sou_first_member; m != NULL; m = m->s_next) { const type_t *mtp = m->s_type; if (mtp->t_const) @@ -2794,7 +2794,7 @@ check_assign_types_compatible(op_t op, i return true; if (is_struct_or_union(lt) && is_struct_or_union(rt)) - return ltp->t_sou == rtp->t_sou; + return ltp->u.sou == rtp->u.sou; if (lt == PTR && is_null_pointer(rn)) { if (is_integer(rn->tn_type->t_tspec)) @@ -3002,7 +3002,7 @@ check_enum_type_mismatch(op_t op, int ar { const mod_t *mp = &modtab[op]; - if (ln->tn_type->t_enum != rn->tn_type->t_enum) { + if (ln->tn_type->u.enumer != rn->tn_type->u.enumer) { switch (op) { case INIT: /* enum type mismatch between '%s' and '%s' in ... */ @@ -3395,8 +3395,8 @@ static bool struct_starts_with(const type_t *struct_tp, const type_t *member_tp) { - return struct_tp->t_sou->sou_first_member != NULL && - types_compatible(struct_tp->t_sou->sou_first_member->s_type, + return struct_tp->u.sou->sou_first_member != NULL && + types_compatible(struct_tp->u.sou->sou_first_member->s_type, member_tp, true, false, NULL); } @@ -3411,7 +3411,7 @@ is_byte_array(const type_t *tp) static bool union_contains(const type_t *utp, const type_t *mtp) { - for (const sym_t *mem = utp->t_sou->sou_first_member; + for (const sym_t *mem = utp->u.sou->sou_first_member; mem != NULL; mem = mem->s_next) { if (types_compatible(mem->s_type, mtp, true, false, NULL)) return true; @@ -3444,8 +3444,8 @@ should_warn_about_pointer_cast(const typ /* Allow cast between pointers to sockaddr variants. */ if (nst == STRUCT && ost == STRUCT) { - const sym_t *nmem = nstp->t_sou->sou_first_member; - const sym_t *omem = ostp->t_sou->sou_first_member; + const sym_t *nmem = nstp->u.sou->sou_first_member; + const sym_t *omem = ostp->u.sou->sou_first_member; while (nmem != NULL && omem != NULL && types_compatible(nmem->s_type, omem->s_type, true, false, NULL)) @@ -3466,7 +3466,7 @@ should_warn_about_pointer_cast(const typ } if (is_struct_or_union(nst) && is_struct_or_union(ost)) - return nstp->t_sou != ostp->t_sou; + return nstp->u.sou != ostp->u.sou; enum rank_kind rk1 = type_properties(nst)->tt_rank_kind; enum rank_kind rk2 = type_properties(ost)->tt_rank_kind; @@ -3886,7 +3886,7 @@ build_offsetof(const type_t *tp, designa if (!is_struct_or_union(tp->t_tspec)) goto proceed; /* silent error */ const char *name = dr->dr_member->s_name; - sym_t *mem = find_member(tp->t_sou, name); + sym_t *mem = find_member(tp->u.sou, name); if (mem == NULL) { /* type '%s' does not have member '%s' */ error(101, name, type_name(tp)); @@ -3914,7 +3914,7 @@ type_size_in_bits(const type_t *tp) lint_assert(tp != NULL); while (tp->t_tspec == ARRAY) { flex = true; /* allow c99 flex arrays [] [0] */ - elem *= tp->t_dim; + elem *= tp->u.dimension; tp = tp->t_subt; } if (elem == 0 && !flex) { @@ -3942,7 +3942,7 @@ type_size_in_bits(const type_t *tp) error(143); elsz = 1; } else - elsz = tp->t_sou->sou_size_in_bits; + elsz = tp->u.sou->sou_size_in_bits; break; case ENUM: if (is_incomplete(tp)) { @@ -4000,7 +4000,7 @@ cast_to_union(tnode_t *otn, bool sys, ty return NULL; } - for (const sym_t *m = ntp->t_sou->sou_first_member; + for (const sym_t *m = ntp->u.sou->sou_first_member; m != NULL; m = m->s_next) { if (types_compatible(m->s_type, otn->tn_type, false, false, NULL)) { @@ -4137,12 +4137,12 @@ check_function_arguments(const function_ /* get # of parameters in the prototype */ int npar = 0; - for (const sym_t *p = ftp->t_params; p != NULL; p = p->s_next) + for (const sym_t *p = ftp->u.params; p != NULL; p = p->s_next) npar++; int narg = (int)call->args_len; - const sym_t *param = ftp->t_params; + const sym_t *param = ftp->u.params; if (ftp->t_proto && npar != narg && !(ftp->t_vararg && npar < narg)) { /* argument mismatch: %d %s passed, %d expected */ error(150, narg, narg != 1 ? "arguments" : "argument", npar); @@ -4368,7 +4368,7 @@ check_array_index(tnode_t *tn, bool ampe ? (int64_t)((uint64_t)rn->tn_val.u.integer / elsz) : rn->tn_val.u.integer / elsz; - int dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0); + int dim = ln->tn_left->tn_type->u.dimension + (amper ? 1 : 0); if (!is_uinteger(rn->tn_type->t_tspec) && con < 0) /* array subscript cannot be negative: %ld */