Module Name:    src
Committed By:   rillig
Date:           Thu Jul 13 06:41:28 UTC 2023

Modified Files:
        src/usr.bin/xlint/lint1: cgram.y decl.c externs1.h func.c lex.c tree.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.457 -r1.458 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.349 -r1.350 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.191 -r1.192 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.167 -r1.168 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.561 -r1.562 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/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.457 src/usr.bin/xlint/lint1/cgram.y:1.458
--- src/usr.bin/xlint/lint1/cgram.y:1.457	Wed Jul 12 18:26:04 2023
+++ src/usr.bin/xlint/lint1/cgram.y	Thu Jul 13 06:41:27 2023
@@ -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.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #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
 
 #include <limits.h>
@@ -614,7 +614,7 @@ gcc_statement_expr_item:
 			if ($1->tn_op == NAME)
 				$1->tn_sym->s_used = true;
 			expr($1, false, false, false, false);
-			seen_fallthrough = false;
+			suppress_fallthrough = false;
 			$$ = $1;
 		}
 	}
@@ -1764,7 +1764,7 @@ non_expr_statement:		/* helper for C99 6
 |	selection_statement
 |	iteration_statement
 |	jump_statement {
-		seen_fallthrough = false;
+		suppress_fallthrough = false;
 	}
 |	asm_statement
 ;
@@ -1780,16 +1780,16 @@ label:
 	}
 |	T_CASE constant_expression T_COLON {
 		case_label($2);
-		seen_fallthrough = true;
+		suppress_fallthrough = true;
 	}
 |	T_CASE constant_expression T_ELLIPSIS constant_expression T_COLON {
 		/* XXX: We don't fill all cases */
 		case_label($2);
-		seen_fallthrough = true;
+		suppress_fallthrough = true;
 	}
 |	T_DEFAULT T_COLON {
 		default_label();
-		seen_fallthrough = true;
+		suppress_fallthrough = true;
 	}
 ;
 
@@ -1812,7 +1812,7 @@ compound_statement_rbrace:
 		level_free_all(mem_block_level);
 		mem_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 T_SEMI {
 		expr($1, false, false, false, false);
-		seen_fallthrough = false;
+		suppress_fallthrough = false;
 	}
 |	T_SEMI {
 		check_statement_reachable();
-		seen_fallthrough = false;
+		suppress_fallthrough = false;
 	}
 ;
 
@@ -1905,7 +1905,7 @@ iteration_statement:		/* C99 6.8.5 */
 	}
 |	do_statement do_while_expr {
 		stmt_do_while_expr($2);
-		seen_fallthrough = false;
+		suppress_fallthrough = false;
 	}
 |	do error {
 		clear_warning_flags();

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.349 src/usr.bin/xlint/lint1/decl.c:1.350
--- src/usr.bin/xlint/lint1/decl.c:1.349	Wed Jul 12 16:07:35 2023
+++ src/usr.bin/xlint/lint1/decl.c	Thu Jul 13 06:41:27 2023
@@ -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.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #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
 
 #include <sys/param.h>
@@ -303,7 +303,7 @@ dcs_add_type(type_t *tp)
 		/* "long long" or "long ... long" */
 		t = LLONG;
 		dcs->d_rank_mod = NO_TSPEC;
-		if (!long_long_flag)
+		if (!suppress_longlong)
 			/* %s does not support 'long long' */
 			c99ism(265, allow_c90 ? "C90" : "traditional C");
 	}
