Module Name: src
Committed By: rillig
Date: Fri Jan 1 11:41:01 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: cgram.y check-msgs.lua decl.c func.c init.c
tree.c
Log Message:
lint: add missing redundant messages in source code
To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/xlint/lint1/check-msgs.lua
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.112 -r1.113 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.126 src/usr.bin/xlint/lint1/cgram.y:1.127
--- src/usr.bin/xlint/lint1/cgram.y:1.126 Fri Jan 1 11:09:40 2021
+++ src/usr.bin/xlint/lint1/cgram.y Fri Jan 1 11:41:01 2021
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.126 2021/01/01 11:09:40 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.127 2021/01/01 11:41:01 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.126 2021/01/01 11:09:40 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.127 2021/01/01 11:41:01 rillig Exp $");
#endif
#include <limits.h>
@@ -801,6 +801,7 @@ member_declaration:
symtyp = FVFT;
/* struct or union member must be named */
if (!Sflag)
+ /* anonymous struct/union members is a C9X feature */
warning(49);
/* add all the members of the anonymous struct/union */
$$ = dcs->d_type->t_str->memb;
@@ -810,6 +811,7 @@ member_declaration:
symtyp = FVFT;
/* struct or union member must be named */
if (!Sflag)
+ /* anonymous struct/union members is a C9X feature */
warning(49);
$$ = dcs->d_type->t_str->memb;
/* add all the members of the anonymous struct/union */
@@ -1363,10 +1365,12 @@ range:
init_field:
T_LBRACK range T_RBRACK {
if (!Sflag)
+ /* array initializer with des.s is a C9X feature */
warning(321);
}
| point identifier {
if (!Sflag)
+ /* struct or union member name in initializer is ... */
warning(313);
push_member($2);
}
@@ -1380,6 +1384,7 @@ init_field_list:
init_by_name:
init_field_list T_ASSIGN
| identifier T_COLON {
+ /* GCC style struct or union member name in initializer */
gnuism(315);
push_member($1);
}
@@ -1511,6 +1516,7 @@ stmnt_d_list:
stmnt_list
| stmnt_d_list declaration_list stmnt_list {
if (!Sflag)
+ /* declarations after statements is a C9X feature */
c99ism(327);
}
;
@@ -1712,6 +1718,7 @@ for_start:
for_exprs:
for_start declspecs deftyp notype_init_decls T_SEMI opt_expr
T_SEMI opt_expr T_RPAREN {
+ /* variable declaration in for loop */
c99ism(325);
for1(NULL, $6, $8);
CLRWFLGS(__FILE__, __LINE__);
@@ -1867,6 +1874,7 @@ term:
initsym = mktempsym(duptyp($4->tn_type));
mblklev++;
blklev++;
+ /* ({ }) is a GCC extension */
gnuism(320);
} comp_stmnt_rbrace T_RPAREN {
$$ = getnnode(initsym, 0);
@@ -1877,6 +1885,7 @@ term:
initsym = mktempsym($3->tn_type);
mblklev++;
blklev++;
+ /* ({ }) is a GCC extension */
gnuism(320);
} comp_stmnt_rbrace T_RPAREN {
$$ = getnnode(initsym, 0);
@@ -1971,7 +1980,8 @@ term:
idecl(tmp, 1, NULL);
} init_lbrace init_expr_list init_rbrace {
if (!Sflag)
- gnuism(319);
+ /* compound literals are a C9X/GCC extension */
+ gnuism(319);
$$ = getnnode(initsym, 0);
}
;
@@ -2017,6 +2027,7 @@ point_or_arrow:
point:
T_STROP {
if ($1 != POINT) {
+ /* syntax error '%s' */
error(249, yytext);
}
}
@@ -2039,6 +2050,7 @@ identifier:
int
yyerror(const char *msg)
{
+ /* syntax error '%s' */
error(249, yytext);
if (++sytxerr >= 5)
norecover();
Index: src/usr.bin/xlint/lint1/check-msgs.lua
diff -u src/usr.bin/xlint/lint1/check-msgs.lua:1.3 src/usr.bin/xlint/lint1/check-msgs.lua:1.4
--- src/usr.bin/xlint/lint1/check-msgs.lua:1.3 Fri Jan 1 01:26:02 2021
+++ src/usr.bin/xlint/lint1/check-msgs.lua Fri Jan 1 11:41:01 2021
@@ -1,5 +1,5 @@
#! /usr/bin/lua
--- $NetBSD: check-msgs.lua,v 1.3 2021/01/01 01:26:02 rillig Exp $
+-- $NetBSD: check-msgs.lua,v 1.4 2021/01/01 11:41:01 rillig Exp $
--[[
@@ -45,6 +45,7 @@ local function check_message(fname, line
comment = string.gsub(comment, "conv%.", "conversion")
comment = string.gsub(comment, "decl%.", "declaration")
comment = string.gsub(comment, "defn%.", "definition")
+ comment = string.gsub(comment, "des%.s", "designators")
comment = string.gsub(comment, "expr%.", "expression")
comment = string.gsub(comment, "func%.", "function")
comment = string.gsub(comment, "incomp%.", "incompatible")
@@ -80,11 +81,15 @@ local function collect_errors(fname, msg
lineno = lineno + 1
local func, id = line:match("^%s+(%w+)%((%d+)[),]")
+ id = tonumber(id)
if func == "error" or func == "warning" or func == "c99ism" or
func == "gnuism" or func == "message" then
local comment = prev:match("^%s+/%* (.+) %*/$")
if comment ~= nil then
- check_message(fname, lineno, tonumber(id), comment, msgs, errors)
+ check_message(fname, lineno, id, comment, msgs, errors)
+ else
+ errors:add("%s:%d: missing comment for %d: /* %s */",
+ fname, lineno, id, msgs[id])
end
end
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.93 src/usr.bin/xlint/lint1/decl.c:1.94
--- src/usr.bin/xlint/lint1/decl.c:1.93 Fri Jan 1 09:28:22 2021
+++ src/usr.bin/xlint/lint1/decl.c Fri Jan 1 11:41:01 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.93 2021/01/01 09:28:22 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.94 2021/01/01 11:41:01 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.93 2021/01/01 09:28:22 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.94 2021/01/01 11:41:01 rillig Exp $");
#endif
#include <sys/param.h>
@@ -302,9 +302,10 @@ add_type(type_t *tp)
if (t == COMPLEX) {
if (dcs->d_cmod == FLOAT)
t = FCOMPLEX;
- else if (dcs->d_cmod == DOUBLE) {
+ else if (dcs->d_cmod == DOUBLE)
t = DCOMPLEX;
- } else
+ else
+ /* Invalid type %s for _Complex */
error(308, tspec_name(dcs->d_cmod));
dcs->d_cmod = NOTSPEC;
}
@@ -528,6 +529,7 @@ setpackedsize(type_t *tp)
}
break;
default:
+ /* %s attribute ignored for %s */
warning(326, "packed", tyname(buf, sizeof(buf), tp));
break;
}
@@ -1038,8 +1040,10 @@ check_type(sym_t *sym)
} else if (incompl(tp)) {
/* array of incomplete type */
if (sflag) {
+ /* array of incomplete type */
error(301);
} else {
+ /* array of incomplete type */
warning(301);
}
#endif
@@ -1110,10 +1114,7 @@ declarator_1_struct_union(sym_t *dsym)
if (bitfieldtype_ok == 0) {
if (sflag) {
char buf[64];
- /*
- * bit-field type '%s' invalid in
- * ANSI C
- */
+ /* bit-field type '%s' invalid ... */
warning(273,
tyname(buf, sizeof(buf), tp));
} else if (pflag) {
@@ -1714,6 +1715,7 @@ newtag(sym_t *tag, scl_t scl, int decl,
tag->s_name);
/* declaration introduces new type in ANSI C: %s %s */
if (!sflag) {
+ /* decl. introduces new type in ANSI C: %s %s */
warning(44, storage_class_name(scl),
tag->s_name);
}
@@ -2066,6 +2068,7 @@ check_redeclaration(sym_t *dsym, int *do
*/
/* redeclaration of %s; ANSI C requires "static" */
if (sflag) {
+ /* redeclaration of %s; ANSI C requires static */
warning(30, dsym->s_name);
print_previous_declaration(-1, rsym);
}
@@ -2613,18 +2616,18 @@ decl1loc(sym_t *dsym, int initflg)
switch (dsym->s_scl) {
case AUTO:
- /* automatic hides external declaration: %s */
if (hflag)
+ /* automatic hides external decl.: %s */
warning(86, dsym->s_name);
break;
case STATIC:
- /* static hides external declaration: %s */
if (hflag)
+ /* static hides external decl.: %s */
warning(87, dsym->s_name);
break;
case TYPEDEF:
- /* typedef hides external declaration: %s */
if (hflag)
+ /* typedef hides external decl.: %s */
warning(88, dsym->s_name);
break;
case EXTERN:
@@ -2762,8 +2765,10 @@ check_init(sym_t *sym)
} else if (sym->s_scl == EXTERN && sym->s_def == DECL) {
/* cannot initialize "extern" declaration: %s */
if (dcs->d_ctx == EXTERN) {
+ /* cannot initialize extern declaration: %s */
warning(26, sym->s_name);
} else {
+ /* cannot initialize extern declaration: %s */
error(26, sym->s_name);
erred = 1;
}
@@ -2848,10 +2853,11 @@ check_size(sym_t *dsym)
if (length(dsym->s_type, dsym->s_name) == 0 &&
dsym->s_type->t_tspec == ARRAY && dsym->s_type->t_dim == 0) {
- /* empty array declaration: %s */
if (tflag) {
+ /* empty array declaration: %s */
warning(190, dsym->s_name);
} else {
+ /* empty array declaration: %s */
error(190, dsym->s_name);
}
}
@@ -3173,10 +3179,11 @@ check_global_variable_size(sym_t *sym)
curr_pos = sym->s_def_pos;
if (length(sym->s_type, sym->s_name) == 0 &&
sym->s_type->t_tspec == ARRAY && sym->s_type->t_dim == 0) {
- /* empty array declaration: %s */
if (tflag || (sym->s_scl == EXTERN && !sflag)) {
+ /* empty array declaration: %s */
warning(190, sym->s_name);
} else {
+ /* empty array declaration: %s */
error(190, sym->s_name);
}
}
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.45 src/usr.bin/xlint/lint1/func.c:1.46
--- src/usr.bin/xlint/lint1/func.c:1.45 Fri Jan 1 11:14:06 2021
+++ src/usr.bin/xlint/lint1/func.c Fri Jan 1 11:41:01 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.45 2021/01/01 11:14:06 rillig Exp $ */
+/* $NetBSD: func.c,v 1.46 2021/01/01 11:41:01 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.45 2021/01/01 11:14:06 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.46 2021/01/01 11:41:01 rillig Exp $");
#endif
#include <stdlib.h>
@@ -787,7 +787,8 @@ do2(tnode_t *tn)
cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
}
if (!cstk->c_infinite && cstk->c_cont)
- error(323);
+ /* continue in 'do ... while (0)' loop */
+ error(323);
}
expr(tn, 0, 1, 1);
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.49 src/usr.bin/xlint/lint1/init.c:1.50
--- src/usr.bin/xlint/lint1/init.c:1.49 Fri Jan 1 00:00:24 2021
+++ src/usr.bin/xlint/lint1/init.c Fri Jan 1 11:41:01 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.49 2021/01/01 00:00:24 rillig Exp $ */
+/* $NetBSD: init.c,v 1.50 2021/01/01 11:41:01 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.49 2021/01/01 00:00:24 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.50 2021/01/01 11:41:01 rillig Exp $");
#endif
#include <ctype.h>
@@ -191,6 +191,7 @@ initstack_pop_item(void)
return;
}
}
+ /* undefined struct/union member: %s */
error(101, namedmem->n_name);
DPRINTF(("%s: end rhs.name=%s\n", __func__, namedmem->n_name));
pop_member();
@@ -472,7 +473,7 @@ init_lbrace(void)
if ((initsym->s_scl == AUTO || initsym->s_scl == REG) &&
initstk->i_next == NULL) {
if (tflag && !tspec_is_scalar(initstk->i_subt->t_tspec))
- /* no automatic aggregate initialization in trad. C*/
+ /* no automatic aggregate initialization in trad. C */
warning(188);
}
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.112 src/usr.bin/xlint/lint1/tree.c:1.113
--- src/usr.bin/xlint/lint1/tree.c:1.112 Fri Jan 1 11:09:40 2021
+++ src/usr.bin/xlint/lint1/tree.c Fri Jan 1 11:41:01 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.112 2021/01/01 11:09:40 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.113 2021/01/01 11:41:01 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.112 2021/01/01 11:09:40 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.113 2021/01/01 11:41:01 rillig Exp $");
#endif
#include <float.h>
@@ -227,13 +227,16 @@ getnnode(sym_t *sym, int ntok)
if (strcmp(sym->s_name, "__FUNCTION__") == 0 ||
strcmp(sym->s_name, "__PRETTY_FUNCTION__")
== 0) {
+ /* __FUNCTION__/__PRETTY_FUNCTION... */
gnuism(316);
fixtype = 1;
} else if (strcmp(sym->s_name, "__func__") == 0) {
if (!Sflag)
+ /* __func__ is a C9X feature */
warning(317);
fixtype = 1;
} else {
+ /* %s undefined */
error(99, sym->s_name);
fixtype = 0;
}
@@ -412,10 +415,11 @@ struct_or_union_member(tnode_t *tn, op_t
* to a struct/union, but the right operand is not member of it.
*/
if (str != NULL) {
- /* illegal member use: %s */
if (eq && tflag) {
+ /* illegal member use: %s */
warning(102, msym->s_name);
} else {
+ /* illegal member use: %s */
error(102, msym->s_name);
}
return msym;
@@ -427,10 +431,11 @@ struct_or_union_member(tnode_t *tn, op_t
*/
if (eq) {
if (op == POINT) {
- /* left operand of "." must be struct/union object */
if (tflag) {
+ /* left operand of '.' must be struct/... */
warning(103);
} else {
+ /* left operand of '.' must be struct/... */
error(103);
}
} else {
@@ -438,9 +443,11 @@ struct_or_union_member(tnode_t *tn, op_t
/* left operand of "->" must be pointer to ... */
if (tflag && tn->tn_type->t_tspec == PTR) {
tyname(buf, sizeof(buf), tn->tn_type);
+ /* left operand of '->' must be pointer ... */
warning(104, buf);
} else {
tyname(buf, sizeof(buf), tn->tn_type);
+ /* left operand of '->' must be pointer ... */
error(104, buf);
}
}
@@ -785,17 +792,17 @@ typeok(op_t op, int arg, tnode_t *ln, tn
if (!ln->tn_lvalue) {
if (ln->tn_op == CVT && ln->tn_cast &&
ln->tn_left->tn_op == LOAD) {
- /* a cast to non-ptr does not yield an lvalue */
if (ln->tn_type->t_tspec == PTR)
break;
+ /* a cast does not yield an lvalue */
error(163);
}
/* %soperand of '%s' must be lvalue */
error(114, "", mp->m_name);
return 0;
} else if (ltp->t_const) {
- /* %soperand of '%s' must be modifiable lvalue */
if (!tflag)
+ /* %soperand of '%s' must be modifiable ... */
warning(115, "", mp->m_name);
}
break;
@@ -805,9 +812,9 @@ typeok(op_t op, int arg, tnode_t *ln, tn
} else if (!ln->tn_lvalue) {
if (ln->tn_op == CVT && ln->tn_cast &&
ln->tn_left->tn_op == LOAD) {
- /* a cast to non-ptr does not yield an lvalue */
if (ln->tn_type->t_tspec == PTR)
break;
+ /* a cast does not yield an lvalue */
error(163);
}
/* %soperand of '%s' must be lvalue */
@@ -1080,9 +1087,9 @@ typeok(op_t op, int arg, tnode_t *ln, tn
if (!ln->tn_lvalue) {
if (ln->tn_op == CVT && ln->tn_cast &&
ln->tn_left->tn_op == LOAD) {
- /* a cast to non-ptr does not yield an lvalue */
if (ln->tn_type->t_tspec == PTR)
break;
+ /* a cast does not yield an lvalue */
error(163);
}
/* %soperand of '%s' must be lvalue */
@@ -1090,8 +1097,8 @@ typeok(op_t op, int arg, tnode_t *ln, tn
return 0;
} else if (ltp->t_const || ((lt == STRUCT || lt == UNION) &&
has_constant_member(ltp))) {
- /* %soperand of %s must be modifiable lvalue */
if (!tflag)
+ /* %soperand of '%s' must be modifiable lvalue */
warning(115, "left ", mp->m_name);
}
break;
@@ -1795,12 +1802,13 @@ check_integer_conversion(op_t op, int ar
if (Pflag && psize(nt) > psize(ot) &&
tspec_is_uint(nt) != tspec_is_uint(ot)) {
- /* conversion to %s may sign-extend incorrectly (, arg #%d) */
if (aflag && pflag) {
if (op == FARG) {
+ /* conversion to '%s' may sign-extend ... */
warning(297, tyname(lbuf, sizeof(lbuf), tp),
arg);
} else {
+ /* conversion to '%s' may sign-extend ... */
warning(131, tyname(lbuf, sizeof(lbuf), tp));
}
}
@@ -1812,6 +1820,7 @@ check_integer_conversion(op_t op, int ar
case MINUS:
case MULT:
case SHL:
+ /* suggest cast from '%s' to '%s' on op %s to ... */
warning(324,
tyname(rbuf, sizeof(rbuf), gettyp(ot)),
tyname(lbuf, sizeof(lbuf), tp),
@@ -1828,11 +1837,13 @@ check_integer_conversion(op_t op, int ar
/* conversion from '%s' may lose accuracy */
if (aflag) {
if (op == FARG) {
+ /* conv. from '%s' to '%s' may lose ... */
warning(298,
tyname(rbuf, sizeof(rbuf), tn->tn_type),
tyname(lbuf, sizeof(lbuf), tp),
arg);
} else {
+ /* conv. from '%s' to '%s' may lose accuracy */
warning(132,
tyname(rbuf, sizeof(rbuf), tn->tn_type),
tyname(lbuf, sizeof(lbuf), tp));
@@ -2078,10 +2089,7 @@ cvtcon(op_t op, int arg, type_t *tp, val
if (nsz > osz &&
(nv->v_quad & qbmasks[osz - 1]) != 0 &&
(nv->v_quad & xmask) != xmask) {
- /*
- * extra bits set to 0 in conversion
- * of '%s' to '%s', op %s
- */
+ /* extra bits set to 0 in conv. of '%s' ... */
warning(309,
tyname(lbuf, sizeof(lbuf), gettyp(ot)),
tyname(rbuf, sizeof(rbuf), tp),
@@ -2390,6 +2398,7 @@ build_real_imag(op_t op, tnode_t *ln)
cn = new_int_const_node(FLOAT, (int64_t)1);
break;
default:
+ /* __%s__ is illegal for type %s */
error(276, op == REAL ? "real" : "imag",
tyname(buf, sizeof(buf), ln->tn_type));
return NULL;
@@ -2409,8 +2418,8 @@ build_ampersand(tnode_t *tn, int noign)
tspec_t t;
if (!noign && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) {
- /* & before array or function: ignored */
if (tflag)
+ /* '&' before array or function: ignored */
warning(127);
return tn;
}
@@ -3024,6 +3033,7 @@ build_offsetof(type_t *tp, sym_t *sym)
#endif
tspec_t t = tp->t_tspec;
if (t != STRUCT && t != UNION)
+ /* unacceptable operand of '%s' */
error(111, "offsetof");
// XXX: wrong size, no checking for sym fixme
@@ -3166,6 +3176,7 @@ cast(tnode_t *tn, type_t *tp)
sym_t *m;
str_t *str = tp->t_str;
if (!Sflag) {
+ /* union cast is a C9X feature */
error(328);
return NULL;
}
@@ -3179,12 +3190,13 @@ cast(tnode_t *tn, type_t *tp)
return tn;
}
}
+ /* type '%s' is not a member of '%s' */
error(329, tyname(buf, sizeof(buf), tn->tn_type),
tyname(buf1, sizeof(buf1), tp));
return NULL;
} else if (nt == STRUCT || nt == ARRAY || nt == FUNC) {
- /* invalid cast expression */
if (!Sflag || nt == ARRAY || nt == FUNC) {
+ /* invalid cast expression */
error(147);
return NULL;
}
@@ -3421,10 +3433,11 @@ constant(tnode_t *tn, int required)
v->v_quad = 1;
}
- /* integral constant expression expected */
if (required)
+ /* integral constant expression expected */
error(55);
else
+ /* variable array dimension is a C99/GCC extension */
c99ism(318);
if (!tspec_is_int(v->v_tspec))
@@ -3676,8 +3689,8 @@ check_expr_misc(tnode_t *tn, int vctx, i
outcall(tn, vctx || tctx, rvdisc);
break;
case EQ:
- /* equality operator "==" found where "=" was exp. */
if (hflag && eqwarn)
+ /* operator '==' found where '=' was expected */
warning(160);
break;
case CON: