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: reduce memory allocations



details:   https://anonhg.NetBSD.org/src/rev/647ca93e6aef
branches:  trunk
changeset: 376618:647ca93e6aef
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 24 20:50:54 2023 +0000

description:
lint: reduce memory allocations

The type val_t has the same size as the tn_s member in the same union.

No functional change.

diffstat:

 usr.bin/xlint/lint1/ckbool.c |    6 +-
 usr.bin/xlint/lint1/debug.c  |   16 ++--
 usr.bin/xlint/lint1/emit1.c  |    6 +-
 usr.bin/xlint/lint1/func.c   |    8 +-
 usr.bin/xlint/lint1/lint1.h  |   12 +-
 usr.bin/xlint/lint1/tree.c   |  131 +++++++++++++++++++++---------------------
 6 files changed, 90 insertions(+), 89 deletions(-)

diffs (truncated from 539 to 300 lines):

diff -r c06f3ae827cd -r 647ca93e6aef usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c      Sat Jun 24 17:50:31 2023 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c      Sat Jun 24 20:50:54 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.21 2023/05/22 12:55:04 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.22 2023/06/24 20:50:54 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.21 2023/05/22 12:55:04 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.22 2023/06/24 20:50:54 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -79,7 +79,7 @@ is_symmetric_bool_or_other(op_t op)
 static bool
 is_int_constant_zero(const tnode_t *tn, tspec_t t)
 {
-       return t == INT && tn->tn_op == CON && tn->tn_val->v_quad == 0;
+       return t == INT && tn->tn_op == CON && tn->tn_val.v_quad == 0;
 }
 
 static bool
diff -r c06f3ae827cd -r 647ca93e6aef usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sat Jun 24 17:50:31 2023 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Jun 24 20:50:54 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.35 2023/06/24 08:11:12 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.36 2023/06/24 20:50:54 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: debug.c,v 1.35 2023/06/24 08:11:12 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.36 2023/06/24 20:50:54 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -184,21 +184,21 @@ debug_node(const tnode_t *tn) // NOLINT(
                break;
        case CON:
                if (is_floating(tn->tn_type->t_tspec))
-                       debug_printf(", value %Lg", tn->tn_val->v_ldbl);
+                       debug_printf(", value %Lg", tn->tn_val.v_ldbl);
                else if (is_uinteger(tn->tn_type->t_tspec))
                        debug_printf(", value %llu",
-                           (unsigned long long)tn->tn_val->v_quad);
+                           (unsigned long long)tn->tn_val.v_quad);
                else if (is_integer(tn->tn_type->t_tspec))
                        debug_printf(", value %lld",
-                           (long long)tn->tn_val->v_quad);
+                           (long long)tn->tn_val.v_quad);
                else {
                        lint_assert(tn->tn_type->t_tspec == BOOL);
                        debug_printf(", value %s",
-                           tn->tn_val->v_quad != 0 ? "true" : "false");
+                           tn->tn_val.v_quad != 0 ? "true" : "false");
                }
-               if (tn->tn_val->v_unsigned_since_c90)
+               if (tn->tn_val.v_unsigned_since_c90)
                        debug_printf(", unsigned_since_c90");
-               if (tn->tn_val->v_char_constant)
+               if (tn->tn_val.v_char_constant)
                        debug_printf(", char_constant");
                debug_printf("\n");
                break;