@@ -962,7 +962,7 @@ check_bit_field_type(sym_t *dsym, type_t
 
 	if (t == CHAR || t == UCHAR || t == SCHAR ||
 	    t == SHORT || t == USHORT || t == ENUM) {
-		if (!bitfieldtype_ok) {
+		if (!suppress_bitfieldtype) {
 			/* TODO: Make this an error in C99 mode as well. */
 			if (!allow_trad && !allow_c99) {
 				type_t *btp = block_dup_type(tp);
@@ -977,19 +977,18 @@ check_bit_field_type(sym_t *dsym, type_t
 			}
 		}
 	} 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 ... */
 			warning(344);
 		}
-	} else if (!(t == INT || t == UINT || t == BOOL ||
-		     (is_integer(t) && (bitfieldtype_ok || allow_gcc)))) {
+	} else if (!(t == INT || t == UINT || t == BOOL
+		|| (is_integer(t) && (suppress_bitfieldtype || allow_gcc)))) {
 
 		type_t *btp = block_dup_type(tp);
 		btp->t_bitfield = false;
 		/* illegal bit-field type '%s' */
 		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;
 		dsym->s_type = tp = block_dup_type(gettyp(t = INT));
 		if ((tp->t_bit_field_width = width) > size_in_bits(t))
@@ -1067,7 +1066,7 @@ declare_unnamed_member(void)
 	mem->s_block_level = -1;
 
 	dcs_add_member(mem);
-	bitfieldtype_ok = false;
+	suppress_bitfieldtype = false;
 	return mem;
 }
 
@@ -1115,11 +1114,7 @@ declare_member(sym_t *dsym)
 
 	check_function_definition(dsym, false);
 
-	/*
-	 * Clear the BITFIELDTYPE indicator after processing each
-	 * structure element.
-	 */
-	bitfieldtype_ok = false;
+	suppress_bitfieldtype = false;
 
 	return dsym;
 }

Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.191 src/usr.bin/xlint/lint1/externs1.h:1.192
--- src/usr.bin/xlint/lint1/externs1.h:1.191	Wed Jul 12 16:07:35 2023
+++ src/usr.bin/xlint/lint1/externs1.h	Thu Jul 13 06:41:27 2023
@@ -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
@@ -293,7 +293,7 @@ tnode_t *end_statement_expr(void);
 extern	sym_t	*funcsym;
 extern	bool	reached;
 extern	bool	warn_about_unreachable;
-extern	bool	seen_fallthrough;
+extern	bool	suppress_fallthrough;
 extern	int	nargusg;
 extern	pos_t	argsused_pos;
 extern	int	nvararg;
@@ -302,12 +302,12 @@ extern	int	printflike_argnum;
 extern	pos_t	printflike_pos;
 extern	int	scanflike_argnum;
 extern	pos_t	scanflike_pos;
-extern	bool	constcond_flag;
+extern	bool	suppress_constcond;
 extern	bool	llibflg;
 extern	int	lwarn;
-extern	bool	bitfieldtype_ok;
+extern	bool	suppress_bitfieldtype;
 extern	bool	plibflg;
-extern	bool	long_long_flag;
+extern	bool	suppress_longlong;
 
 void	begin_control_statement(control_statement_kind);
 void	end_control_statement(control_statement_kind);

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.167 src/usr.bin/xlint/lint1/func.c:1.168
--- src/usr.bin/xlint/lint1/func.c:1.167	Sun Jul  9 12:15:07 2023
+++ src/usr.bin/xlint/lint1/func.c	Thu Jul 13 06:41:27 2023
@@ -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
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #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
 
 #include <stdlib.h>
@@ -67,13 +67,14 @@ bool	warn_about_unreachable;
  * Reset by each statement and set by FALLTHROUGH, stmt_switch_expr and
  * case_label.
  *
- * Control statements if, for, while and switch do not reset seen_fallthrough
- * because this must be done by the controlled statement. At least for if this
- * is important because ** FALLTHROUGH ** after "if (expr) statement" is
- * evaluated before the following token, which causes reduction of above.
- * This means that ** FALLTHROUGH ** after "if ..." would always be ignored.
+ * The control statements 'if', 'for', 'while' and 'switch' do not reset
+ * suppress_fallthrough because this must be done by the controlled statement.
+ * At least for 'if', this is important because ** FALLTHROUGH ** after "if
+ * (expr) statement" is evaluated before the following token, which causes
+ * reduction of above. This means that ** FALLTHROUGH ** after "if ..." would
+ * always be ignored.
  */
-bool	seen_fallthrough;
+bool	suppress_fallthrough;
 
 /* The innermost control statement */
 static control_statement *cstmt;
@@ -115,11 +116,8 @@ pos_t	scanflike_pos;
  */
 bool	plibflg;
 
-/*
- * True means that no warnings about constants in conditional
- * context are printed.
- */
-bool	constcond_flag;
+/* Temporarily suppress warnings about constants in conditional context. */
+bool	suppress_constcond;
 
 /*
  * Whether a lint library shall be created. The effect of this flag is that
@@ -138,17 +136,11 @@ bool	llibflg;
  */
 int	lwarn = LWARN_ALL;
 
-/*
- * Whether bitfield type errors are suppressed by a BITFIELDTYPE
- * directive.
- */
-bool	bitfieldtype_ok;
+/* Temporarily suppress warnings about wrong types for bit-fields. */
+bool	suppress_bitfieldtype;
 
-/*
- * Whether complaints about use of "long long" are suppressed in
- * the next statement or declaration.
- */
-bool	long_long_flag;
+/* Temporarily suppress warnings about use of 'long long'. */
+bool	suppress_longlong;
 
 void
 begin_control_statement(control_statement_kind kind)
