Module Name: src Committed By: rillig Date: Sat Jul 29 07:49:15 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: gcc_init_compound_literal.c src/usr.bin/xlint/lint1: decl.c externs1.h func.c main1.c Log Message: lint: condense code for ending a function No functional change. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 \ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c cvs rdiff -u -r1.365 -r1.366 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.201 -r1.202 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.171 -r1.172 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.75 -r1.76 src/usr.bin/xlint/lint1/main1.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c diff -u src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.7 src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.8 --- src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.7 Tue Mar 28 14:44:34 2023 +++ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c Sat Jul 29 07:49:15 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: gcc_init_compound_literal.c,v 1.7 2023/03/28 14:44:34 rillig Exp $ */ +/* $NetBSD: gcc_init_compound_literal.c,v 1.8 2023/07/29 07:49:15 rillig Exp $ */ # 3 "gcc_init_compound_literal.c" /* @@ -13,9 +13,9 @@ * object created by a compound literal (C99 6.5.2.5), using either an * explicit '&' or the implicit array-to-pointer conversion from C99 6.3.2.1. * - * Before init.c 1.195 from 2021-04-17, lint failed with an assertion failure - * in check_global_variable, called by check_global_symbols since these - * temporary objects have neither storage class EXTERN nor STATIC. + * Before init.c 1.195 from 2021-04-17, an assertion in check_global_variable + * failed since these temporary objects have neither storage class EXTERN nor + * STATIC. */ /* lint1-extra-flags: -X 351 */ Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.365 src/usr.bin/xlint/lint1/decl.c:1.366 --- src/usr.bin/xlint/lint1/decl.c:1.365 Sat Jul 29 07:26:53 2023 +++ src/usr.bin/xlint/lint1/decl.c Sat Jul 29 07:49:14 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.365 2023/07/29 07:26:53 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.366 2023/07/29 07:49:14 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.365 2023/07/29 07:26:53 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.366 2023/07/29 07:49:14 rillig Exp $"); #endif #include <sys/param.h> @@ -3095,23 +3095,15 @@ check_global_variable(const sym_t *sym) check_static_global_variable(sym); } -/* - * Called after the entire translation unit has been parsed. - * Changes tentative definitions into definitions. - * Performs some tests on global symbols. Detected problems are: - * - defined variables of incomplete type - * - constant variables which are not initialized - * - static symbols which are never used - */ void -check_global_symbols(void) +end_translation_unit(void) { - sym_t *sym; if (block_level != 0 || dcs->d_enclosing != NULL) norecover(); - for (sym = dcs->d_first_dlsym; sym != NULL; sym = sym->s_level_next) { + for (const sym_t *sym = dcs->d_first_dlsym; + sym != NULL; sym = sym->s_level_next) { if (sym->s_block_level == -1) continue; if (sym->s_kind == FVFT) Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.201 src/usr.bin/xlint/lint1/externs1.h:1.202 --- src/usr.bin/xlint/lint1/externs1.h:1.201 Sat Jul 29 07:26:53 2023 +++ src/usr.bin/xlint/lint1/externs1.h Sat Jul 29 07:49:14 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.201 2023/07/29 07:26:53 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.202 2023/07/29 07:49:14 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -255,7 +255,7 @@ void mark_as_set(sym_t *); void mark_as_used(sym_t *, bool, bool); void check_usage(const decl_level *); void check_usage_sym(bool, const sym_t *); -void check_global_symbols(void); +void end_translation_unit(void); void print_previous_declaration(const sym_t *); int to_int_constant(tnode_t *, bool); Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.171 src/usr.bin/xlint/lint1/func.c:1.172 --- src/usr.bin/xlint/lint1/func.c:1.171 Sat Jul 15 13:35:24 2023 +++ src/usr.bin/xlint/lint1/func.c Sat Jul 29 07:49:14 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.171 2023/07/15 13:35:24 rillig Exp $ */ +/* $NetBSD: func.c,v 1.172 2023/07/29 07:49:14 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.171 2023/07/15 13:35:24 rillig Exp $"); +__RCSID("$NetBSD: func.c,v 1.172 2023/07/29 07:49:14 rillig Exp $"); #endif #include <stdlib.h> @@ -361,8 +361,6 @@ check_missing_return_value(void) void end_function(void) { - sym_t *arg; - int n; if (reached) { cstmt->c_had_return_noval = true; @@ -379,15 +377,12 @@ end_function(void) /* function '%s' has 'return expr' and 'return' */ warning(216, funcsym->s_name); - /* Print warnings for unused arguments */ - arg = dcs->d_func_args; - n = 0; - while (arg != NULL && (nargusg == -1 || n < nargusg)) { - check_usage_sym(dcs->d_asm, arg); - arg = arg->s_next; - n++; - } + /* Warn about unused parameters. */ + int n = nargusg; nargusg = -1; + for (sym_t *arg = dcs->d_func_args; + arg != NULL && n != 0; arg = arg->s_next, n--) + check_usage_sym(dcs->d_asm, arg); /* * write the information about the function definition to the Index: src/usr.bin/xlint/lint1/main1.c diff -u src/usr.bin/xlint/lint1/main1.c:1.75 src/usr.bin/xlint/lint1/main1.c:1.76 --- src/usr.bin/xlint/lint1/main1.c:1.75 Sat Jul 29 06:44:44 2023 +++ src/usr.bin/xlint/lint1/main1.c Sat Jul 29 07:49:14 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: main1.c,v 1.75 2023/07/29 06:44:44 rillig Exp $ */ +/* $NetBSD: main1.c,v 1.76 2023/07/29 07:49:14 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: main1.c,v 1.75 2023/07/29 06:44:44 rillig Exp $"); +__RCSID("$NetBSD: main1.c,v 1.76 2023/07/29 07:49:14 rillig Exp $"); #endif #include <sys/types.h> @@ -254,7 +254,7 @@ main(int argc, char *argv[]) lwarn = LWARN_ALL; debug_step("main lwarn = %d", lwarn); - check_global_symbols(); + end_translation_unit(); outclose();