lint: clean up code related to lint comments

Remove type information from variable names, as the word 'flag' did not
indicate that the variables were negated.

Remove contradicting comments. Suppressing a warning for 'this line',
'this and the following line' and 'this statement or declaration' cannot
all be accurate at the same time.
This commit is contained in:
rillig 2023-07-13 06:41:27 +00:00
parent e2e148694e
commit 5a11074ff1
6 changed files with 57 additions and 97 deletions

View File

@ -1,5 +1,5 @@
%{ %{
/* $NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 rillig Exp $ */ /* $NetBSD: cgram.y,v 1.458 2023/07/13 06:41:27 rillig Exp $ */
/* /*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) #if defined(__RCSID)
__RCSID("$NetBSD: cgram.y,v 1.457 2023/07/12 18:26:04 rillig Exp $"); __RCSID("$NetBSD: cgram.y,v 1.458 2023/07/13 06:41:27 rillig Exp $");
#endif #endif
#include <limits.h> #include <limits.h>
@ -614,7 +614,7 @@ gcc_statement_expr_item:
if ($1->tn_op == NAME) if ($1->tn_op == NAME)
$1->tn_sym->s_used = true; $1->tn_sym->s_used = true;
expr($1, false, false, false, false); expr($1, false, false, false, false);
seen_fallthrough = false; suppress_fallthrough = false;
$$ = $1; $$ = $1;
} }
} }
@ -1764,7 +1764,7 @@ non_expr_statement: /* helper for C99 6.8 */
| selection_statement | selection_statement
| iteration_statement | iteration_statement
| jump_statement { | jump_statement {
seen_fallthrough = false; suppress_fallthrough = false;
} }
| asm_statement | asm_statement
; ;
@ -1780,16 +1780,16 @@ label:
} }
| T_CASE constant_expression T_COLON { | T_CASE constant_expression T_COLON {
case_label($2); case_label($2);
seen_fallthrough = true; suppress_fallthrough = true;
} }
| T_CASE constant_expression T_ELLIPSIS constant_expression T_COLON { | T_CASE constant_expression T_ELLIPSIS constant_expression T_COLON {
/* XXX: We don't fill all cases */ /* XXX: We don't fill all cases */
case_label($2); case_label($2);
seen_fallthrough = true; suppress_fallthrough = true;
} }
| T_DEFAULT T_COLON { | T_DEFAULT T_COLON {
default_label(); default_label();
seen_fallthrough = true; suppress_fallthrough = true;
} }
; ;
@ -1812,7 +1812,7 @@ compound_statement_rbrace:
level_free_all(mem_block_level); level_free_all(mem_block_level);
mem_block_level--; mem_block_level--;
block_level--; block_level--;
seen_fallthrough = false; suppress_fallthrough = false;
} }
; ;
@ -1840,11 +1840,11 @@ block_item: /* C99 6.8.2 */
expression_statement: /* C99 6.8.3 */ expression_statement: /* C99 6.8.3 */
expression T_SEMI { expression T_SEMI {
expr($1, false, false, false, false); expr($1, false, false, false, false);
seen_fallthrough = false; suppress_fallthrough = false;
} }
| T_SEMI { | T_SEMI {
check_statement_reachable(); check_statement_reachable();
seen_fallthrough = false; suppress_fallthrough = false;
} }
; ;
@ -1905,7 +1905,7 @@ iteration_statement: /* C99 6.8.5 */
} }
| do_statement do_while_expr { | do_statement do_while_expr {
stmt_do_while_expr($2); stmt_do_while_expr($2);
seen_fallthrough = false; suppress_fallthrough = false;
} }
| do error { | do error {
clear_warning_flags(); clear_warning_flags();

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.349 2023/07/12 16:07:35 rillig Exp $ */ /* $NetBSD: decl.c,v 1.350 2023/07/13 06:41:27 rillig Exp $ */
/* /*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -38,7 +38,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) #if defined(__RCSID)
__RCSID("$NetBSD: decl.c,v 1.349 2023/07/12 16:07:35 rillig Exp $"); __RCSID("$NetBSD: decl.c,v 1.350 2023/07/13 06:41:27 rillig Exp $");
#endif #endif
#include <sys/param.h> #include <sys/param.h>
@ -303,7 +303,7 @@ dcs_add_type(type_t *tp)
/* "long long" or "long ... long" */ /* "long long" or "long ... long" */
t = LLONG; t = LLONG;
dcs->d_rank_mod = NO_TSPEC; dcs->d_rank_mod = NO_TSPEC;
if (!long_long_flag) if (!suppress_longlong)
/* %s does not support 'long long' */ /* %s does not support 'long long' */
c99ism(265, allow_c90 ? "C90" : "traditional C"); c99ism(265, allow_c90 ? "C90" : "traditional C");
} }
@ -962,7 +962,7 @@ check_bit_field_type(sym_t *dsym, type_t **const inout_tp, tspec_t *inout_t)
if (t == CHAR || t == UCHAR || t == SCHAR || if (t == CHAR || t == UCHAR || t == SCHAR ||
t == SHORT || t == USHORT || t == ENUM) { t == SHORT || t == USHORT || t == ENUM) {
if (!bitfieldtype_ok) { if (!suppress_bitfieldtype) {
/* TODO: Make this an error in C99 mode as well. */ /* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99) { if (!allow_trad && !allow_c99) {
type_t *btp = block_dup_type(tp); type_t *btp = block_dup_type(tp);
@ -977,19 +977,18 @@ check_bit_field_type(sym_t *dsym, type_t **const inout_tp, tspec_t *inout_t)
} }
} }
} else if (t == INT && dcs->d_sign_mod == NO_TSPEC) { } else if (t == INT && dcs->d_sign_mod == NO_TSPEC) {
if (pflag && !bitfieldtype_ok) { if (pflag && !suppress_bitfieldtype) {
/* bit-field of type plain 'int' has ... */ /* bit-field of type plain 'int' has ... */
warning(344); warning(344);
} }
} else if (!(t == INT || t == UINT || t == BOOL || } else if (!(t == INT || t == UINT || t == BOOL
(is_integer(t) && (bitfieldtype_ok || allow_gcc)))) { || (is_integer(t) && (suppress_bitfieldtype || allow_gcc)))) {
type_t *btp = block_dup_type(tp); type_t *btp = block_dup_type(tp);
btp->t_bitfield = false; btp->t_bitfield = false;
/* illegal bit-field type '%s' */ /* illegal bit-field type '%s' */
warning(35, type_name(btp)); warning(35, type_name(btp));
// XXX: What about _Bool bit-fields since C99 6.7.2.1?
unsigned int width = tp->t_bit_field_width; unsigned int width = tp->t_bit_field_width;
dsym->s_type = tp = block_dup_type(gettyp(t = INT)); dsym->s_type = tp = block_dup_type(gettyp(t = INT));
if ((tp->t_bit_field_width = width) > size_in_bits(t)) if ((tp->t_bit_field_width = width) > size_in_bits(t))
@ -1067,7 +1066,7 @@ declare_unnamed_member(void)
mem->s_block_level = -1; mem->s_block_level = -1;
dcs_add_member(mem); dcs_add_member(mem);
bitfieldtype_ok = false; suppress_bitfieldtype = false;
return mem; return mem;
} }
@ -1115,11 +1114,7 @@ declare_member(sym_t *dsym)
check_function_definition(dsym, false); check_function_definition(dsym, false);
/* suppress_bitfieldtype = false;
* Clear the BITFIELDTYPE indicator after processing each
* structure element.
*/
bitfieldtype_ok = false;
return dsym; return dsym;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.191 2023/07/12 16:07:35 rillig Exp $ */ /* $NetBSD: externs1.h,v 1.192 2023/07/13 06:41:27 rillig Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -293,7 +293,7 @@ tnode_t *end_statement_expr(void);
extern sym_t *funcsym; extern sym_t *funcsym;
extern bool reached; extern bool reached;
extern bool warn_about_unreachable; extern bool warn_about_unreachable;
extern bool seen_fallthrough; extern bool suppress_fallthrough;
extern int nargusg; extern int nargusg;
extern pos_t argsused_pos; extern pos_t argsused_pos;
extern int nvararg; extern int nvararg;
@ -302,12 +302,12 @@ extern int printflike_argnum;
extern pos_t printflike_pos; extern pos_t printflike_pos;
extern int scanflike_argnum; extern int scanflike_argnum;
extern pos_t scanflike_pos; extern pos_t scanflike_pos;
extern bool constcond_flag; extern bool suppress_constcond;
extern bool llibflg; extern bool llibflg;
extern int lwarn; extern int lwarn;
extern bool bitfieldtype_ok; extern bool suppress_bitfieldtype;
extern bool plibflg; extern bool plibflg;
extern bool long_long_flag; extern bool suppress_longlong;
void begin_control_statement(control_statement_kind); void begin_control_statement(control_statement_kind);
void end_control_statement(control_statement_kind); void end_control_statement(control_statement_kind);

View File

@ -1,4 +1,4 @@
/* $NetBSD: func.c,v 1.167 2023/07/09 12:15:07 rillig Exp $ */ /* $NetBSD: func.c,v 1.168 2023/07/13 06:41:27 rillig Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) #if defined(__RCSID)
__RCSID("$NetBSD: func.c,v 1.167 2023/07/09 12:15:07 rillig Exp $"); __RCSID("$NetBSD: func.c,v 1.168 2023/07/13 06:41:27 rillig Exp $");
#endif #endif
#include <stdlib.h> #include <stdlib.h>
@ -67,13 +67,14 @@ bool warn_about_unreachable;
* Reset by each statement and set by FALLTHROUGH, stmt_switch_expr and * Reset by each statement and set by FALLTHROUGH, stmt_switch_expr and
* case_label. * case_label.
* *
* Control statements if, for, while and switch do not reset seen_fallthrough * The control statements 'if', 'for', 'while' and 'switch' do not reset
* because this must be done by the controlled statement. At least for if this * suppress_fallthrough because this must be done by the controlled statement.
* is important because ** FALLTHROUGH ** after "if (expr) statement" is * At least for 'if', this is important because ** FALLTHROUGH ** after "if
* evaluated before the following token, which causes reduction of above. * (expr) statement" is evaluated before the following token, which causes
* This means that ** FALLTHROUGH ** after "if ..." would always be ignored. * reduction of above. This means that ** FALLTHROUGH ** after "if ..." would
* always be ignored.
*/ */
bool seen_fallthrough; bool suppress_fallthrough;
/* The innermost control statement */ /* The innermost control statement */
static control_statement *cstmt; static control_statement *cstmt;
@ -115,11 +116,8 @@ pos_t scanflike_pos;
*/ */
bool plibflg; bool plibflg;
/* /* Temporarily suppress warnings about constants in conditional context. */
* True means that no warnings about constants in conditional bool suppress_constcond;
* context are printed.
*/
bool constcond_flag;
/* /*
* Whether a lint library shall be created. The effect of this flag is that * Whether a lint library shall be created. The effect of this flag is that
@ -138,17 +136,11 @@ bool llibflg;
*/ */
int lwarn = LWARN_ALL; int lwarn = LWARN_ALL;
/* /* Temporarily suppress warnings about wrong types for bit-fields. */
* Whether bitfield type errors are suppressed by a BITFIELDTYPE bool suppress_bitfieldtype;
* directive.
*/
bool bitfieldtype_ok;
/* /* Temporarily suppress warnings about use of 'long long'. */
* Whether complaints about use of "long long" are suppressed in bool suppress_longlong;
* the next statement or declaration.
*/
bool long_long_flag;
void void
begin_control_statement(control_statement_kind kind) begin_control_statement(control_statement_kind kind)
@ -514,7 +506,7 @@ check_case_label(tnode_t *tn, control_statement *cs)
lint_assert(cs->c_switch_type != NULL); lint_assert(cs->c_switch_type != NULL);
if (reached && !seen_fallthrough) { if (reached && !suppress_fallthrough) {
if (hflag) if (hflag)
/* fallthrough on case statement */ /* fallthrough on case statement */
warning(220); warning(220);
@ -591,7 +583,7 @@ default_label(void)
/* duplicate default in switch */ /* duplicate default in switch */
error(202); error(202);
} else { } else {
if (reached && !seen_fallthrough) { if (reached && !suppress_fallthrough) {
if (hflag) if (hflag)
/* fallthrough on default statement */ /* fallthrough on default statement */
warning(284); warning(284);
@ -718,7 +710,7 @@ stmt_switch_expr(tnode_t *tn)
cstmt->c_switch_expr = tn; cstmt->c_switch_expr = tn;
set_reached(false); set_reached(false);
seen_fallthrough = true; suppress_fallthrough = true;
} }
void void
@ -1156,12 +1148,6 @@ argsused(int n)
argsused_pos = curr_pos; argsused_pos = curr_pos;
} }
/*
* VARARGS comment
*
* Causes lint2 to check only the first n arguments for compatibility
* with the function definition. A missing argument is taken to be 0.
*/
void void
varargs(int n) varargs(int n)
{ {
@ -1183,8 +1169,6 @@ varargs(int n)
} }
/* /*
* PRINTFLIKE comment
*
* Check all arguments until the (n-1)-th as usual. The n-th argument is * Check all arguments until the (n-1)-th as usual. The n-th argument is
* used the check the types of remaining arguments. * used the check the types of remaining arguments.
*/ */
@ -1209,8 +1193,6 @@ printflike(int n)
} }
/* /*
* SCANFLIKE comment
*
* Check all arguments until the (n-1)-th as usual. The n-th argument is * Check all arguments until the (n-1)-th as usual. The n-th argument is
* used the check the types of remaining arguments. * used the check the types of remaining arguments.
*/ */
@ -1234,34 +1216,22 @@ scanflike(int n)
scanflike_pos = curr_pos; scanflike_pos = curr_pos;
} }
/*
* Set the line number for a CONSTCOND comment. At this and the following
* line no warnings about constants in conditional contexts are printed.
*/
/* ARGSUSED */ /* ARGSUSED */
void void
constcond(int n) constcond(int n)
{ {
constcond_flag = true; suppress_constcond = true;
} }
/*
* Suppress printing of "fallthrough on ..." warnings until next
* statement.
*/
/* ARGSUSED */ /* ARGSUSED */
void void
fallthru(int n) fallthru(int n)
{ {
seen_fallthrough = true; suppress_fallthrough = true;
} }
/*
* Stop warnings about statements which cannot be reached. Also tells lint
* that the following statements cannot be reached (e.g. after exit()).
*/
/* ARGSUSED */ /* ARGSUSED */
void void
not_reached(int n) not_reached(int n)
@ -1285,7 +1255,6 @@ lintlib(int n)
vflag = true; vflag = true;
} }
/* Suppress one or most warnings at the current and the following line. */
void void
linted(int n) linted(int n)
{ {
@ -1294,17 +1263,14 @@ linted(int n)
lwarn = n; lwarn = n;
} }
/*
* Suppress bitfield type errors on the current line.
*/
/* ARGSUSED */ /* ARGSUSED */
void void
bitfieldtype(int n) bitfieldtype(int n)
{ {
debug_step("%s, %d: bitfieldtype_ok = true", debug_step("%s:%d: suppress_bitfieldtype = true",
curr_pos.p_file, curr_pos.p_line); curr_pos.p_file, curr_pos.p_line);
bitfieldtype_ok = true; suppress_bitfieldtype = true;
} }
/* /*
@ -1324,11 +1290,10 @@ protolib(int n)
plibflg = n != 0; plibflg = n != 0;
} }
/* The next statement/declaration may use "long long" without a diagnostic. */
/* ARGSUSED */ /* ARGSUSED */
void void
longlong(int n) longlong(int n)
{ {
long_long_flag = true; suppress_longlong = true;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: lex.c,v 1.178 2023/07/12 20:13:28 rillig Exp $ */ /* $NetBSD: lex.c,v 1.179 2023/07/13 06:41:27 rillig Exp $ */
/* /*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -38,7 +38,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) #if defined(__RCSID)
__RCSID("$NetBSD: lex.c,v 1.178 2023/07/12 20:13:28 rillig Exp $"); __RCSID("$NetBSD: lex.c,v 1.179 2023/07/13 06:41:27 rillig Exp $");
#endif #endif
#include <ctype.h> #include <ctype.h>
@ -1181,8 +1181,8 @@ clear_warn_flags(void)
{ {
lwarn = LWARN_ALL; lwarn = LWARN_ALL;
long_long_flag = false; suppress_longlong = false;
constcond_flag = false; suppress_constcond = false;
} }
int int

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.561 2023/07/12 19:34:01 rillig Exp $ */ /* $NetBSD: tree.c,v 1.562 2023/07/13 06:41:27 rillig Exp $ */
/* /*
* Copyright (c) 1994, 1995 Jochen Pohl * Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(__RCSID) #if defined(__RCSID)
__RCSID("$NetBSD: tree.c,v 1.561 2023/07/12 19:34:01 rillig Exp $"); __RCSID("$NetBSD: tree.c,v 1.562 2023/07/13 06:41:27 rillig Exp $");
#endif #endif
#include <float.h> #include <float.h>
@ -1497,7 +1497,7 @@ fold_bool(tnode_t *tn)
switch (tn->tn_op) { switch (tn->tn_op) {
case NOT: case NOT:
if (hflag && !constcond_flag) if (hflag && !suppress_constcond)
/* constant argument to '!' */ /* constant argument to '!' */
warning(239); warning(239);
v->u.integer = !l ? 1 : 0; v->u.integer = !l ? 1 : 0;
@ -1794,7 +1794,7 @@ build_binary(tnode_t *ln, op_t op, bool sys, tnode_t *rn)
* Print a warning if one of the operands is in a context where * Print a warning if one of the operands is in a context where
* it is compared with zero and if this operand is a constant. * it is compared with zero and if this operand is a constant.
*/ */
if (hflag && !constcond_flag && if (hflag && !suppress_constcond &&
mp->m_compares_with_zero && mp->m_compares_with_zero &&
(ln->tn_op == CON || (ln->tn_op == CON ||
((mp->m_binary && op != QUEST) && rn->tn_op == CON)) && ((mp->m_binary && op != QUEST) && rn->tn_op == CON)) &&
@ -4397,7 +4397,7 @@ expr(tnode_t *tn, bool vctx, bool cond, bool dofreeblk, bool is_do_while)
/* assignment in conditional context */ /* assignment in conditional context */
warning(159); warning(159);
} else if (tn->tn_op == CON) { } else if (tn->tn_op == CON) {
if (hflag && cond && !constcond_flag && if (hflag && cond && !suppress_constcond &&
!tn->tn_system_dependent && !tn->tn_system_dependent &&
!(is_do_while && !(is_do_while &&
is_constcond_false(tn, tn->tn_type->t_tspec))) is_constcond_false(tn, tn->tn_type->t_tspec)))