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/5cc9294210b6
branches:  trunk
changeset: 362048:5cc9294210b6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 27 10:31:58 2022 +0000

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

No functional change.

diffstat:

 usr.bin/xlint/lint1/decl.c     |  46 ++++++++++++++++++++---------------------
 usr.bin/xlint/lint1/externs1.h |   6 ++--
 usr.bin/xlint/lint1/init.c     |   6 ++--
 usr.bin/xlint/lint1/tree.c     |  14 ++++++------
 4 files changed, 35 insertions(+), 37 deletions(-)

diffs (292 lines):

diff -r e5015c2db044 -r 5cc9294210b6 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Feb 27 08:31:26 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Feb 27 10:31:58 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.246 2022/02/27 08:31:26 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.247 2022/02/27 10:31:58 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.246 2022/02/27 08:31:26 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.247 2022/02/27 10:31:58 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -159,8 +159,8 @@
 /*
  * Returns a shared type structure for arithmetic types and void.
  *
- * It's important to duplicate this structure (using dup_type() or
- * expr_dup_type()) if it is to be modified (adding qualifiers or anything
+ * It's important to duplicate this structure using block_dup_type or
+ * expr_dup_type if it is to be modified (adding qualifiers or anything
  * else).
  */
 type_t *
@@ -172,7 +172,7 @@
 }
 
 type_t *
-dup_type(const type_t *tp)
+block_dup_type(const type_t *tp)
 {
        type_t  *ntp;
 
@@ -181,10 +181,7 @@
        return ntp;
 }
 
-/*
- * Use expr_dup_type() instead of dup_type() inside expressions (if the
- * allocated memory should be freed after the expr).
- */
+/* Duplicate a type, free the allocated memory after the expression. */
 type_t *
 expr_dup_type(const type_t *tp)
 {
@@ -451,7 +448,7 @@
                if (!tflag)
                        /* modifying typedef with '%s'; only qualifiers... */
                        warning(5, tspec_name(t));
-               td = dup_type(gettyp(merge_signedness(t2, t)));
+               td = block_dup_type(gettyp(merge_signedness(t2, t)));
                td->t_typedef = true;
                return td;
        }
@@ -459,7 +456,7 @@
        if (t == SHORT && (t2 == INT || t2 == UINT)) {
                /* modifying typedef with '%s'; only qualifiers allowed */
                warning(5, "short");
-               td = dup_type(gettyp(t2 == INT ? SHORT : USHORT));
+               td = block_dup_type(gettyp(t2 == INT ? SHORT : USHORT));
                td->t_typedef = true;
                return td;
        }
@@ -484,7 +481,7 @@
                } else if (t2 == DCOMPLEX) {
                        td = gettyp(LCOMPLEX);
                }
-               td = dup_type(td);
+               td = block_dup_type(td);
                td->t_typedef = true;
                return td;
        }
@@ -864,7 +861,7 @@
        }
 
        if (dcs->d_const || dcs->d_volatile) {
-               dcs->d_type = dup_type(dcs->d_type);
+               dcs->d_type = block_dup_type(dcs->d_type);
                dcs->d_type->t_const |= dcs->d_const;
                dcs->d_type->t_volatile |= dcs->d_volatile;
        }
@@ -995,9 +992,10 @@
                                /* function returns illegal type */
                                error(15);
                                if (t == FUNC) {
-                                       *tpp = derive_type(*tpp, PTR);
+                                       *tpp = block_derive_type(*tpp, PTR);
                                } else {
-                                       *tpp = derive_type((*tpp)->t_subt, PTR);
+                                       *tpp = block_derive_type(
+                                           (*tpp)->t_subt, PTR);
                                }
                                return;
                        } else if (tp->t_const || tp->t_volatile) {
@@ -1105,7 +1103,7 @@
                        /* illegal bit-field type '%s' */
                        warning(35, type_name(tp));
                        sz = tp->t_flen;
-                       dsym->s_type = tp = dup_type(gettyp(t = INT));
+                       dsym->s_type = tp = block_dup_type(gettyp(t = INT));
                        if ((tp->t_flen = sz) > size_in_bits(t))
                                tp->t_flen = size_in_bits(t);
                        *inout_t = t;
@@ -1175,7 +1173,7 @@
        } else if (t == FUNC) {
                /* function illegal in structure or union */
                error(38);
-               dsym->s_type = tp = derive_type(tp, t = PTR);
+               dsym->s_type = tp = block_derive_type(tp, t = PTR);
        }
 
        /*
@@ -1259,7 +1257,7 @@
                dsym->s_type = gettyp(UINT);
                dsym->s_block_level = -1;
        }
-       dsym->s_type = dup_type(dsym->s_type);
+       dsym->s_type = block_dup_type(dsym->s_type);
        dsym->s_type->t_bitfield = true;
        dsym->s_type->t_flen = len;
        dsym->s_bitfield = true;
@@ -2014,7 +2012,7 @@
        }
 
        if (dsym->s_scl == TYPEDEF) {
-               dsym->s_type = dup_type(dsym->s_type);
+               dsym->s_type = block_dup_type(dsym->s_type);
                dsym->s_type->t_typedef = true;
                settdsym(dsym->s_type, dsym);
        }
@@ -2370,13 +2368,13 @@
                lint_assert(dst->t_tspec == src->t_tspec);
                if (dst->t_tspec == ARRAY) {
                        if (dst->t_dim == 0 && src->t_dim != 0) {
-                               *dstp = dst = dup_type(dst);
+                               *dstp = dst = block_dup_type(dst);
                                dst->t_dim = src->t_dim;
                                setcomplete(dst, true);
                        }
                } else if (dst->t_tspec == FUNC) {
                        if (!dst->t_proto && src->t_proto) {
-                               *dstp = dst = dup_type(dst);
+                               *dstp = dst = block_dup_type(dst);
                                dst->t_proto = true;
                                dst->t_args = src->t_args;
                        }
@@ -2421,12 +2419,12 @@
                sym->s_type = gettyp(VOID);
 
        if ((t = sym->s_type->t_tspec) == ARRAY) {
-               sym->s_type = derive_type(sym->s_type->t_subt, PTR);
+               sym->s_type = block_derive_type(sym->s_type->t_subt, PTR);
        } else if (t == FUNC) {
                if (tflag)
                        /* a function is declared as an argument: %s */
                        warning(50, sym->s_name);