@@ -514,7 +506,7 @@ check_case_label(tnode_t *tn, control_st
 
 	lint_assert(cs->c_switch_type != NULL);
 
-	if (reached && !seen_fallthrough) {
+	if (reached && !suppress_fallthrough) {
 		if (hflag)
 			/* fallthrough on case statement */
 			warning(220);
@@ -591,7 +583,7 @@ default_label(void)
 		/* duplicate default in switch */
 		error(202);
 	} else {
-		if (reached && !seen_fallthrough) {
+		if (reached && !suppress_fallthrough) {
 			if (hflag)
 				/* fallthrough on default statement */
 				warning(284);
@@ -718,7 +710,7 @@ stmt_switch_expr(tnode_t *tn)
 	cstmt->c_switch_expr = tn;
 
 	set_reached(false);
-	seen_fallthrough = true;
+	suppress_fallthrough = true;
 }
 
 void
@@ -1156,12 +1148,6 @@ argsused(int n)
 	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
 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
  * 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
  * used the check the types of remaining arguments.
  */
@@ -1234,34 +1216,22 @@ scanflike(int n)
 	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 */
 void
 constcond(int n)
 {
 
-	constcond_flag = true;
+	suppress_constcond = true;
 }
 
-/*
- * Suppress printing of "fallthrough on ..." warnings until next
- * statement.
- */
 /* ARGSUSED */
 void
 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 */
 void
 not_reached(int n)
@@ -1285,7 +1255,6 @@ lintlib(int n)
 	vflag = true;
 }
 
-/* Suppress one or most warnings at the current and the following line. */
 void
 linted(int n)
 {
@@ -1294,17 +1263,14 @@ linted(int n)
 	lwarn = n;
 }
 
-/*
- * Suppress bitfield type errors on the current line.
- */
 /* ARGSUSED */
 void
 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);
-	bitfieldtype_ok = true;
+	suppress_bitfieldtype = true;
 }
 
 /*
@@ -1324,11 +1290,10 @@ protolib(int n)
 	plibflg = n != 0;
 }
 
-/* The next statement/declaration may use "long long" without a diagnostic. */
 /* ARGSUSED */
 void
 longlong(int n)
 {
 
-	long_long_flag = true;
+	suppress_longlong = true;
 }

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.178 src/usr.bin/xlint/lint1/lex.c:1.179
--- src/usr.bin/xlint/lint1/lex.c:1.178	Wed Jul 12 20:13:28 2023
+++ src/usr.bin/xlint/lint1/lex.c	Thu Jul 13 06:41:27 2023
@@ -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.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #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
 
 #include <ctype.h>
@@ -1181,8 +1181,8 @@ clear_warn_flags(void)
 {
 
 	lwarn = LWARN_ALL;
-	long_long_flag = false;
-	constcond_flag = false;
+	suppress_longlong = false;
+	suppress_constcond = false;
 }
 
 int

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.561 src/usr.bin/xlint/lint1/tree.c:1.562
--- src/usr.bin/xlint/lint1/tree.c:1.561	Wed Jul 12 19:34:01 2023
+++ src/usr.bin/xlint/lint1/tree.c	Thu Jul 13 06:41:27 2023
@@ -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
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #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
 
 #include <float.h>
@@ -1497,7 +1497,7 @@ fold_bool(tnode_t *tn)
 
 	switch (tn->tn_op) {
 	case NOT:
-		if (hflag && !constcond_flag)
+		if (hflag && !suppress_constcond)
 			/* constant argument to '!' */
 			warning(239);
 		v->u.integer = !l ? 1 : 0;
@@ -1794,7 +1794,7 @@ build_binary(tnode_t *ln, op_t op, bool 
 	 * 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.
 	 */
-	if (hflag && !constcond_flag &&
+	if (hflag && !suppress_constcond &&
 	    mp->m_compares_with_zero &&
 	    (ln->tn_op == CON ||
 	     ((mp->m_binary && op != QUEST) && rn->tn_op == CON)) &&
@@ -4397,7 +4397,7 @@ expr(tnode_t *tn, bool vctx, bool cond, 
 			/* assignment in conditional context */
 			warning(159);
 	} else if (tn->tn_op == CON) {
-		if (hflag && cond && !constcond_flag &&
+		if (hflag && cond && !suppress_constcond &&
 		    !tn->tn_system_dependent &&
 		    !(is_do_while &&
 		      is_constcond_false(tn, tn->tn_type->t_tspec)))

Reply via email to