Module Name:    src
Committed By:   rillig
Date:           Sun Feb 28 19:24:15 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: lint1.h tree.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.229 -r1.230 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.68 src/usr.bin/xlint/lint1/lint1.h:1.69
--- src/usr.bin/xlint/lint1/lint1.h:1.68	Sun Feb 28 19:16:05 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Sun Feb 28 19:24:15 2021
@@ -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 @@ check_printf(const char *fmt, ...)
 #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);
 }

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.229 src/usr.bin/xlint/lint1/tree.c:1.230
--- src/usr.bin/xlint/lint1/tree.c:1.229	Sun Feb 28 19:16:05 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Feb 28 19:24:15 2021
@@ -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 @@ convert_constant(op_t op, int arg, type_
 
 	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;
 	}
 

Reply via email to