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: replace wrong comment with assertion



details:   https://anonhg.NetBSD.org/src/rev/467a9b8afc9d
branches:  trunk
changeset: 959908:467a9b8afc9d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 28 19:24:15 2021 +0000

description:
lint: replace wrong comment with assertion

The broad type of a value is indeed stored in the value itself, in the
member v_tspec.  For nodes that refer to this value, it is redundantly
stored, it always equals tn->tn_type->t_tspec.

After initialization, neither tn->tn_type nor val->v_tspec are modified.
This is not ensured by the compiler but has to be analyzed manually.

No functional change.

diffstat:

 usr.bin/xlint/lint1/lint1.h |  15 +++++++--------
 usr.bin/xlint/lint1/tree.c  |   6 +++---
 2 files changed, 10 insertions(+), 11 deletions(-)

diffs (61 lines):

diff -r 635d2c08d4ac -r 467a9b8afc9d usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Feb 28 19:16:05 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Feb 28 19:24:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.68 2021/02/28 19:16:05 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.69 2021/02/28 19:24:15 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -464,18 +464,17 @@
 #endif
 
 static inline bool
-is_nonzero_val(tspec_t t, const val_t *val)
+is_nonzero_val(const val_t *val)
 {
-       return is_floating(t) ? val->v_ldbl != 0.0 : val->v_quad != 0;
+       return is_floating(val->v_tspec)
+           ? val->v_ldbl != 0.0
+           : val->v_quad != 0;
 }
 
 static inline bool
 constant_is_nonzero(const tnode_t *tn)
 {
-       /*
-        * XXX: It's strange that val_t doesn't know itself whether it
-        * holds a floating-point or an integer value.
-        */
        lint_assert(tn->tn_op == CON);
-       return is_nonzero_val(tn->tn_type->t_tspec, tn->tn_val);
+       lint_assert(tn->tn_type->t_tspec == tn->tn_val->v_tspec);
+       return is_nonzero_val(tn->tn_val);
 }
diff -r 635d2c08d4ac -r 467a9b8afc9d usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Feb 28 19:16:05 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Feb 28 19:24:15 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.229 2021/02/28 19:16:05 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.230 2021/02/28 19:24:15 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.229 2021/02/28 19:16:05 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.230 2021/02/28 19:24:15 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2289,7 +2289,7 @@
 
        if (nt == BOOL) {       /* C99 6.3.1.2 */
                nv->v_ansiu = false;
-               nv->v_quad = is_nonzero_val(ot, v) ? 1 : 0;
+               nv->v_quad = is_nonzero_val(v) ? 1 : 0;
                return;
        }
 



Home | Main Index | Thread Index | Old Index