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: don't warn about constant conditio...
details: https://anonhg.NetBSD.org/src/rev/df06c633afb9
branches: trunk
changeset: 1018351:df06c633afb9
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 31 12:44:34 2021 +0000
description:
lint: don't warn about constant condition in 'do { } while (0)'
diffstat:
tests/usr.bin/xlint/lint1/msg_161.c | 6 +++---
tests/usr.bin/xlint/lint1/msg_161.exp | 1 -
usr.bin/xlint/lint1/cgram.y | 8 ++++----
usr.bin/xlint/lint1/externs1.h | 4 ++--
usr.bin/xlint/lint1/func.c | 20 ++++++++++----------
usr.bin/xlint/lint1/init.c | 8 ++++----
usr.bin/xlint/lint1/tree.c | 10 ++++++----
7 files changed, 29 insertions(+), 28 deletions(-)
diffs (250 lines):
diff -r c1ce135bbcf2 -r df06c633afb9 tests/usr.bin/xlint/lint1/msg_161.c
--- a/tests/usr.bin/xlint/lint1/msg_161.c Sun Jan 31 12:30:53 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_161.c Sun Jan 31 12:44:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_161.c,v 1.3 2021/01/31 12:30:53 rillig Exp $ */
+/* $NetBSD: msg_161.c,v 1.4 2021/01/31 12:44:34 rillig Exp $ */
# 3 "msg_161.c"
// Test for message: constant in conditional context [161]
@@ -23,14 +23,14 @@
* The pattern 'do { } while (0)' is a common technique to define a
* preprocessor macro that behaves like a single statement. There is
* nothing unusual or surprising about the constant condition.
- * Still, lint warns about it. FIXME don't.
+ * Before tree.c 1.202 from 2021-01-31, lint warned about it.
*/
void
do_while_0(void)
{
do {
- } while (0); /* expect: 161 */
+ } while (0);
}
void
diff -r c1ce135bbcf2 -r df06c633afb9 tests/usr.bin/xlint/lint1/msg_161.exp
--- a/tests/usr.bin/xlint/lint1/msg_161.exp Sun Jan 31 12:30:53 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_161.exp Sun Jan 31 12:44:34 2021 +0000
@@ -1,4 +1,3 @@
msg_161.c(11): warning: constant in conditional context [161]
msg_161.c(18): warning: constant in conditional context [161]
-msg_161.c(33): warning: constant in conditional context [161]
msg_161.c(41): warning: constant in conditional context [161]
diff -r c1ce135bbcf2 -r df06c633afb9 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Sun Jan 31 12:30:53 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Sun Jan 31 12:44:34 2021 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.159 2021/01/31 11:23:01 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.160 2021/01/31 12:44:34 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.159 2021/01/31 11:23:01 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.160 2021/01/31 12:44:34 rillig Exp $");
#endif
#include <limits.h>
@@ -1557,7 +1557,7 @@
expr_statement:
expr T_SEMI {
- expr($1, 0, 0, 0);
+ expr($1, false, false, false, false);
ftflg = false;
}
| T_SEMI {
@@ -1576,7 +1576,7 @@
if ($1->tn_op == NAME)
$1->tn_sym->s_used = true;
$$ = $1;
- expr($1, 0, 0, 0);
+ expr($1, false, false, false, false);
ftflg = false;
}
| non_expr_statement {
diff -r c1ce135bbcf2 -r df06c633afb9 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Sun Jan 31 12:30:53 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Sun Jan 31 12:44:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.64 2021/01/30 18:16:45 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.65 2021/01/31 12:44:34 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -216,7 +216,7 @@
extern tnode_t *new_function_argument_node(tnode_t *, tnode_t *);
extern tnode_t *new_function_call_node(tnode_t *, tnode_t *);
extern val_t *constant(tnode_t *, bool);
-extern void expr(tnode_t *, bool, bool, bool);
+extern void expr(tnode_t *, bool, bool, bool, bool);
extern void check_expr_misc(const tnode_t *, bool, bool, bool,
bool, bool, bool);
extern bool constant_addr(tnode_t *, sym_t **, ptrdiff_t *);
diff -r c1ce135bbcf2 -r df06c633afb9 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c Sun Jan 31 12:30:53 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c Sun Jan 31 12:44:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.66 2021/01/30 18:16:45 rillig Exp $ */
+/* $NetBSD: func.c,v 1.67 2021/01/31 12:44:34 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.66 2021/01/30 18:16:45 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.67 2021/01/31 12:44:34 rillig Exp $");
#endif
#include <stdlib.h>
@@ -569,7 +569,7 @@
if (tn != NULL)
tn = check_controlling_expression(tn);
if (tn != NULL)
- expr(tn, false, true, false);
+ expr(tn, false, true, false, false);
pushctrl(T_IF);
}
@@ -642,7 +642,7 @@
tp->t_tspec = INT;
}
- expr(tn, true, false, true);
+ expr(tn, true, false, true, false);
pushctrl(T_SWITCH);
cstmt->c_switch = true;
@@ -726,7 +726,7 @@
if (tn != NULL && tn->tn_op == CON)
cstmt->c_infinite = is_nonzero(tn);
- expr(tn, false, true, true);
+ expr(tn, false, true, true, false);
}
/*
@@ -789,7 +789,7 @@
error(323);
}
- expr(tn, false, true, true);
+ expr(tn, false, true, true, true);
/*
* The end of the loop is only reached if it is no endless loop
@@ -832,12 +832,12 @@
cstmt->c_cfpos = csrc_pos;
if (tn1 != NULL)
- expr(tn1, false, false, true);
+ expr(tn1, false, false, true, false);
if (tn2 != NULL)
tn2 = check_controlling_expression(tn2);
if (tn2 != NULL)
- expr(tn2, false, true, true);
+ expr(tn2, false, true, true, false);
cstmt->c_infinite =
tn2 == NULL || (tn2->tn_op == CON && is_nonzero(tn2));
@@ -877,7 +877,7 @@
}
if (tn3 != NULL) {
- expr(tn3, false, false, true);
+ expr(tn3, false, false, true, false);
} else {
tfreeblk();
}
@@ -1013,7 +1013,7 @@
}
}
- expr(tn, true, false, true);
+ expr(tn, true, false, true, false);
} else {
diff -r c1ce135bbcf2 -r df06c633afb9 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Sun Jan 31 12:30:53 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Sun Jan 31 12:44:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.65 2021/01/30 18:16:45 rillig Exp $ */
+/* $NetBSD: init.c,v 1.66 2021/01/31 12:44:34 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.65 2021/01/30 18:16:45 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.66 2021/01/31 12:44:34 rillig Exp $");
#endif
#include <stdlib.h>
@@ -584,7 +584,7 @@
ln->tn_type = tduptyp(ln->tn_type);
ln->tn_type->t_const = false;
tn = build(ASSIGN, ln, tn);
- expr(tn, false, false, false);
+ expr(tn, false, false, false, false);
return;
}
@@ -628,7 +628,7 @@
* expr() would free it.
*/
tmem = tsave();
- expr(tn, true, false, true);
+ expr(tn, true, false, true, false);
trestor(tmem);
if (is_integer(lt) && ln->tn_type->t_bitfield && !is_integer(rt)) {
diff -r c1ce135bbcf2 -r df06c633afb9 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Jan 31 12:30:53 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Jan 31 12:44:34 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.201 2021/01/31 12:20:00 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.202 2021/01/31 12:44:34 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.201 2021/01/31 12:20:00 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.202 2021/01/31 12:44:34 rillig Exp $");
#endif
#include <float.h>
@@ -3730,7 +3730,7 @@
* for the expression.
*/
void
-expr(tnode_t *tn, bool vctx, bool tctx, bool dofreeblk)
+expr(tnode_t *tn, bool vctx, bool tctx, bool dofreeblk, bool constcond_zero_ok)
{
lint_assert(tn != NULL || nerr != 0);
@@ -3750,7 +3750,9 @@
/* assignment in conditional context */
warning(159);
} else if (tn->tn_op == CON) {
- if (hflag && tctx && !constcond_flag)
+ if (hflag && tctx && !constcond_flag &&
+ !(constcond_zero_ok &&
+ is_int_constant_zero(tn, tn->tn_type->t_tspec)))
/* constant in conditional context */
warning(161);
}
Home |
Main Index |
Thread Index |
Old Index