Module Name:    src
Committed By:   rillig
Date:           Fri Mar 29 08:35:32 UTC 2024

Modified Files:
        src/usr.bin/xlint: Makefile.inc
        src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h func.c init.c lex.c
            tree.c

Log Message:
lint: clean up


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/Makefile.inc
cvs rdiff -u -r1.492 -r1.493 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.396 -r1.397 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.185 -r1.186 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.265 -r1.266 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.222 -r1.223 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.628 -r1.629 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/Makefile.inc
diff -u src/usr.bin/xlint/Makefile.inc:1.28 src/usr.bin/xlint/Makefile.inc:1.29
--- src/usr.bin/xlint/Makefile.inc:1.28	Tue Jan 23 19:44:28 2024
+++ src/usr.bin/xlint/Makefile.inc	Fri Mar 29 08:35:31 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.28 2024/01/23 19:44:28 rillig Exp $
+#	$NetBSD: Makefile.inc,v 1.29 2024/03/29 08:35:31 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -23,9 +23,7 @@ CLEANFILES+=	*.gcno *.gcda *.gcov
 CFLAGS+=	${ACTIVE_CC:Mgcc:%=-ftrapv}
 .endif
 
-.if exists(${.CURDIR}/../../Makefile.inc)
 .include "${.CURDIR}/../../Makefile.inc"
-.endif
 
 LINTFLAGS+=	-aa	# warn about all lossy conversions
 LINTFLAGS+=	-e	# strict enum mode

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.492 src/usr.bin/xlint/lint1/cgram.y:1.493
--- src/usr.bin/xlint/lint1/cgram.y:1.492	Wed Mar 27 21:14:09 2024
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Mar 29 08:35:32 2024
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.492 2024/03/27 21:14:09 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.493 2024/03/29 08:35:32 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.492 2024/03/27 21:14:09 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.493 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -77,7 +77,7 @@ static void
 clear_warning_flags_loc(const char *file, size_t line)
 {
 	debug_step("%s:%zu: clearing flags", file, line);
-	clear_warn_flags();
+	reset_suppressions();
 	saved_lwarn = LWARN_NOTHING_SAVED;
 }
 

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.396 src/usr.bin/xlint/lint1/decl.c:1.397
--- src/usr.bin/xlint/lint1/decl.c:1.396	Sat Mar  9 13:20:55 2024
+++ src/usr.bin/xlint/lint1/decl.c	Fri Mar 29 08:35:32 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.396 2024/03/09 13:20:55 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.397 2024/03/29 08:35:32 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.396 2024/03/09 13:20:55 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.397 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1072,7 +1072,7 @@ declare_member(sym_t *dsym)
 		    rdsym->u.s_member.sm_containing_type) {
 			/* duplicate member name '%s' */
 			error(33, dsym->s_name);
-			rmsym(rdsym);
+			symtab_remove_forever(rdsym);
 		}
 	}
 
@@ -1169,14 +1169,6 @@ block_derive_pointer(type_t *stp, bool i
 	return tp;
 }
 
-/*
- * The following 3 functions extend the type of a declarator with
- * pointer, function and array types.
- *
- * The current type is the type built by dcs_end_type (dcs->d_type) and
- * pointer, function and array types already added for this
- * declarator. The new type extension is inserted between both.
- */
 sym_t *
 add_pointer(sym_t *decl, qual_ptr *p)
 {
@@ -1205,23 +1197,19 @@ add_pointer(sym_t *decl, qual_ptr *p)
 }
 
 static type_t *
