Module Name: src
Committed By: rillig
Date: Sat Jan 30 23:15:32 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: tree.c
Log Message:
lint: flatten has_side_effect
Since GCC performs tail call optimization, the generated code is
practically the same.
Replace redundant comments with open questions.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 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/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.198 src/usr.bin/xlint/lint1/tree.c:1.199
--- src/usr.bin/xlint/lint1/tree.c:1.198 Sat Jan 30 23:05:08 2021
+++ src/usr.bin/xlint/lint1/tree.c Sat Jan 30 23:15:32 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.198 2021/01/30 23:05:08 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.199 2021/01/30 23:15:32 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.198 2021/01/30 23:05:08 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.199 2021/01/30 23:15:32 rillig Exp $");
#endif
#include <float.h>
@@ -3771,32 +3771,30 @@ expr(tnode_t *tn, bool vctx, bool tctx,
}
static bool
-has_side_effect(const tnode_t *tn)
+has_side_effect(const tnode_t *tn) // NOLINT(misc-no-recursion)
{
- while (!modtab[tn->tn_op].m_has_side_effect) {
- if (tn->tn_op == CVT && tn->tn_type->t_tspec == VOID) {
- tn = tn->tn_left;
- } else if (tn->tn_op == LOGAND || tn->tn_op == LOGOR) {
- /*
- * && and || have a side effect if the right operand
- * has a side effect.
- */
- tn = tn->tn_right;
- } else if (tn->tn_op == QUEST) {
- /*
- * ? has a side effect if at least one of its right
- * operands has a side effect
- */
- tn = tn->tn_right;
- } else if (tn->tn_op == COLON || tn->tn_op == COMMA) {
- return has_side_effect(tn->tn_left) ||
- has_side_effect(tn->tn_right);
- } else {
- return false;
- }
+ op_t op = tn->tn_op;
+
+ if (modtab[op].m_has_side_effect)
+ return true;
+
+ if (op == CVT && tn->tn_type->t_tspec == VOID)
+ return has_side_effect(tn->tn_left);
+
+ /* XXX: Why not has_side_effect(tn->tn_left) as well? */
+ if (op == LOGAND || op == LOGOR)
+ return has_side_effect(tn->tn_right);
+
+ /* XXX: Why not has_side_effect(tn->tn_left) as well? */
+ if (op == QUEST)
+ return has_side_effect(tn->tn_right);
+
+ if (op == COLON || op == COMMA) {
+ return has_side_effect(tn->tn_left) ||
+ has_side_effect(tn->tn_right);
}
- return modtab[tn->tn_op].m_has_side_effect;
+ return false;
}
static void