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: condense code for ending a function



details:   https://anonhg.NetBSD.org/src/rev/87d16c41431b
branches:  trunk
changeset: 378279:87d16c41431b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 29 07:49:14 2023 +0000

description:
lint: condense code for ending a function

No functional change.

diffstat:

 tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c |   8 ++++----
 usr.bin/xlint/lint1/decl.c                            |  18 +++++-------------
 usr.bin/xlint/lint1/externs1.h                        |   4 ++--
 usr.bin/xlint/lint1/func.c                            |  19 +++++++------------
 usr.bin/xlint/lint1/main1.c                           |   6 +++---
 5 files changed, 21 insertions(+), 34 deletions(-)

diffs (160 lines):

diff -r 897c09bab2a0 -r 87d16c41431b tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c
--- a/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c     Sat Jul 29 07:26:53 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c     Sat Jul 29 07:49:14 2023 +0000
@@ -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 */
diff -r 897c09bab2a0 -r 87d16c41431b usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jul 29 07:26:53 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jul 29 07:49:14 2023 +0000
@@ -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)
diff -r 897c09bab2a0 -r 87d16c41431b usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Jul 29 07:26:53 2023 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Jul 29 07:49:14 2023 +0000
@@ -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);
 
diff -r 897c09bab2a0 -r 87d16c41431b usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Jul 29 07:26:53 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Jul 29 07:49:14 2023 +0000
@@ -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)) {
+       /* 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);
-               arg = arg->s_next;
-               n++;
-       }
-       nargusg = -1;
 
        /*
         * write the information about the function definition to the
diff -r 897c09bab2a0 -r 87d16c41431b usr.bin/xlint/lint1/main1.c
--- a/usr.bin/xlint/lint1/main1.c       Sat Jul 29 07:26:53 2023 +0000
+++ b/usr.bin/xlint/lint1/main1.c       Sat Jul 29 07:49:14 2023 +0000
@@ -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();
 



Home | Main Index | Thread Index | Old Index