lint: inline macro 'sflag'

Mark all places where lint's C90 mode is stricter than its C99 mode.

Most of the situations in which lint produces only warnings instead of
errors covered by the "Constraints" sections in the relevant standards.
This doesn't prevent a specific compiler from accepting it though.

No functional change.
This commit is contained in:
rillig 2022-04-30 22:31:23 +00:00
parent d03e0048ed
commit 71ecb3cfc0
7 changed files with 81 additions and 55 deletions

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: cgram.y,v 1.409 2022/04/30 21:38:03 rillig Exp $ */
/* $NetBSD: cgram.y,v 1.410 2022/04/30 22:31:23 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.409 2022/04/30 21:38:03 rillig Exp $");
__RCSID("$NetBSD: cgram.y,v 1.410 2022/04/30 22:31:23 rillig Exp $");
#endif
#include <limits.h>
@ -372,7 +372,8 @@ static inline void cgram_print(FILE *, int, YYSTYPE);
program:
/* empty */ {
if (sflag) {
/* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99) {
/* empty translation unit */
error(272);
} else if (allow_c90) {
@ -1482,7 +1483,8 @@ vararg_parameter_type_list: /* specific to lint */
$$ = $1;
}
| T_ELLIPSIS {
if (sflag) {
/* TODO: C99 6.7.5 makes this an error as well. */
if (!allow_trad && !allow_c99) {
/* ANSI C requires formal parameter before '...' */
error(84);
} else if (allow_c90) {
@ -1919,7 +1921,11 @@ external_declaration: /* C99 6.9 */
}
| asm_statement /* GCC extension */
| T_SEMI { /* GCC extension */
if (sflag) {
/*
* TODO: Only allow this in GCC mode, not in plain C99.
* This is one of the top 10 warnings in the NetBSD build.
*/
if (!allow_trad && !allow_c99) {
/* empty declaration */
error(0);
} else if (allow_c90) {
@ -1940,7 +1946,8 @@ external_declaration: /* C99 6.9 */
*/
top_level_declaration: /* C99 6.9 calls this 'declaration' */
begin_type end_type notype_init_declarators T_SEMI {
if (sflag) {
/* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99) {
/* old style declaration; add 'int' */
error(1);
} else if (allow_c90) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.279 2022/04/30 21:38:03 rillig Exp $ */
/* $NetBSD: decl.c,v 1.280 2022/04/30 22:31:23 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.279 2022/04/30 21:38:03 rillig Exp $");
__RCSID("$NetBSD: decl.c,v 1.280 2022/04/30 22:31:23 rillig Exp $");
#endif
#include <sys/param.h>
@ -958,7 +958,8 @@ check_type(sym_t *sym)
*/
if (t == FUNC && !tp->t_proto &&
!(to == NOTSPEC && sym->s_osdef)) {
if (sflag && hflag)
/* TODO: Make this an error in C99 mode as well. */
if ((!allow_trad && !allow_c99) && hflag)
/* function declaration is not a prototype */
warning(287);
}
@ -974,7 +975,8 @@ check_type(sym_t *sym)
}
return;
} else if (tp->t_const || tp->t_volatile) {
if (sflag) { /* XXX or better allow_c90? */
/* TODO: Make this a warning in C99 mode as well. */
if (!allow_trad && !allow_c99) { /* XXX or better allow_c90? */
/* function cannot return const... */
warning(228);
}
@ -996,7 +998,8 @@ check_type(sym_t *sym)
#if 0 /* errors are produced by length_in_bits */
} else if (is_incomplete(tp)) {
/* array of incomplete type */
if (sflag) {
/* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99) {
/* array of incomplete type */
error(301);
} else {
@ -1053,7 +1056,8 @@ check_bit_field_type(sym_t *dsym, type_t **const inout_tp, tspec_t *inout_t)
if (t == CHAR || t == UCHAR || t == SCHAR ||
t == SHORT || t == USHORT || t == ENUM) {
if (!bitfieldtype_ok) {
if (sflag) {
/* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99) {
/* bit-field type '%s' invalid in ANSI C */
warning(273, type_name(tp));
} else if (pflag) {
@ -1699,7 +1703,8 @@ mktag(sym_t *tag, tspec_t kind, bool decl, bool semi)
/* a new tag, no empty declaration */
dcs->d_enclosing->d_nonempty_decl = true;
if (scl == ENUM_TAG && !decl) {
if (allow_c90 && (sflag || pflag))
/* TODO: Make this an error in C99 mode as well. */
if (allow_c90 && ((!allow_trad && !allow_c99) || pflag))
/* forward reference to enum type */
warning(42);
}
@ -1753,7 +1758,8 @@ newtag(sym_t *tag, scl_t scl, bool decl, bool semi)
if (semi) {
/* "struct a;" */
if (allow_c90) {
if (!sflag)
/* XXX: Why is this warning suppressed in C90 mode? */
if (allow_trad || allow_c99)
/* declaration introduces new ... */
warning(44, storage_class_name(scl),
tag->s_name);
@ -1775,7 +1781,8 @@ newtag(sym_t *tag, scl_t scl, bool decl, bool semi)
/* base type is really '%s %s' */
warning(45, storage_class_name(tag->s_scl),
tag->s_name);
if (!sflag) {
/* XXX: Why is this warning suppressed in C90 mode? */
if (allow_trad || allow_c99) {
/* declaration introduces new type in ... */
warning(44, storage_class_name(scl),
tag->s_name);
@ -2002,7 +2009,8 @@ declare_extern(sym_t *dsym, bool initflg, sbuf_t *renaming)
!check_redeclaration(dsym, (dowarn = false, &dowarn))) {
if (dowarn) {
if (sflag)
/* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99)
/* redeclaration of %s */
error(27, dsym->s_name);
else
@ -2169,7 +2177,8 @@ check_redeclaration(sym_t *dsym, bool *dowarn)
* "static a; int a;", "static a; int a = 1;", "static a = 1; int a;"
*/
/* redeclaration of %s; ANSI C requires "static" */
if (sflag) {
/* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99) {
/* redeclaration of %s; ANSI C requires static */
warning(30, dsym->s_name);
print_previous_declaration(-1, rsym);
@ -2369,8 +2378,10 @@ check_old_style_definition(sym_t *rdsym, sym_t *dsym)
while (narg-- > 0) {
dowarn = false;
/*
* If it does not match due to promotion and sflag is
* not set we print only a warning.
* If it does not match due to promotion and lint runs in
* "traditional to C90" migration mode, print only a warning.
*
* XXX: Where is this "only a warning"?
*/
if (!eqtype(arg->s_type, parg->s_type, true, true, &dowarn) ||
dowarn) {
@ -2656,7 +2667,8 @@ check_prototype_declaration(sym_t *arg, sym_t *parg)
return true;
}
} else if (dowarn) {
if (sflag)
/* TODO: Make this an error in C99 mode as well. */
if (!allow_trad && !allow_c99)
/* type does not match prototype: %s */
error(58, arg->s_name);
else
@ -3311,7 +3323,9 @@ check_global_variable_size(const sym_t *sym)
if (len_in_bits == 0 &&
sym->s_type->t_tspec == ARRAY && sym->s_type->t_dim == 0) {
if (!allow_c90 || (sym->s_scl == EXTERN && !sflag)) {
/* TODO: C99 6.7.5.2p1 defines this as an error as well. */
if (!allow_c90 ||
(sym->s_scl == EXTERN && (allow_trad || allow_c99))) {
/* empty array declaration: %s */
warning_at(190, &sym->s_def_pos, sym->s_name);
} else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.163 2022/04/30 18:51:00 rillig Exp $ */
/* $NetBSD: err.c,v 1.164 2022/04/30 22:31:23 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: err.c,v 1.163 2022/04/30 18:51:00 rillig Exp $");
__RCSID("$NetBSD: err.c,v 1.164 2022/04/30 22:31:23 rillig Exp $");
#endif
#include <sys/types.h>
@ -634,9 +634,12 @@ void
(c99ism)(int msgid, ...)
{
va_list ap;
int severity = (!allow_c99 && !allow_gcc ? 1 : 0) + (sflag ? 1 : 0);
if (allow_c99)
return;
va_start(ap, msgid);
int severity = (!allow_gcc ? 1 : 0) + (!allow_trad ? 1 : 0);
if (severity == 2)
verror_at(msgid, &curr_pos, ap);
if (severity == 1)
@ -661,7 +664,8 @@ bool
(gnuism)(int msgid, ...)
{
va_list ap;
int severity = (!allow_gcc ? 1 : 0) + (sflag ? 1 : 0);
int severity = (!allow_gcc ? 1 : 0) +
(!allow_trad && !allow_c99 ? 1 : 0);
va_start(ap, msgid);
if (severity == 2)

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.159 2022/04/30 21:38:03 rillig Exp $ */
/* $NetBSD: externs1.h,v 1.160 2022/04/30 22:31:23 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -56,18 +56,6 @@ extern bool allow_c99;
extern bool allow_c11;
extern bool allow_gcc;
/*
* TODO: Replace the old flags with the new expressions, checking in each
* case whether the specific condition still makes sense. When lint was
* invented in 1995, it did not know about C99 mode, which makes all
* conditions involving sflag suspicious.
*
* In 1995, gflag meant "C90 plus GCC extensions". That definition needs to
* be extended to C99 and later as well to properly match "C99 + GCC" or "C11
* + GCC", in all calls to gnuism.
*/
#define sflag (!allow_trad && !allow_c99)
extern void norecover(void);
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: func.c,v 1.134 2022/04/30 21:38:03 rillig Exp $ */
/* $NetBSD: func.c,v 1.135 2022/04/30 22:31:23 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.134 2022/04/30 21:38:03 rillig Exp $");
__RCSID("$NetBSD: func.c,v 1.135 2022/04/30 22:31:23 rillig Exp $");
#endif
#include <stdlib.h>
@ -307,7 +307,8 @@ funcdef(sym_t *fsym)
* be printed in check_func_lint_directives().
*/
if (dowarn && !fsym->s_osdef) {
if (sflag)
/* TODO: error in C99 mode as well? */
if (!allow_trad && !allow_c99)
/* redeclaration of %s */
error(27, fsym->s_name);
else
@ -339,7 +340,9 @@ funcdef(sym_t *fsym)
}
if (fsym->s_osdef && !fsym->s_type->t_proto) {
if (sflag && hflag && strcmp(fsym->s_name, "main") != 0)
/* TODO: Make this an error in C99 mode as well. */
if ((!allow_trad && !allow_c99) && hflag &&
strcmp(fsym->s_name, "main") != 0)
/* function definition is not a prototype */
warning(286);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: lex.c,v 1.127 2022/04/30 21:38:03 rillig Exp $ */
/* $NetBSD: lex.c,v 1.128 2022/04/30 22:31:23 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: lex.c,v 1.127 2022/04/30 21:38:03 rillig Exp $");
__RCSID("$NetBSD: lex.c,v 1.128 2022/04/30 22:31:23 rillig Exp $");
#endif
#include <ctype.h>
@ -629,10 +629,12 @@ lex_integer_constant(const char *yytext, size_t yyleng, int base)
if (typ == UINT || typ == ULONG) {
if (!allow_c90) {
typ = LONG;
} else if (!sflag) {
} else if (allow_trad || allow_c99) {
/*
* Remember that the constant is unsigned
* only in ANSI C
* only in ANSI C.
*
* TODO: C99 behaves like C90 here.
*/
ansiu = true;
}
@ -650,7 +652,8 @@ lex_integer_constant(const char *yytext, size_t yyleng, int base)
case LONG:
if (uq > TARG_LONG_MAX && allow_c90) {
typ = ULONG;
if (!sflag)
/* TODO: C99 behaves like C90 here. */
if (allow_trad || allow_c99)
ansiu = true;
if (uq > TARG_ULONG_MAX && !warned) {
/* integer constant out of range */
@ -667,7 +670,8 @@ lex_integer_constant(const char *yytext, size_t yyleng, int base)
case QUAD:
if (uq > TARG_QUAD_MAX && allow_c90) {
typ = UQUAD;
if (!sflag)
/* TODO: C99 behaves like C90 here. */
if (allow_trad || allow_c99)
ansiu = true;
}
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.438 2022/04/30 21:38:03 rillig Exp $ */
/* $NetBSD: tree.c,v 1.439 2022/04/30 22:31:23 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.438 2022/04/30 21:38:03 rillig Exp $");
__RCSID("$NetBSD: tree.c,v 1.439 2022/04/30 22:31:23 rillig Exp $");
#endif
#include <float.h>
@ -1070,7 +1070,8 @@ typeok_colon_pointer(const mod_t *mp, const type_t *ltp, const type_t *rtp)
if ((lst == VOID && rst == FUNC) || (lst == FUNC && rst == VOID)) {
/* (void *)0 handled above */
if (sflag)
/* TODO: C99 behaves like C90 here. */
if (!allow_trad && !allow_c99)
/* ANSI C forbids conversion of %s to %s, op %s */
warning(305, "function pointer", "'void *'",
mp->m_name);
@ -1343,7 +1344,9 @@ check_pointer_comparison(op_t op, const tnode_t *ln, const tnode_t *rn)
rst = (rtp = rn->tn_type)->t_subt->t_tspec;
if (lst == VOID || rst == VOID) {
if (sflag && (lst == FUNC || rst == FUNC)) {
/* TODO: C99 behaves like C90 here. */
if ((!allow_trad && !allow_c99) &&
(lst == FUNC || rst == FUNC)) {
/* (void *)0 already handled in typeok() */
*(lst == FUNC ? &lsts : &rsts) = "function pointer";
*(lst == VOID ? &lsts : &rsts) = "'void *'";
@ -1359,7 +1362,8 @@ check_pointer_comparison(op_t op, const tnode_t *ln, const tnode_t *rn)
}
if (lst == FUNC && rst == FUNC) {
if (sflag && op != EQ && op != NE)
/* TODO: C99 behaves like C90 here, see C99 6.5.8p2. */
if ((!allow_trad && !allow_c99) && op != EQ && op != NE)
/* ANSI C forbids ordered comparisons of ... */
warning(125);
}
@ -1486,7 +1490,8 @@ check_assign_void_pointer(op_t op, int arg,
return;
/* two pointers, at least one pointer to void */
if (!(sflag && (lst == FUNC || rst == FUNC)))
/* TODO: C99 behaves like C90 here. */
if (!((!allow_trad && !allow_c99) && (lst == FUNC || rst == FUNC)))
return;
/* comb. of ptr to func and ptr to void */
@ -2335,7 +2340,8 @@ check_pointer_conversion(tnode_t *tn, type_t *ntp)
ost = ostp->t_tspec;
if (nst == VOID || ost == VOID) {
if (sflag && (nst == FUNC || ost == FUNC)) {
/* TODO: C99 behaves like C90 here. */
if ((!allow_trad && !allow_c99) && (nst == FUNC || ost == FUNC)) {
/* null pointers are already handled in convert() */
*(nst == FUNC ? &nts : &ots) = "function pointer";
*(nst == VOID ? &nts : &ots) = "'void *'";