-block_derive_array(type_t *stp, bool dim, int len)
+block_derive_array(type_t *stp, bool has_dim, int dim)
 {
 
 	type_t *tp = block_derive_type(stp, ARRAY);
-	tp->u.dimension = len;
+	tp->u.dimension = dim;
 
 #if 0
 	/*
-	 * As of 2022-04-03, the implementation of the type parser (see
-	 * add_function, add_array, add_pointer) is strange.  When it sees the
-	 * type 'void *b[4]', it first creates 'void b[4]' and only later
-	 * inserts the '*' in the middle of the type.  Late modifications like
-	 * these should not be done at all, instead the parser should be fixed
-	 * to process the type names in the proper syntactical order.
-	 *
-	 * Since the intermediate type would be an array of void, but the final
-	 * type is valid, this check cannot be enabled yet.
+	 * When the type of the declaration 'void *b[4]' is constructed (see
+	 * add_function, add_array, add_pointer), the intermediate type
+	 * 'void[4]' is invalid and only later gets the '*' inserted in the
+	 * middle of the type.  Due to the invalid intermediate type, this
+	 * check cannot be enabled yet.
 	 */
 	if (stp->t_tspec == VOID) {
 		/* array of incomplete type */
@@ -1229,25 +1217,21 @@ block_derive_array(type_t *stp, bool dim
 		tp->t_subt = gettyp(CHAR);
 	}
 #endif
-	if (len < 0)
+	if (dim < 0)
 		/* negative array dimension (%d) */
-		error(20, len);
-	else if (len == 0 && dim)
+		error(20, dim);
+	else if (dim == 0 && has_dim)
 		/* zero sized array requires C99 or later */
 		c99ism(322);
-	else if (len == 0 && !dim)
+	else if (dim == 0 && !has_dim)
 		tp->t_incomplete_array = true;
 
 	debug_step("%s: '%s'", __func__, type_name(tp));
 	return tp;
 }
 
-/*
- * If a dimension was specified, dim is true, otherwise false
- * n is the specified dimension
- */
 sym_t *
-add_array(sym_t *decl, bool dim, int n)
+add_array(sym_t *decl, bool has_dim, int dim)
 {
 
 	debug_dcs();
@@ -1259,7 +1243,7 @@ add_array(sym_t *decl, bool dim, int n)
 		lint_assert(*tpp != NULL);
 	}
 
-	*tpp = block_derive_array(dcs->d_type, dim, n);
+	*tpp = block_derive_array(dcs->d_type, has_dim, dim);
 
 	debug_step("%s: '%s'", __func__, type_name(decl->s_type));
 	return decl;
@@ -1980,7 +1964,7 @@ declare_extern(sym_t *dsym, bool has_ini
 			complete_type(dsym, rdsym);
 		}
 
-		rmsym(rdsym);
+		symtab_remove_forever(rdsym);
 	}
 
 	if (dsym->s_scl == TYPEDEF) {
@@ -2299,7 +2283,7 @@ declare_parameter(sym_t *sym, bool has_i
 	    dcs->d_redeclared_symbol->s_block_level == block_level) {
 		/* redeclaration of formal parameter '%s' */
 		error(237, sym->s_name);
-		rmsym(dcs->d_redeclared_symbol);
+		symtab_remove_forever(dcs->d_redeclared_symbol);
 		sym->s_param = true;
 	}
 
@@ -2564,7 +2548,7 @@ check_local_redeclaration(const sym_t *d
 				if (hflag)
 					/* declaration of '%s' hides ... */
 					warning(91, dsym->s_name);
-				rmsym(rdsym);
+				symtab_remove_forever(rdsym);
 			}
 		}
 
@@ -2575,7 +2559,7 @@ check_local_redeclaration(const sym_t *d
 	if (rdsym->s_block_level == block_level) {
 		/* redeclaration of '%s' */
 		error(27, dsym->s_name);
-		rmsym(rdsym);
+		symtab_remove_forever(rdsym);
 	}
 }
 
@@ -2741,7 +2725,7 @@ abstract_name_level(bool enclosing)
 	 * will be updated later, adding pointers, arrays and functions as
 	 * necessary.
 	 */
