diff options
author | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-12 23:36:00 +0000 |
---|---|---|
committer | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-12 23:36:00 +0000 |
commit | 7563c3a21b2756c5ee3935624d8915f3fc842fd2 (patch) | |
tree | 6d945f8d882c3c1e857bd18ef93ae72a0e4ce96d /usr.bin | |
parent | a9975d18ca405e73e9e69b8e28c550f2848977df (diff) |
Cut down on extraneous "constant in conditional context" warnings when
lint encounters expressions like do { ... } while (0); and if (1) ...
We use these idioms frequently in our tree for scoping purposes and we
deem them to be safe. Now lint will not warn if it encounters a constant
in a conditional context when the expression consists only of a constant
(with no operators) and the constant is 0 or 1. This means that lint
will not warn for "if (1)" but will warn for "if (2)" and will also
continue to warn for "if (foo && 1)". This cuts down the vast majority
of these warnings while still preserving the ability to catch bugs.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/xlint/lint1/externs1.h | 3 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/tree.c | 21 |
2 files changed, 15 insertions, 9 deletions
diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index 0d7f2fe9a14..22e9e30a837 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: externs1.h,v 1.7 2005/12/10 18:42:45 cloder Exp $ */ +/* $OpenBSD: externs1.h,v 1.8 2005/12/12 23:35:59 cloder Exp $ */ /* $NetBSD: externs1.h,v 1.7 1995/10/02 17:31:39 jpo Exp $ */ /* @@ -205,6 +205,7 @@ extern void expr(tnode_t *, int, int); extern void chkmisc(tnode_t *, int, int, int, int, int, int); extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *); extern strg_t *catstrg(strg_t *, strg_t *); +extern void displexpr(tnode_t *, int); /* * func.c diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 677ef807664..54b7c8545d4 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.22 2005/12/10 18:42:45 cloder Exp $ */ +/* $OpenBSD: tree.c,v 1.23 2005/12/12 23:35:59 cloder Exp $ */ /* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: tree.c,v 1.22 2005/12/10 18:42:45 cloder Exp $"; +static char rcsid[] = "$OpenBSD: tree.c,v 1.23 2005/12/12 23:35:59 cloder Exp $"; #endif #include <stdlib.h> @@ -79,7 +79,6 @@ static tnode_t *chkfarg(type_t *, tnode_t *); static tnode_t *parg(int, type_t *, tnode_t *); static int chkdbz(op_t, tnode_t *); static void nulleff(tnode_t *); -static void displexpr(tnode_t *, int); static void chkaidx(tnode_t *, int); static void chkcomp(op_t, tnode_t *, tnode_t *); static void precconf(tnode_t *); @@ -672,9 +671,10 @@ build(op_t op, tnode_t *ln, tnode_t *rn) if (mp->m_tctx) { if (ln->tn_op == CON || ((mp->m_binary && op != QUEST) && rn->tn_op == CON)) { - if (hflag && !ccflg) + if (hflag && !ccflg) { /* constant in conditional context */ warning(161); + } } } @@ -3321,9 +3321,14 @@ expr(tnode_t *tn, int vctx, int tctx) /* assignment in conditional context */ warning(159); } else if (tn->tn_op == CON) { - if (hflag && tctx && !ccflg) - /* constant in conditional context */ - warning(161); + if (hflag && tctx && !ccflg) { + if (isityp(tn->tn_type->t_tspec) && + tn->tn_val->v_quad != 0 && + tn->tn_val->v_quad != 1) { + /* constant in conditional context */ + warning(161); + } + } } if (!modtab[tn->tn_op].m_sideeff) { /* @@ -3386,7 +3391,7 @@ nulleff(tnode_t *tn) * Dump an expression to stdout * only used for debugging */ -static void +void displexpr(tnode_t *tn, int offs) { u_quad_t uq; |