Module Name: src Committed By: rillig Date: Sun Jul 2 18:28:15 UTC 2023
Modified Files: src/usr.bin/xlint/lint1: cgram.y debug.c decl.c lint1.h Log Message: lint: clean up variable names relating to structure padding To generate a diff of this commit: cvs rdiff -u -r1.443 -r1.444 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.337 -r1.338 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.177 -r1.178 src/usr.bin/xlint/lint1/lint1.h 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/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.443 src/usr.bin/xlint/lint1/cgram.y:1.444 --- src/usr.bin/xlint/lint1/cgram.y:1.443 Fri Jun 30 21:39:54 2023 +++ src/usr.bin/xlint/lint1/cgram.y Sun Jul 2 18:28:15 2023 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.443 2023/06/30 21:39:54 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.444 2023/07/02 18:28:15 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: cgram.y,v 1.443 2023/06/30 21:39:54 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.444 2023/07/02 18:28:15 rillig Exp $"); #endif #include <limits.h> @@ -898,7 +898,7 @@ struct_or_union: /* C99 6.7.2.1 */ T_STRUCT_OR_UNION { symtyp = FTAG; begin_declaration_level($1 == STRUCT ? DLK_STRUCT : DLK_UNION); - dcs->d_offset_in_bits = 0; + dcs->d_sou_size_in_bits = 0; dcs->d_sou_align_in_bits = CHAR_SIZE; $$ = $1; } Index: src/usr.bin/xlint/lint1/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.45 src/usr.bin/xlint/lint1/debug.c:1.46 --- src/usr.bin/xlint/lint1/debug.c:1.45 Sun Jul 2 18:14:44 2023 +++ src/usr.bin/xlint/lint1/debug.c Sun Jul 2 18:28:15 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.45 2023/07/02 18:14:44 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.46 2023/07/02 18:28:15 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.45 2023/07/02 18:14:44 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.46 2023/07/02 18:28:15 rillig Exp $"); #endif #include <stdlib.h> @@ -414,8 +414,8 @@ debug_decl_level(const decl_level *dl) } if (dl->d_redeclared_symbol != NULL) debug_sym(" redeclared=(", dl->d_redeclared_symbol, ")"); - if (dl->d_offset_in_bits != 0) - debug_printf(" offset=%u", dl->d_offset_in_bits); + if (dl->d_sou_size_in_bits != 0) + debug_printf(" size=%u", dl->d_sou_size_in_bits); if (dl->d_sou_align_in_bits != 0) debug_printf(" align=%u", dl->d_sou_align_in_bits); Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.337 src/usr.bin/xlint/lint1/decl.c:1.338 --- src/usr.bin/xlint/lint1/decl.c:1.337 Sun Jul 2 18:14:44 2023 +++ src/usr.bin/xlint/lint1/decl.c Sun Jul 2 18:28:15 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.337 2023/07/02 18:14:44 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.338 2023/07/02 18:28:15 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.337 2023/07/02 18:14:44 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.338 2023/07/02 18:28:15 rillig Exp $"); #endif #include <sys/param.h> @@ -1024,28 +1024,28 @@ dcs_add_member(sym_t *mem) { type_t *tp = mem->s_type; - unsigned int union_offset = 0; + unsigned int union_size = 0; if (dcs->d_kind == DLK_UNION) { - union_offset = dcs->d_offset_in_bits; - dcs->d_offset_in_bits = 0; + union_size = dcs->d_sou_size_in_bits; + dcs->d_sou_size_in_bits = 0; } if (mem->s_bitfield) { dcs_align(alignment_in_bits(tp), tp->t_bit_field_width); // XXX: Why round down? - mem->u.s_member.sm_offset_in_bits = dcs->d_offset_in_bits - - dcs->d_offset_in_bits % size_in_bits(tp->t_tspec); - tp->t_bit_field_offset = dcs->d_offset_in_bits + mem->u.s_member.sm_offset_in_bits = dcs->d_sou_size_in_bits + - dcs->d_sou_size_in_bits % size_in_bits(tp->t_tspec); + tp->t_bit_field_offset = dcs->d_sou_size_in_bits - mem->u.s_member.sm_offset_in_bits; - dcs->d_offset_in_bits += tp->t_bit_field_width; + dcs->d_sou_size_in_bits += tp->t_bit_field_width; } else { dcs_align(alignment_in_bits(tp), 0); - mem->u.s_member.sm_offset_in_bits = dcs->d_offset_in_bits; - dcs->d_offset_in_bits += type_size_in_bits(tp); + mem->u.s_member.sm_offset_in_bits = dcs->d_sou_size_in_bits; + dcs->d_sou_size_in_bits += type_size_in_bits(tp); } - if (union_offset > dcs->d_offset_in_bits) - dcs->d_offset_in_bits = union_offset; + if (union_size > dcs->d_sou_size_in_bits) + dcs->d_sou_size_in_bits = union_size; } sym_t * @@ -1125,11 +1125,11 @@ dcs_align(unsigned int member_alignment, if (member_alignment > dcs->d_sou_align_in_bits) dcs->d_sou_align_in_bits = member_alignment; - unsigned int offset = (dcs->d_offset_in_bits + member_alignment - 1) + unsigned int offset = (dcs->d_sou_size_in_bits + member_alignment - 1) & ~(member_alignment - 1); if (bit_field_width == 0 - || dcs->d_offset_in_bits + bit_field_width > offset) - dcs->d_offset_in_bits = offset; + || dcs->d_sou_size_in_bits + bit_field_width > offset) + dcs->d_sou_size_in_bits = offset; } sym_t * @@ -1733,16 +1733,16 @@ complete_struct_or_union(sym_t *first_me dcs_align(dcs->d_sou_align_in_bits, 0); - struct_or_union *sp = tp->t_sou; - sp->sou_align_in_bits = dcs->d_sou_align_in_bits; - sp->sou_incomplete = false; - sp->sou_first_member = first_member; + struct_or_union *sou = tp->t_sou; + sou->sou_align_in_bits = dcs->d_sou_align_in_bits; + sou->sou_incomplete = false; + sou->sou_first_member = first_member; if (tp->t_packed) pack_struct_or_union(tp); else - sp->sou_size_in_bits = dcs->d_offset_in_bits; + sou->sou_size_in_bits = dcs->d_sou_size_in_bits; - if (sp->sou_size_in_bits == 0) { + if (sou->sou_size_in_bits == 0) { /* zero sized %s is a C99 feature */ c99ism(47, tspec_name(tp->t_tspec)); } else if (!has_named_member(tp)) { Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.177 src/usr.bin/xlint/lint1/lint1.h:1.178 --- src/usr.bin/xlint/lint1/lint1.h:1.177 Sun Jul 2 18:14:44 2023 +++ src/usr.bin/xlint/lint1/lint1.h Sun Jul 2 18:28:15 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.177 2023/07/02 18:14:44 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.178 2023/07/02 18:28:15 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -350,9 +350,11 @@ typedef struct decl_level { type_t *d_type; /* after dcs_end_type, the pointer to the type * used for all declarators */ sym_t *d_redeclared_symbol; - unsigned int d_offset_in_bits; /* offset of next structure member */ - unsigned int d_sou_align_in_bits; /* alignment required for current - * structure */ + unsigned int d_sou_size_in_bits; /* size of the structure or + * union being built, without + * trailing padding */ + unsigned int d_sou_align_in_bits; /* alignment of the structure + * or union being built */ bool d_const:1; /* const in declaration specifiers */ bool d_volatile:1; /* volatile in declaration specifiers */ bool d_inline:1; /* inline in declaration specifiers */