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: encode lifetime of allocated memor...



details:   https://anonhg.NetBSD.org/src/rev/e5015c2db044
branches:  trunk
changeset: 362047:e5015c2db044
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 27 08:31:26 2022 +0000

description:
lint: encode lifetime of allocated memory in the function names

No functional change.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c |   4 +-
 usr.bin/xlint/lint1/cgram.y                   |  16 ++++----
 usr.bin/xlint/lint1/decl.c                    |  32 +++++++++---------
 usr.bin/xlint/lint1/externs1.h                |  15 ++++----
 usr.bin/xlint/lint1/func.c                    |   6 +-
 usr.bin/xlint/lint1/init.c                    |   6 +-
 usr.bin/xlint/lint1/lex.c                     |  24 +++++++-------
 usr.bin/xlint/lint1/mem1.c                    |  39 +++++++---------------
 usr.bin/xlint/lint1/tree.c                    |  44 +++++++++++++-------------
 9 files changed, 86 insertions(+), 100 deletions(-)

diffs (truncated from 652 to 300 lines):

diff -r 7a763dd8671e -r e5015c2db044 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Feb 27 07:50:09 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Feb 27 08:31:26 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.36 2022/01/15 14:22:03 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.37 2022/02/27 08:31:26 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -1042,7 +1042,7 @@
        /*
         * Before cgram.y 1.369 from 2021-11-16, the comment following
         * 'stdio_stdout' did not prevent the search for '('.  At the point
-        * where build_name called expr_zalloc_tnode, the parser was already
+        * where build_name called expr_alloc_tnode, the parser was already
         * in the main file again, thus treating 'stdio_stdout' as not coming
         * from a system header.
         *
diff -r 7a763dd8671e -r e5015c2db044 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sun Feb 27 07:50:09 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sun Feb 27 08:31:26 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.382 2022/02/27 01:47:28 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.383 2022/02/27 08:31:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.382 2022/02/27 01:47:28 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.383 2022/02/27 08:31:26 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -58,7 +58,7 @@
  * for these can't be freed after the declaration, but symbols must
  * be removed from the symbol table after the declaration.
  */
-int    mem_block_level;
+size_t mem_block_level;
 
 /*
  * Save the no-warns state and restore it to avoid the problem where
@@ -477,12 +477,12 @@
 /* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
 generic_association:
          type_name T_COLON assignment_expression {
-               $$ = getblk(sizeof(*$$));
+               $$ = block_zero_alloc(sizeof(*$$));
                $$->ga_arg = $1;
                $$->ga_result = $3;
          }
        | T_DEFAULT T_COLON assignment_expression {
-               $$ = getblk(sizeof(*$$));
+               $$ = block_zero_alloc(sizeof(*$$));
                $$->ga_arg = NULL;
                $$->ga_result = $3;
          }
@@ -549,12 +549,12 @@
                $$ = NULL;
          }
        | non_expr_statement {
-               $$ = expr_zalloc_tnode();
+               $$ = expr_alloc_tnode();
                $$->tn_type = gettyp(VOID);
          }
        | expression T_SEMI {
                if ($1 == NULL) {       /* in case of syntax errors */