diff -r c06f3ae827cd -r 647ca93e6aef usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c       Sat Jun 24 17:50:31 2023 +0000
+++ b/usr.bin/xlint/lint1/emit1.c       Sat Jun 24 20:50:54 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.68 2023/06/09 15:36:31 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.69 2023/06/24 20:50:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit1.c,v 1.68 2023/06/09 15:36:31 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.69 2023/06/24 20:50:54 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -372,7 +372,7 @@ outcall(const tnode_t *tn, bool retval_u
                                 * XXX it would probably be better to
                                 * explicitly test the sign
                                 */
-                               if ((q = arg->tn_val->v_quad) == 0) {
+                               if ((q = arg->tn_val.v_quad) == 0) {
                                        /* zero constant */
                                        outchar('z');
                                } else if (!msb(q, t)) {
diff -r c06f3ae827cd -r 647ca93e6aef usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Jun 24 17:50:31 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Jun 24 20:50:54 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.156 2023/06/09 15:36:31 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.157 2023/06/24 20:50:54 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.156 2023/06/09 15:36:31 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.157 2023/06/24 20:50:54 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -454,8 +454,8 @@ check_case_label_bitand(const tnode_t *c
                return;
 
        lint_assert(case_expr->tn_op == CON);
-       case_value = case_expr->tn_val->v_quad;
-       mask = switch_expr->tn_right->tn_val->v_quad;
+       case_value = case_expr->tn_val.v_quad;
+       mask = switch_expr->tn_right->tn_val.v_quad;
 
        if ((case_value & ~mask) != 0) {
                /* statement not reached */
diff -r c06f3ae827cd -r 647ca93e6aef usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Jun 24 17:50:31 2023 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Jun 24 20:50:54 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.166 2023/06/24 08:11:12 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.167 2023/06/24 20:50:54 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -315,7 +315,7 @@ typedef     struct tnode {
                        struct  tnode *_tn_right;       /* right operand */
                } tn_s;
                sym_t   *_tn_sym;       /* symbol if op == NAME */
-               val_t   *_tn_val;       /* value if op == CON */
+               val_t   _tn_val;        /* value if op == CON */
                strg_t  *_tn_string;    /* string if op == STRING */
        } tn_u;
 } tnode_t;
@@ -528,20 +528,20 @@ static inline bool
 constant_is_nonzero(const tnode_t *tn)
 {
        lint_assert(tn->tn_op == CON);
-       lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec);
-       return is_nonzero_val(tn->tn_val);
+       lint_assert(tn->tn_type->t_tspec == tn->tn_val.v_tspec);
+       return is_nonzero_val(&tn->tn_val);
 }
 
 static inline bool
 is_zero(const tnode_t *tn)
 {
-       return tn != NULL && tn->tn_op == CON && !is_nonzero_val(tn->tn_val);
+       return tn != NULL && tn->tn_op == CON && !is_nonzero_val(&tn->tn_val);
 }
 
 static inline bool
 is_nonzero(const tnode_t *tn)
 {
-       return tn != NULL && tn->tn_op == CON && is_nonzero_val(tn->tn_val);
+       return tn != NULL && tn->tn_op == CON && is_nonzero_val(&tn->tn_val);
 }
 
 static inline bool
diff -r c06f3ae827cd -r 647ca93e6aef usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jun 24 17:50:31 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jun 24 20:50:54 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.530 2023/06/24 17:50:31 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.531 2023/06/24 20:50:54 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.530 2023/06/24 17:50:31 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.531 2023/06/24 20:50:54 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -276,7 +276,7 @@ ic_expr(const tnode_t *tn)
 
        switch (tn->tn_op) {
        case CON:
-               return ic_con(tn->tn_type, tn->tn_val);
+               return ic_con(tn->tn_type, &tn->tn_val);
        case CVT:
                if (!is_integer(tn->tn_left->tn_type->t_tspec))
                        return ic_any(tn->tn_type);
@@ -373,11 +373,10 @@ build_constant(type_t *tp, val_t *v)
        n = expr_alloc_tnode();
        n->tn_op = CON;
        n->tn_type = tp;
-       n->tn_val = expr_zero_alloc(sizeof(*n->tn_val));
-       n->tn_val->v_tspec = tp->t_tspec;
-       n->tn_val->v_unsigned_since_c90 = v->v_unsigned_since_c90;
-       n->tn_val->v_char_constant = v->v_char_constant;
-       n->tn_val->v_u = v->v_u;
+       n->tn_val.v_tspec = tp->t_tspec;
+       n->tn_val.v_unsigned_since_c90 = v->v_unsigned_since_c90;
+       n->tn_val.v_char_constant = v->v_char_constant;
+       n->tn_val.v_u = v->v_u;
        free(v);
        return n;
 }
@@ -390,9 +389,10 @@ build_integer_constant(tspec_t t, int64_
        n = expr_alloc_tnode();
        n->tn_op = CON;
        n->tn_type = gettyp(t);
-       n->tn_val = expr_zero_alloc(sizeof(*n->tn_val));
-       n->tn_val->v_tspec = t;
-       n->tn_val->v_quad = q;
+       n->tn_val.v_tspec = t;
+       n->tn_val.v_unsigned_since_c90 = false;
+       n->tn_val.v_char_constant = false;
+       n->tn_val.v_quad = q;
        return n;
 }
 
@@ -507,14 +507,16 @@ build_name(sym_t *sym, bool is_funcname)
        n->tn_type = sym->s_type;
        if (sym->s_scl == BOOL_CONST) {
                n->tn_op = CON;
-               n->tn_val = expr_zero_alloc(sizeof(*n->tn_val));
-               n->tn_val->v_tspec = BOOL;
-               n->tn_val->v_quad = sym->u.s_bool_constant ? 1 : 0;
+               n->tn_val.v_tspec = BOOL;
+               n->tn_val.v_unsigned_since_c90 = false;
+               n->tn_val.v_char_constant = false;
+               n->tn_val.v_quad = sym->u.s_bool_constant ? 1 : 0;
        } else if (sym->s_scl == ENUM_CONST) {
                n->tn_op = CON;
-               n->tn_val = expr_zero_alloc(sizeof(*n->tn_val));
-               n->tn_val->v_tspec = INT;       /* ENUM is in n->tn_type */
-               n->tn_val->v_quad = sym->u.s_enum_constant;
+               n->tn_val.v_tspec = INT;        /* ENUM is in n->tn_type */
+               n->tn_val.v_unsigned_since_c90 = false;
+               n->tn_val.v_char_constant = false;
+               n->tn_val.v_quad = sym->u.s_enum_constant;
        } else {
                n->tn_op = NAME;
                n->tn_sym = sym;
@@ -580,9 +582,9 @@ static bool
 is_out_of_char_range(const tnode_t *tn)
 {
        return tn->tn_op == CON &&
-              !tn->tn_val->v_char_constant &&
-              !(0 <= tn->tn_val->v_quad &&
-                tn->tn_val->v_quad < 1 << (CHAR_SIZE - 1));
+              !tn->tn_val.v_char_constant &&
+              !(0 <= tn->tn_val.v_quad &&
+                tn->tn_val.v_quad < 1 << (CHAR_SIZE - 1));
 }
 
 static void
@@ -601,16 +603,16 @@ check_integer_comparison(op_t op, tnode_
 
        if (any_query_enabled && !in_system_header) {
                if (lt == CHAR && rn->tn_op == CON &&
-                   !rn->tn_val->v_char_constant) {
+                   !rn->tn_val.v_char_constant) {
                        /* comparison '%s' of 'char' with plain integer %d */
                        query_message(14,
-                           op_name(op), (int)rn->tn_val->v_quad);
+                           op_name(op), (int)rn->tn_val.v_quad);
                }
                if (rt == CHAR && ln->tn_op == CON &&
-                   !ln->tn_val->v_char_constant) {
+                   !ln->tn_val.v_char_constant) {
                        /* comparison '%s' of 'char' with plain integer %d */
                        query_message(14,
-                           op_name(op), (int)ln->tn_val->v_quad);
+                           op_name(op), (int)ln->tn_val.v_quad);
                }
        }
 
@@ -618,7 +620,7 @@ check_integer_comparison(op_t op, tnode_
                if (lt == CHAR && is_out_of_char_range(rn)) {
                        char buf[128];
                        (void)snprintf(buf, sizeof(buf), "%s %d",
-                           op_name(op), (int)rn->tn_val->v_quad);
+                           op_name(op), (int)rn->tn_val.v_quad);
                        /* nonportable character comparison '%s' */
                        warning(230, buf);
                        return;
@@ -626,7 +628,7 @@ check_integer_comparison(op_t op, tnode_
                if (rt == CHAR && is_out_of_char_range(ln)) {
                        char buf[128];
                        (void)snprintf(buf, sizeof(buf), "%d %s ?",
-                           (int)ln->tn_val->v_quad, op_name(op));



Home | Main Index | Thread Index | Old Index