-	sym->s_type = (enclosing ? dcs->d_enclosing : dcs)->d_type;
+	sym->s_type = enclosing ? dcs->d_enclosing->d_type : dcs->d_type;
 	dcs->d_redeclared_symbol = NULL;
 
 	debug_printf("%s: ", __func__);

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.220 src/usr.bin/xlint/lint1/externs1.h:1.221
--- src/usr.bin/xlint/lint1/externs1.h:1.220	Thu Mar 28 21:04:48 2024
+++ src/usr.bin/xlint/lint1/externs1.h	Fri Mar 29 08:35:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: externs1.h,v 1.220 2024/03/28 21:04:48 rillig Exp $	*/
+/*	$NetBSD: externs1.h,v 1.221 2024/03/29 08:35:32 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -85,12 +85,12 @@ extern FILE *yyin;
 
 void init_lex(void);
 int64_t convert_integer(int64_t, tspec_t, unsigned int);
-void clear_warn_flags(void);
+void reset_suppressions(void);
 sym_t *getsym(sbuf_t *);
 void clean_up_after_error(void);
 sym_t *pushdown(const sym_t *);
 sym_t *mktempsym(type_t *);
-void rmsym(sym_t *);
+void symtab_remove_forever(sym_t *);
 void symtab_remove_level(sym_t *);
 void inssym(int, sym_t *);
 void freeyyv(void *, int);

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.185 src/usr.bin/xlint/lint1/func.c:1.186
--- src/usr.bin/xlint/lint1/func.c:1.185	Wed Mar 27 19:28:20 2024
+++ src/usr.bin/xlint/lint1/func.c	Fri Mar 29 08:35:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.185 2024/03/27 19:28:20 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.186 2024/03/29 08:35:32 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.185 2024/03/27 19:28:20 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.186 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -308,8 +308,7 @@ begin_function(sym_t *fsym)
 				fsym->s_inline = true;
 		}
 
-		/* remove the old symbol from the symbol table */
-		rmsym(rdsym);
+		symtab_remove_forever(rdsym);
 	}
 
 	if (fsym->s_osdef && !fsym->s_type->t_proto) {

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.265 src/usr.bin/xlint/lint1/init.c:1.266
--- src/usr.bin/xlint/lint1/init.c:1.265	Fri Mar 29 07:35:45 2024
+++ src/usr.bin/xlint/lint1/init.c	Fri Mar 29 08:35:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.265 2024/03/29 07:35:45 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.266 2024/03/29 08:35:32 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.265 2024/03/29 07:35:45 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.266 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -105,12 +105,7 @@ typedef struct brace_level {
 	struct brace_level *bl_enclosing;
 } brace_level;
 
-/*
- * An ongoing initialization.
- *
- * In most cases there is only ever a single initialization at a time.  See
- * pointer_to_compound_literal in msg_171.c for a real-life counterexample.
- */
+/* An ongoing initialization. */
 typedef struct initialization {
 	/* The symbol that is to be initialized. */
 	sym_t		*in_sym;
@@ -173,13 +168,6 @@ can_init_character_array(const type_t *l
 	    : lst == WCHAR_TSPEC;
 }
 
-/*
- * C11 6.7.9p9 seems to say that all unnamed members are skipped. C11 6.7.2.1p8
- * suggests an exception to that rule, and together with C11 6.7.2.1p13, it
- * says that the members from an anonymous struct/union member are "considered
- * to be members of the containing structure or union", thereby preventing that
- * the containing structure or union has only unnamed members.
- */
 static const sym_t *
 skip_unnamed(const sym_t *m)
 {
@@ -198,10 +186,6 @@ first_named_member(const type_t *tp)
 	return skip_unnamed(tp->u.sou->sou_first_member);
 }
 
-/*
- * C99 6.7.8p22 says that the type of an array of unknown size becomes known
- * at the end of its initializer list.
- */
 static void
 update_type_of_array_of_unknown_size(sym_t *sym, size_t size)
 {
@@ -214,8 +198,6 @@ update_type_of_array_of_unknown_size(sym
 	outsym(sym, sym->s_scl, sym->s_def);
 }
 
-
-/* In traditional C, bit-fields can be initialized only by integer constants. */
 static void
 check_bit_field_init(const tnode_t *ln, tspec_t lt, tspec_t rt)
 {
@@ -275,27 +257,19 @@ check_init_expr(const type_t *ltp, sym_t
 
 	rn = cconv(rn);
 
-	tspec_t lt = ln->tn_type->t_tspec;
-	tspec_t rt = rn->tn_type->t_tspec;
-
 	debug_step("typeok '%s', '%s'",
 	    type_name(ln->tn_type), type_name(rn->tn_type));
 	if (!typeok(INIT, 0, ln, rn))
 		return;
 
-	/*
-	 * Preserve the tree memory. This is necessary because otherwise expr()
-	 * would free it.
-	 */
 	memory_pool saved_mem = expr_save_memory();
 	expr(rn, true, false, true, false);
 	expr_restore_memory(saved_mem);
 
+	tspec_t lt = ln->tn_type->t_tspec;
+	tspec_t rt = rn->tn_type->t_tspec;
 	check_bit_field_init(ln, lt, rt);
 
-	/*
-	 * XXX: Is it correct to do this conversion _after_ the typeok above?
-	 */
 	if (lt != rt || (ltp->t_bitfield && rn->tn_op == CON))
 		rn = convert(INIT, 0, unconst_cast(ltp), rn);
 
@@ -515,7 +489,6 @@ brace_level_advance(brace_level *bl, siz
 		(void)designation_descend(dn, bl->bl_type);
 
 	designator *dr = designation_last(dn);
-	/* TODO: try to switch on dr->dr_kind instead */
 	switch (tp->t_tspec) {
 	case STRUCT:
 		lint_assert(dr->dr_member != NULL);
@@ -594,12 +567,7 @@ brace_level_pop_final(brace_level *bl, s
 	}
 }
 
-/*
- * Make the designation point to the sub-object to be initialized next.
- * Initially or after a previous expression, the designation is not advanced
- * yet since the place to stop depends on the next expression, especially for
- * string literals.
- */
+/* Make the designation point to the sub-object to be initialized next. */
 static bool
 brace_level_goto(brace_level *bl, const tnode_t *rn, size_t *max_subscript)
 {
@@ -646,7 +614,6 @@ initialization_free(initialization *in)
 {
 	brace_level *bl, *next;
 
-	/* TODO: lint_assert(in->in_brace_level == NULL) */
 	for (bl = in->in_brace_level; bl != NULL; bl = next) {
 		next = bl->bl_enclosing;
 		brace_level_free(bl);

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.222 src/usr.bin/xlint/lint1/lex.c:1.223
--- src/usr.bin/xlint/lint1/lex.c:1.222	Sun Mar  3 16:09:01 2024
+++ src/usr.bin/xlint/lint1/lex.c	Fri Mar 29 08:35:32 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.222 2024/03/03 16:09:01 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.223 2024/03/29 08:35:32 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.222 2024/03/03 16:09:01 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.223 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -478,18 +478,6 @@ lex_name(const char *yytext, size_t yyle
 	return T_NAME;
 }
 
-// Determines whether the constant is signed in traditional C but unsigned in
-// C90 and later.
-static bool
-is_unsigned_since_c90(unsigned ls, uint64_t ui, int base)
-{
-	if (ui <= TARG_INT_MAX)
-		return false;
-	if (ls == 0 && ui <= TARG_UINT_MAX && base != 10)
-		return true;
-	return ls <= 1 && ui > TARG_LONG_MAX;
-}
-
 static tspec_t
 integer_constant_type_signed(unsigned ls, uint64_t ui, int base, bool warned)
 {
@@ -595,12 +583,14 @@ lex_integer_constant(const char *yytext,
 		query_message(8, (int)len, cp);
 
 	bool unsigned_since_c90 = allow_trad && allow_c90 && u_suffix == 0
-	    && is_unsigned_since_c90(l_suffix, ui, base);
+	    && ui > TARG_INT_MAX
+	    && ((l_suffix == 0 && base != 10 && ui <= TARG_UINT_MAX)
+		|| (l_suffix <= 1 && ui > TARG_LONG_MAX));
 
 	tspec_t t = u_suffix > 0
 	    ? integer_constant_type_unsigned(l_suffix, ui, warned)
 	    : integer_constant_type_signed(l_suffix, ui, base, warned);
-	ui = (uint64_t)convert_integer((int64_t)ui, t, 0);
+	ui = (uint64_t)convert_integer((int64_t)ui, t, size_in_bits(t));
 
 	yylval.y_val = xcalloc(1, sizeof(*yylval.y_val));
 	yylval.y_val->v_tspec = t;
@@ -610,22 +600,14 @@ lex_integer_constant(const char *yytext,
 	return T_CON;
 }
 
-/*
- * Extend or truncate si to match t.  If t is signed, sign-extend.
- *
- * len is the number of significant bits. If len is 0, len is set
- * to the width of type t.
- */
+/* Extend or truncate si to match t.  If t is signed, sign-extend. */
 int64_t
-convert_integer(int64_t si, tspec_t t, unsigned int len)
+convert_integer(int64_t si, tspec_t t, unsigned int bits)
 {
 
-	if (len == 0)
-		len = size_in_bits(t);
-
-	uint64_t vbits = value_bits(len);
+	uint64_t vbits = value_bits(bits);
 	uint64_t ui = (uint64_t)si;
-	return t == PTR || is_uinteger(t) || ((ui & bit(len - 1)) == 0)
+	return t == PTR || is_uinteger(t) || ((ui & bit(bits - 1)) == 0)
 	    ? (int64_t)(ui & vbits)
 	    : (int64_t)(ui | ~vbits);
 }
@@ -984,9 +966,7 @@ lex_character_constant(void)
 	return T_CON;
 }
 
-/*
- * Called if lex found a leading L\'
- */
+/* Called if lex found a leading "L'". */
 int
 lex_wide_character_constant(void)
 {
@@ -1169,9 +1149,6 @@ lex_comment(void)
 		{ "VARARGS",		true,	LC_VARARGS	},
 	};
 	char keywd[32];
-	char arg[32];
-	size_t l, i;
-	int a;
 
 	bool seen_end_of_comment = false;
 
@@ -1179,7 +1156,7 @@ lex_comment(void)
 		continue;
 
 	/* Read the potential keyword to keywd */
-	l = 0;
+	size_t l = 0;
 	while (c != EOF && l < sizeof(keywd) - 1 &&
 	    (isalpha(c) || isspace(c))) {
 		if (islower(c) && l > 0 && isupper((unsigned char)keywd[0]))
@@ -1192,6 +1169,7 @@ lex_comment(void)
 	keywd[l] = '\0';
 
 	/* look for the keyword */
+	size_t i;
 	for (i = 0; i < sizeof(keywtab) / sizeof(keywtab[0]); i++)
 		if (strcmp(keywtab[i].name, keywd) == 0)
 			goto found_keyword;
@@ -1202,6 +1180,7 @@ found_keyword:
 		c = read_byte();
 
 	/* read the argument, if the keyword accepts one and there is one */
+	char arg[32];
 	l = 0;
 	if (keywtab[i].arg) {
 		while (isdigit(c) && l < sizeof(arg) - 1) {
@@ -1210,7 +1189,7 @@ found_keyword:
 		}
 	}
 	arg[l] = '\0';
-	a = l != 0 ? atoi(arg) : -1;
+	int a = l != 0 ? atoi(arg) : -1;
 
 	while (isspace(c))
 		c = read_byte();
@@ -1238,25 +1217,17 @@ skip_rest:
 void
 lex_slash_slash_comment(void)
 {
-	int c;
 
 	if (!allow_c99 && !allow_gcc)
 		/* %s does not support '//' comments */
 		gnuism(312, allow_c90 ? "C90" : "traditional C");
 
-	while ((c = read_byte()) != EOF && c != '\n')
+	for (int c; c = read_byte(), c != EOF && c != '\n';)
 		continue;
 }
 
-/*
- * Clear flags for lint comments LINTED, LONGLONG and CONSTCOND.
- * clear_warn_flags is called after function definitions and global and
- * local declarations and definitions. It is also called between
- * the controlling expression and the body of control statements
- * (if, switch, for, while).
- */
 void
-clear_warn_flags(void)
+reset_suppressions(void)
 {
 
 	lwarn = LWARN_ALL;
@@ -1367,7 +1338,6 @@ getsym(sbuf_t *sb)
 
 	/* create a new symbol table entry */
 
-	/* labels must always be allocated at level 1 (outermost block) */
 	decl_level *dl;
 	if (sym_kind == SK_LABEL) {
 		sym = level_zero_alloc(1, sizeof(*sym), "sym");
@@ -1440,12 +1410,11 @@ mktempsym(type_t *tp)
 	return sym;
 }
 
-/* Remove a symbol forever from the symbol table. */
 void
-rmsym(sym_t *sym)
+symtab_remove_forever(sym_t *sym)
 {
 
-	debug_step("rmsym '%s' %s '%s'",
+	debug_step("%s '%s' %s '%s'", __func__,
 	    sym->s_name, symbol_kind_name(sym->s_kind),
 	    type_name(sym->s_type));
 	symtab_remove(sym);
@@ -1488,11 +1457,6 @@ inssym(int level, sym_t *sym)
 	sym->s_block_level = level;
 	symtab_add(sym);
 
-	/*
-	 * Placing the inner symbols to the beginning of the list ensures that
-	 * these symbols are preferred over symbols from the outer blocks that
-	 * happen to have the same name.
-	 */
 	const sym_t *next = sym->s_symtab_next;
 	if (next != NULL)
 		lint_assert(sym->s_block_level >= next->s_block_level);
@@ -1513,12 +1477,12 @@ clean_up_after_error(void)
 sym_t *
 pushdown(const sym_t *sym)
 {
-	sym_t *nsym;
 
 	debug_step("pushdown '%s' %s '%s'",
 	    sym->s_name, symbol_kind_name(sym->s_kind),
 	    type_name(sym->s_type));
-	nsym = block_zero_alloc(sizeof(*nsym), "sym");
+
+	sym_t *nsym = block_zero_alloc(sizeof(*nsym), "sym");
 	lint_assert(sym->s_block_level <= block_level);
 	nsym->s_name = sym->s_name;
 	nsym->s_def_pos = unique_curr_pos();

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.628 src/usr.bin/xlint/lint1/tree.c:1.629
--- src/usr.bin/xlint/lint1/tree.c:1.628	Wed Mar 27 20:09:43 2024
+++ src/usr.bin/xlint/lint1/tree.c	Fri Mar 29 08:35:32 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.628 2024/03/27 20:09:43 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.629 2024/03/29 08:35:32 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.628 2024/03/27 20:09:43 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.629 2024/03/29 08:35:32 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1014,7 +1014,7 @@ fold_constant_integer(tnode_t *tn)
 
 	val_t *v = xcalloc(1, sizeof(*v));
 	v->v_tspec = tn->tn_type->t_tspec;
-	v->u.integer = convert_integer(res, t, 0);
+	v->u.integer = convert_integer(res, t, size_in_bits(t));
 
 	tnode_t *cn = build_constant(tn->tn_type, v);
 	if (tn->u.ops.left->tn_system_dependent)
@@ -1963,7 +1963,7 @@ remove_unknown_member(tnode_t *tn, sym_t
 {
 	/* type '%s' does not have member '%s' */
 	error(101, type_name(tn->tn_type), msym->s_name);
-	rmsym(msym);
+	symtab_remove_forever(msym);
 	msym->s_kind = SK_MEMBER;
 	msym->s_scl = STRUCT_MEMBER;
 

Reply via email to