-                       $$ = expr_zalloc_tnode();
+                       $$ = expr_alloc_tnode();
                        $$->tn_type = gettyp(VOID);
                } else {
                        /* XXX: do that only on the last name */
@@ -1692,7 +1692,7 @@
 compound_statement_rbrace:
          T_RBRACE {
                end_declaration_level();
-               freeblk();
+               level_free_all(mem_block_level);
                mem_block_level--;
                block_level--;
                seen_fallthrough = false;
diff -r 7a763dd8671e -r e5015c2db044 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Feb 27 07:50:09 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Feb 27 08:31:26 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.245 2022/02/27 01:47:28 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.246 2022/02/27 08:31:26 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.245 2022/02/27 01:47:28 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.246 2022/02/27 08:31:26 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -176,7 +176,7 @@
 {
        type_t  *ntp;
 
-       ntp = getblk(sizeof(*ntp));
+       ntp = block_zero_alloc(sizeof(*ntp));
        *ntp = *tp;
        return ntp;
 }
@@ -190,7 +190,7 @@
 {
        type_t  *ntp;
 
-       ntp = expr_zalloc(sizeof(*ntp));
+       ntp = expr_zero_alloc(sizeof(*ntp));
        *ntp = *tp;
        return ntp;
 }
@@ -206,7 +206,7 @@
 {
        type_t *ntp;
 
-       ntp = expr_zalloc(sizeof(*ntp));
+       ntp = expr_zero_alloc(sizeof(*ntp));
        *ntp = *tp;
        ntp->t_const = false;
        ntp->t_volatile = false;
@@ -1252,7 +1252,7 @@
 {
 
        if (dsym == NULL) {
-               dsym = getblk(sizeof(*dsym));
+               dsym = block_zero_alloc(sizeof(*dsym));
                dsym->s_name = unnamed;
                dsym->s_kind = FMEMBER;
                dsym->s_scl = MOS;
@@ -1328,7 +1328,7 @@
                return decl;
 
        while (p != NULL) {
-               *tpp = tp = getblk(sizeof(*tp));
+               *tpp = tp = block_zero_alloc(sizeof(*tp));
                tp->t_tspec = PTR;
                tp->t_const = p->p_const;
                tp->t_volatile = p->p_volatile;
@@ -1355,7 +1355,7 @@
        if (*tpp == NULL)
            return decl;
 
-       *tpp = tp = getblk(sizeof(*tp));
+       *tpp = tp = block_zero_alloc(sizeof(*tp));
        tp->t_tspec = ARRAY;
        tp->t_subt = dcs->d_type;
        tp->t_dim = n;
@@ -1418,7 +1418,7 @@
        if (*tpp == NULL)
            return decl;        /* see msg_347 */
 
-       *tpp = tp = getblk(sizeof(*tp));
+       *tpp = tp = block_zero_alloc(sizeof(*tp));
        tp->t_tspec = FUNC;
        tp->t_subt = dcs->d_next->d_type;
        if ((tp->t_proto = dcs->d_proto) != false)
@@ -1669,19 +1669,19 @@
                }
                if (tag->s_scl == NOSCL) {
                        tag->s_scl = scl;
-                       tag->s_type = tp = getblk(sizeof(*tp));
+                       tag->s_type = tp = block_zero_alloc(sizeof(*tp));
                        tp->t_packed = dcs->d_packed;
                } else {
                        tp = tag->s_type;
                }
        } else {
-               tag = getblk(sizeof(*tag));
+               tag = block_zero_alloc(sizeof(*tag));
                tag->s_name = unnamed;
                UNIQUE_CURR_POS(tag->s_def_pos);
                tag->s_kind = FTAG;
                tag->s_scl = scl;
                tag->s_block_level = -1;
-               tag->s_type = tp = getblk(sizeof(*tp));
+               tag->s_type = tp = block_zero_alloc(sizeof(*tp));
                tp->t_packed = dcs->d_packed;
                dcs->d_next->d_nonempty_decl = true;
        }
@@ -1689,12 +1689,12 @@
        if (tp->t_tspec == NOTSPEC) {
                tp->t_tspec = kind;
                if (kind != ENUM) {
-                       tp->t_str = getblk(sizeof(*tp->t_str));
+                       tp->t_str = block_zero_alloc(sizeof(*tp->t_str));
                        tp->t_str->sou_align_in_bits = CHAR_SIZE;
                        tp->t_str->sou_tag = tag;
                } else {
                        tp->t_is_enum = true;
-                       tp->t_enum = getblk(sizeof(*tp->t_enum));
+                       tp->t_enum = block_zero_alloc(sizeof(*tp->t_enum));
                        tp->t_enum->en_tag = tag;
                }
                setcomplete(tp, false);
@@ -1902,7 +1902,7 @@
        if (renaming != NULL) {
                lint_assert(dsym->s_rename == NULL);
 
-               s = getlblk(1, renaming->sb_len + 1);
+               s = level_zero_alloc(1, renaming->sb_len + 1);
                (void)memcpy(s, renaming->sb_name, renaming->sb_len + 1);
                dsym->s_rename = s;
        }
@@ -2863,7 +2863,7 @@
 
        lint_assert(dcs->d_ctx == ABSTRACT || dcs->d_ctx == PROTO_ARG);
 
-       sym = getblk(sizeof(*sym));
+       sym = block_zero_alloc(sizeof(*sym));
 
        sym->s_name = unnamed;
        sym->s_def = DEF;
diff -r 7a763dd8671e -r e5015c2db044 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sun Feb 27 07:50:09 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sun Feb 27 08:31:26 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.146 2022/02/26 20:36:11 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.147 2022/02/27 08:31:26 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -61,7 +61,7 @@
  * cgram.y
  */
 extern int     block_level;
-extern int     mem_block_level;
+extern size_t  mem_block_level;
 extern int     yydebug;
 
 extern int     yyerror(const char *);
@@ -100,13 +100,12 @@
 
 extern void    initmem(void);
 
-extern void    *getblk(size_t);
-extern void    *getlblk(size_t, size_t);
-extern void    freeblk(void);
-extern void    freelblk(int);
+extern void    *block_zero_alloc(size_t);
+extern void    *level_zero_alloc(size_t, size_t);
+extern void    level_free_all(size_t);
 
-extern void    *expr_zalloc(size_t);
-extern tnode_t *expr_zalloc_tnode(void);
+extern void    *expr_zero_alloc(size_t);
+extern tnode_t *expr_alloc_tnode(void);
 extern void    expr_free_all(void);
 extern struct  memory_block *expr_save_memory(void);
 extern void    expr_restore_memory(struct memory_block *);
diff -r 7a763dd8671e -r e5015c2db044 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Feb 27 07:50:09 2022 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Feb 27 08:31:26 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.126 2021/11/16 21:01:05 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.127 2022/02/27 08:31:26 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.126 2021/11/16 21:01:05 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.127 2022/02/27 08:31:26 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -1086,7 +1086,7 @@
        if (tn != NULL) {
 
                /* Create a temporary node for the left side */
-               ln = expr_zalloc(sizeof(*ln));
+               ln = expr_zero_alloc(sizeof(*ln));
                ln->tn_op = NAME;
                ln->tn_type = expr_unqualified_type(funcsym->s_type->t_subt);
                ln->tn_lvalue = true;
diff -r 7a763dd8671e -r e5015c2db044 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sun Feb 27 07:50:09 2022 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sun Feb 27 08:31:26 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.230 2021/12/22 14:35:23 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.231 2022/02/27 08:31:26 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.230 2021/12/22 14:35:23 rillig Exp $");



Home | Main Index | Thread Index | Old Index