Module Name:    src
Committed By:   rillig
Date:           Sat Apr 16 22:21:10 UTC 2022

Modified Files:
        src/usr.bin/xlint/lint1: ckbool.c op.h oper.c ops.def tree.c

Log Message:
lint: merge mod_t.m_test_context into m_requires_bool

These two flags mean exactly the same.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/oper.c
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/ops.def
cvs rdiff -u -r1.432 -r1.433 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/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.12 src/usr.bin/xlint/lint1/ckbool.c:1.13
--- src/usr.bin/xlint/lint1/ckbool.c:1.12	Sat Apr  9 15:43:41 2022
+++ src/usr.bin/xlint/lint1/ckbool.c	Sat Apr 16 22:21:10 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.12 2022/04/09 15:43:41 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.13 2022/04/16 22:21:10 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckbool.c,v 1.12 2022/04/09 15:43:41 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.13 2022/04/16 22:21:10 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -156,7 +156,7 @@ typeok_scalar_strict_bool(op_t op, const
 	    !typeok_strict_bool_binary_compatible(op, arg, ln, lt, rn, rt))
 		return false;
 
-	if (mp->m_requires_bool || op == QUEST) {
+	if (mp->m_requires_bool) {
 		bool binary = mp->m_binary;
 		bool lbool = is_typeok_bool_operand(ln);
 		bool ok = true;

Index: src/usr.bin/xlint/lint1/op.h
diff -u src/usr.bin/xlint/lint1/op.h:1.18 src/usr.bin/xlint/lint1/op.h:1.19
--- src/usr.bin/xlint/lint1/op.h:1.18	Sat Apr 16 21:14:33 2022
+++ src/usr.bin/xlint/lint1/op.h	Sat Apr 16 22:21:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: op.h,v 1.18 2022/04/16 21:14:33 rillig Exp $	*/
+/*	$NetBSD: op.h,v 1.19 2022/04/16 22:21:10 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -47,7 +47,6 @@ typedef	struct {
 	bool	m_requires_scalar: 1;
 	bool	m_fold_constant_operands: 1;
 	bool	m_value_context: 1;
-	bool	m_test_context: 1;
 	bool	m_balance_operands: 1;
 	bool	m_has_side_effect: 1;
 	bool	m_warn_if_left_unsigned_in_c90: 1;
@@ -66,7 +65,7 @@ extern const mod_t modtab[];
 #define op(name, repr, \
 		is_binary, is_logical, takes_bool, requires_bool, \
 		is_integer, is_complex, is_arithmetic, is_scalar, \
-		can_fold, is_value, is_test, balances_operands, \
+		can_fold, is_value, unused, balances_operands, \
 		side_effects, left_unsigned, right_unsigned, \
 		precedence_confusion, is_comparison, \
 		valid_on_enum, bad_on_enum, warn_if_eq) \

Index: src/usr.bin/xlint/lint1/oper.c
diff -u src/usr.bin/xlint/lint1/oper.c:1.10 src/usr.bin/xlint/lint1/oper.c:1.11
--- src/usr.bin/xlint/lint1/oper.c:1.10	Mon Aug  2 20:58:39 2021
+++ src/usr.bin/xlint/lint1/oper.c	Sat Apr 16 22:21:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: oper.c,v 1.10 2021/08/02 20:58:39 rillig Exp $	*/
+/*	$NetBSD: oper.c,v 1.11 2022/04/16 22:21:10 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@ const mod_t modtab[NOPS] =
 #define op(name, repr, \
 		is_binary, is_logical, takes_bool, requires_bool, \
 		is_integer, is_complex, is_arithmetic, is_scalar, \
-		can_fold, is_value, is_test, balances_operands, \
+		can_fold, is_value, unused, balances_operands, \
 		side_effects, left_unsigned, right_unsigned, \
 		precedence_confusion, is_comparison, \
 		valid_on_enum, bad_on_enum, warn_if_eq) \
@@ -48,7 +48,7 @@ const mod_t modtab[NOPS] =
 		is_integer	+ 0 > 0, is_complex		+ 0 > 0, \
 		is_arithmetic	+ 0 > 0, is_scalar		+ 0 > 0, \
 		can_fold	+ 0 > 0, is_value		+ 0 > 0, \
-		is_test		+ 0 > 0, balances_operands	+ 0 > 0, \
+		balances_operands + 0 > 0, \
 		side_effects	+ 0 > 0, left_unsigned		+ 0 > 0, \
 		right_unsigned	+ 0 > 0, precedence_confusion	+ 0 > 0, \
 		is_comparison	+ 0 > 0, valid_on_enum		+ 0 > 0, \

Index: src/usr.bin/xlint/lint1/ops.def
diff -u src/usr.bin/xlint/lint1/ops.def:1.27 src/usr.bin/xlint/lint1/ops.def:1.28
--- src/usr.bin/xlint/lint1/ops.def:1.27	Sat Apr 16 21:22:12 2022
+++ src/usr.bin/xlint/lint1/ops.def	Sat Apr 16 22:21:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: ops.def,v 1.27 2022/04/16 21:22:12 rillig Exp $ */
+/*	$NetBSD: ops.def,v 1.28 2022/04/16 22:21:10 rillig Exp $ */
 
 begin_ops()
 
@@ -14,7 +14,7 @@ begin_ops()
  *	warn if left operand unsigned			  x	|
  *	has side effects	- - - - - - - - - - - - x	|
  *	balance operands			      x	|	|
- *	test context				    x	|	|
+ *	(unused)				    x	|	|
  *	value context				  x	|	|
  *	fold constant operands	- - - - - - - - x	|	|
  *	requires scalar			      x	|	|	|
@@ -26,11 +26,11 @@ begin_ops()
  *	logical			  x	|	|	|	|
  *	binary			x	|	|	|	|
  */
-/*	name	repr		b l b B i c a s f v t b s l r p c e e =	*/
+/*	name	repr		b l b B i c a s f v - b s l r p c e e =	*/
 op(	NOOP,	"no-op",	 , , , , , , , , , , , , , , , , , , , )
 op(	ARROW,	"->",		1, ,1, , , , , , ,1, , , , , , , , , , )
 op(	POINT,	".",		1, ,1, , , , , , , , , , , , , , , , , )
-op(	NOT,	"!",		 ,1,1,1, , , ,1,1, ,1, , , , , , , ,1, )
+op(	NOT,	"!",		 ,1,1,1, , , ,1,1, , , , , , , , , ,1, )
 op(	COMPL,	"~",		 , , , , ,1, , ,1,1, , , , , , , , ,1,1)
 op(	INC,	"++",		 , , , , , , , , , , , , , , , , , , , )
 op(	DEC,	"--",		 , , , , , , , , , , , , , , , , , , , )
@@ -44,7 +44,7 @@ op(	INDIR,	"*",		 , , , , , , , , ,1, , 
 op(	ADDR,	"&",		 , ,1, , , , , , , , , , , , , , , , , )
 /* the operator 'arr[ind]' is translated to '*(arr + ind)' during parsing. */
 
-/*	name	repr		b l b B i c a s f v t b s l r p c e e = */
+/*	name	repr		b l b B i c a s f v - b s l r p c e e =	*/
 op(	MULT,	"*",		1, , , , , ,1, ,1,1, ,1, , ,1, , , ,1,1)
 op(	DIV,	"/",		1, , , , , ,1, ,1,1, ,1, ,1,1, , , ,1,1)
 op(	MOD,	"%",		1, , , ,1, , , ,1,1, ,1, ,1,1, , , ,1,1)
@@ -53,7 +53,7 @@ op(	MINUS,	"-",		1, , , , , , ,1,1,1, ,1
 op(	SHL,	"<<",		1, , , ,1, , , ,1,1, , , , , ,1, , ,1,1)
 op(	SHR,	">>",		1, , , ,1, , , ,1,1, , , ,1, ,1, , ,1,1)
 
-/*	name	repr		b l b B i c a s f v t b s l r p c e e = */
+/*	name	repr		b l b B i c a s f v - b s l r p c e e =	*/
 op(	LT,	"<",		1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1)
 op(	LE,	"<=",		1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1)
 op(	GT,	">",		1,1, , , , , ,1,1,1, ,1, ,1,1, ,1,1, ,1)
@@ -61,16 +61,16 @@ op(	GE,	">=",		1,1, , , , , ,1,1,1, ,1, 
 op(	EQ,	"==",		1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1)
 op(	NE,	"!=",		1,1,1, , , , ,1,1,1, ,1, , , , ,1,1, ,1)
 
-/*	name	repr		b l b B i c a s f v t b s l r p c e e = */
+/*	name	repr		b l b B i c a s f v - b s l r p c e e =	*/
 op(	BITAND,	"&",		1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, )
 op(	BITXOR,	"^",		1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, )
 op(	BITOR,	"|",		1, ,1, ,1, , , ,1,1, ,1, , , ,1, , ,1, )
-op(	LOGAND,	"&&",		1,1,1,1, , , ,1,1, ,1, , , , , , , ,1, )
-op(	LOGOR,	"||",		1,1,1,1, , , ,1,1, ,1, , , , ,1, , ,1, )
-op(	QUEST,	"?",		1, , , , , , , ,1, ,1, , , , , , , , , )
+op(	LOGAND,	"&&",		1,1,1,1, , , ,1,1, , , , , , , , , ,1, )
+op(	LOGOR,	"||",		1,1,1,1, , , ,1,1, , , , , , ,1, , ,1, )
+op(	QUEST,	"?",		1, , ,1, , , , ,1, , , , , , , , , , , )
 op(	COLON,	":",		1, ,1, , , , , , ,1, ,1, , , , , ,1, , )
 
-/*	name	repr		b l b B i c a s f v t b s l r p c e e = */
+/*	name	repr		b l b B i c a s f v - b s l r p c e e =	*/
 op(	ASSIGN,	"=",		1, ,1, , , , , , , , , ,1, , , , ,1, , )
 op(	MULASS,	"*=",		1, , , , , ,1, , , , , ,1, , , , , ,1, )
 op(	DIVASS,	"/=",		1, , , , , ,1, , , , , ,1, ,1, , , ,1, )
@@ -83,7 +83,7 @@ op(	ANDASS,	"&=",		1, ,1, ,1, , , , , , 
 op(	XORASS,	"^=",		1, ,1, ,1, , , , , , , ,1, , , , , ,1, )
 op(	ORASS,	"|=",		1, ,1, ,1, , , , , , , ,1, , , , , ,1, )
 
-/*	name	repr		b l b B i c a s f v t b s l r p c e e = */
+/*	name	repr		b l b B i c a s f v - b s l r p c e e =	*/
 op(	NAME,	"name",		 , , , , , , , , , , , , , , , , , , , )
 op(	CON,	"constant",	 , , , , , , , , , , , , , , , , , , , )
 op(	STRING,	"string",	 , , , , , , , , , , , , , , , , , , , )
@@ -105,7 +105,7 @@ op(	REAL,	"real",		 , , , , , , , , , , 
 op(	IMAG,	"imag",		 , , , , , , , , , , , , , , , , , , , )
 
 /* INIT, CASE and FARG are pseudo operators that don't appear in the tree. */
-/*	name	repr		b l b B i c a s f v t b s l r p c e e = */
+/*	name	repr		b l b B i c a s f v - b s l r p c e e =	*/
 op(	INIT,	"init",		1, ,1, , , , , , , , , ,1, , , , ,1, , )
 op(	CASE,	"case",		 , , , , , , , , , , , , , , , , , , , )
 /*

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.432 src/usr.bin/xlint/lint1/tree.c:1.433
--- src/usr.bin/xlint/lint1/tree.c:1.432	Sat Apr 16 21:14:33 2022
+++ src/usr.bin/xlint/lint1/tree.c	Sat Apr 16 22:21:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.432 2022/04/16 21:14:33 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.433 2022/04/16 22:21:10 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.432 2022/04/16 21:14:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.433 2022/04/16 22:21:10 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -85,7 +85,7 @@ static	tnode_t	*build_colon(bool, tnode_
 static	tnode_t	*build_assignment(op_t, bool, tnode_t *, tnode_t *);
 static	tnode_t	*plength(type_t *);
 static	tnode_t	*fold(tnode_t *);
-static	tnode_t	*fold_test(tnode_t *);
+static	tnode_t	*fold_bool(tnode_t *);
 static	tnode_t	*fold_float(tnode_t *);
 static	tnode_t	*check_function_arguments(type_t *, tnode_t *);
 static	tnode_t	*check_prototype_argument(int, type_t *, tnode_t *);
@@ -536,7 +536,7 @@ build_binary(tnode_t *ln, op_t op, bool 
 	 * Apply class conversions to the left operand, but only if its
 	 * value is needed or it is compared with zero.
 	 */
-	if (mp->m_value_context || mp->m_test_context)
+	if (mp->m_value_context || mp->m_requires_bool)
 		ln = cconv(ln);
 	/*
 	 * The right operand is almost always in a test or value context,
@@ -555,7 +555,7 @@ build_binary(tnode_t *ln, op_t op, bool 
 	if (mp->m_comparison)
 		check_integer_comparison(op, ln, rn);
 
-	if (mp->m_value_context || mp->m_test_context)
+	if (mp->m_value_context || mp->m_requires_bool)
 		ln = promote(op, false, ln);
 	if (mp->m_binary && op != ARROW && op != POINT &&
 	    op != ASSIGN && op != RETURN && op != INIT) {
@@ -664,7 +664,7 @@ build_binary(tnode_t *ln, op_t op, bool 
 	 * it is compared with zero and if this operand is a constant.
 	 */
 	if (hflag && !constcond_flag &&
-	    mp->m_test_context &&
+	    mp->m_requires_bool &&
 	    (ln->tn_op == CON ||
 	     ((mp->m_binary && op != QUEST) && rn->tn_op == CON)) &&
 	    /* XXX: rn->tn_system_dependent should be checked as well */
@@ -676,8 +676,8 @@ build_binary(tnode_t *ln, op_t op, bool 
 	/* Fold if the operator requires it */
 	if (mp->m_fold_constant_operands) {
 		if (ln->tn_op == CON && (!mp->m_binary || rn->tn_op == CON)) {
-			if (mp->m_test_context) {
-				ntn = fold_test(ntn);
+			if (mp->m_requires_bool) {
+				ntn = fold_bool(ntn);
 			} else if (is_floating(ntn->tn_type->t_tspec)) {
 				ntn = fold_float(ntn);
 			} else {
@@ -3292,11 +3292,10 @@ fold(tnode_t *tn)
 }
 
 /*
- * Fold constant nodes, as much as is needed for comparing the value with 0
- * (test context, for controlling expressions).
+ * Fold constant nodes, as much as is needed for comparing the value with 0.
  */
 static tnode_t *
-fold_test(tnode_t *tn)
+fold_bool(tnode_t *tn)
 {
 	bool	l, r;
 	val_t	*v;
@@ -3878,7 +3877,7 @@ is_constcond_false(const tnode_t *tn, ts
  * memory which is used for the expression.
  */
 void
-expr(tnode_t *tn, bool vctx, bool tctx, bool dofreeblk, bool is_do_while)
+expr(tnode_t *tn, bool vctx, bool cond, bool dofreeblk, bool is_do_while)
 {
 
 	if (tn == NULL) {	/* in case of errors */
@@ -3890,13 +3889,13 @@ expr(tnode_t *tn, bool vctx, bool tctx, 
 	if (dcs->d_kind != DK_EXTERN && !is_do_while)
 		check_statement_reachable();
 
-	check_expr_misc(tn, vctx, tctx, !tctx, false, false, false);
+	check_expr_misc(tn, vctx, cond, !cond, false, false, false);
 	if (tn->tn_op == ASSIGN) {
-		if (hflag && tctx)
+		if (hflag && cond)
 			/* assignment in conditional context */
 			warning(159);
 	} else if (tn->tn_op == CON) {
-		if (hflag && tctx && !constcond_flag &&
+		if (hflag && cond && !constcond_flag &&
 		    !tn->tn_system_dependent &&
 		    !(is_do_while &&
 		      is_constcond_false(tn, tn->tn_type->t_tspec)))
@@ -3908,7 +3907,7 @@ expr(tnode_t *tn, bool vctx, bool tctx, 
 		 * for left operands of COMMA this warning is already
 		 * printed
 		 */
-		if (tn->tn_op != COMMA && !vctx && !tctx)
+		if (tn->tn_op != COMMA && !vctx && !cond)
 			check_null_effect(tn);
 	}
 	debug_node(tn);
@@ -4054,18 +4053,18 @@ check_expr_assign(const tnode_t *ln, boo
 
 static void
 check_expr_call(const tnode_t *tn, const tnode_t *ln,
-		bool szof, bool vctx, bool tctx, bool retval_discarded)
+		bool szof, bool vctx, bool cond, bool retval_discarded)
 {
 	lint_assert(ln->tn_op == ADDR);
 	lint_assert(ln->tn_left->tn_op == NAME);
 	if (!szof &&
 	    !is_compiler_builtin(ln->tn_left->tn_sym->s_name))
-		outcall(tn, vctx || tctx, retval_discarded);
+		outcall(tn, vctx || cond, retval_discarded);
 }
 
 static bool
 check_expr_op(const tnode_t *tn, op_t op, const tnode_t *ln,
-	      bool szof, bool fcall, bool vctx, bool tctx,
+	      bool szof, bool fcall, bool vctx, bool cond,
 	      bool retval_discarded, bool eqwarn)
 {
 	switch (op) {
@@ -4098,7 +4097,7 @@ check_expr_op(const tnode_t *tn, op_t op
 		check_expr_assign(ln, szof);
 		break;
 	case CALL:
-		check_expr_call(tn, ln, szof, vctx, tctx, retval_discarded);
+		check_expr_call(tn, ln, szof, vctx, cond, retval_discarded);
 		break;
 	case EQ:
 		if (hflag && eqwarn)
@@ -4153,13 +4152,13 @@ check_expr_op(const tnode_t *tn, op_t op
 }
 
 void
-check_expr_misc(const tnode_t *tn, bool vctx, bool tctx,
+check_expr_misc(const tnode_t *tn, bool vctx, bool cond,
 		bool eqwarn, bool fcall, bool retval_discarded, bool szof)
 {
 	tnode_t *ln, *rn;
 	const mod_t *mp;
 	op_t op;
-	bool cvctx, ctctx, eq, discard;
+	bool cvctx, ccond, eq, discard;
 
 	if (tn == NULL)
 		return;
@@ -4169,11 +4168,11 @@ check_expr_misc(const tnode_t *tn, bool 
 	mp = &modtab[op = tn->tn_op];
 
 	if (!check_expr_op(tn, op, ln,
-	    szof, fcall, vctx, tctx, retval_discarded, eqwarn))
+	    szof, fcall, vctx, cond, retval_discarded, eqwarn))
 		return;
 
 	cvctx = mp->m_value_context;
-	ctctx = mp->m_test_context;
+	ccond = mp->m_requires_bool;
 	eq = mp->m_warn_if_operand_eq &&
 	     !ln->tn_parenthesized &&
 	     rn != NULL && !rn->tn_parenthesized;
@@ -4185,9 +4184,9 @@ check_expr_misc(const tnode_t *tn, bool 
 	 * context for both operands of COLON
 	 */
 	if (op == COLON && tn->tn_type->t_tspec == VOID)
-		cvctx = ctctx = false;
+		cvctx = ccond = false;
 	discard = op == CVT && tn->tn_type->t_tspec == VOID;
-	check_expr_misc(ln, cvctx, ctctx, eq, op == CALL, discard, szof);
+	check_expr_misc(ln, cvctx, ccond, eq, op == CALL, discard, szof);
 
 	switch (op) {
 	case PUSH:
@@ -4200,10 +4199,10 @@ check_expr_misc(const tnode_t *tn, bool 
 		check_expr_misc(rn, false, true, eq, false, false, szof);
 		break;
 	case COLON:
-		check_expr_misc(rn, cvctx, ctctx, eq, false, false, szof);
+		check_expr_misc(rn, cvctx, ccond, eq, false, false, szof);
 		break;
 	case COMMA:
-		check_expr_misc(rn, vctx, tctx, eq, false, false, szof);
+		check_expr_misc(rn, vctx, cond, eq, false, false, szof);
 		break;
 	default:
 		if (mp->m_binary)

Reply via email to