-               sym->s_type = derive_type(sym->s_type, PTR);
+               sym->s_type = block_derive_type(sym->s_type, PTR);
        } else if (t == FLOAT) {
                if (tflag)
                        sym->s_type = gettyp(DOUBLE);
@@ -2755,7 +2753,7 @@
        }
 
        if (dsym->s_scl == TYPEDEF) {
-               dsym->s_type = dup_type(dsym->s_type);
+               dsym->s_type = block_dup_type(dsym->s_type);
                dsym->s_type->t_typedef = true;
                settdsym(dsym->s_type, dsym);
        }
diff -r e5015c2db044 -r 5cc9294210b6 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sun Feb 27 08:31:26 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sun Feb 27 10:31:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.147 2022/02/27 08:31:26 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.148 2022/02/27 10:31:58 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -168,7 +168,7 @@
 
 extern void    initdecl(void);
 extern type_t  *gettyp(tspec_t);
-extern type_t  *dup_type(const type_t *);
+extern type_t  *block_dup_type(const type_t *);
 extern type_t  *expr_dup_type(const type_t *);
 extern type_t  *expr_unqualified_type(const type_t *);
 extern bool    is_incomplete(const type_t *);
@@ -229,7 +229,7 @@
  * tree.c
  */
 extern const tnode_t *before_conversion(const tnode_t *);
-extern type_t  *derive_type(type_t *, tspec_t);
+extern type_t  *block_derive_type(type_t *, tspec_t);
 extern type_t  *expr_derive_type(type_t *, tspec_t);
 extern bool    is_compiler_builtin(const char *);
 extern tnode_t *build_constant(type_t *, val_t *);
diff -r e5015c2db044 -r 5cc9294210b6 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sun Feb 27 08:31:26 2022 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sun Feb 27 10:31:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.231 2022/02/27 08:31:26 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.232 2022/02/27 10:31:58 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.231 2022/02/27 08:31:26 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.232 2022/02/27 10:31:58 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -249,7 +249,7 @@
 {
        type_t *tp;
 
-       tp = dup_type(sym->s_type);
+       tp = block_dup_type(sym->s_type);
        tp->t_dim = (int)size;
        tp->t_incomplete_array = false;
        sym->s_type = tp;
diff -r e5015c2db044 -r 5cc9294210b6 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Feb 27 08:31:26 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Feb 27 10:31:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.405 2022/02/27 08:31:26 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.406 2022/02/27 10:31:58 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.405 2022/02/27 08:31:26 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.406 2022/02/27 10:31:58 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -104,7 +104,7 @@
 
 /* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */
 type_t *
-derive_type(type_t *tp, tspec_t t)
+block_derive_type(type_t *tp, tspec_t t)
 {
        type_t  *tp2;
 
@@ -173,7 +173,7 @@
                           strcmp(sym->s_name, "__PRETTY_FUNCTION__") == 0)) {
                /* __FUNCTION__/__PRETTY_FUNCTION__ is a GCC extension */
                gnuism(316);
-               sym->s_type = derive_type(gettyp(CHAR), PTR);
+               sym->s_type = block_derive_type(gettyp(CHAR), PTR);
                sym->s_type->t_const = true;
                return;
        }
@@ -182,7 +182,7 @@
                if (!Sflag)
                        /* __func__ is a C9X feature */
                        warning(317);
-               sym->s_type = derive_type(gettyp(CHAR), PTR);
+               sym->s_type = block_derive_type(gettyp(CHAR), PTR);
                sym->s_type->t_const = true;
                return;
        }
@@ -257,7 +257,7 @@
        }
 
        /* XXX if tflag is set, the symbol should be exported to level 0 */
-       sym->s_type = derive_type(sym->s_type, FUNC);
+       sym->s_type = block_derive_type(sym->s_type, FUNC);
 }
 
 /* Create a node for a name (symbol table entry). */
@@ -4562,7 +4562,7 @@
 {
        block_level--;
        mem_block_level--;
-       stmt_exprs->se_sym = mktempsym(dup_type(tn->tn_type));
+       stmt_exprs->se_sym = mktempsym(block_dup_type(tn->tn_type));
        mem_block_level++;
        block_level++;
        /* ({ }) is a GCC extension */



Home | Main Index | Thread Index | Old Index