Module Name: src Committed By: rillig Date: Sat Apr 16 19:18:17 UTC 2022
Modified Files: src/usr.bin/xlint/lint1: decl.c err.c externs1.h lex.c lint1.h tree.c Log Message: lint: migrate gflag to allow_gcc No functional change. To generate a diff of this commit: cvs rdiff -u -r1.277 -r1.278 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.161 -r1.162 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.155 -r1.156 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.120 -r1.121 src/usr.bin/xlint/lint1/lex.c cvs rdiff -u -r1.151 -r1.152 src/usr.bin/xlint/lint1/lint1.h cvs rdiff -u -r1.428 -r1.429 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/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.277 src/usr.bin/xlint/lint1/decl.c:1.278 --- src/usr.bin/xlint/lint1/decl.c:1.277 Sun Apr 10 12:14:10 2022 +++ src/usr.bin/xlint/lint1/decl.c Sat Apr 16 19:18:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.277 2022/04/10 12:14:10 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.278 2022/04/16 19:18:17 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.277 2022/04/10 12:14:10 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.278 2022/04/16 19:18:17 rillig Exp $"); #endif #include <sys/param.h> @@ -1066,24 +1066,18 @@ check_bit_field_type(sym_t *dsym, type_t /* bit-field of type plain 'int' has ... */ warning(344); } - } else if (t != INT && t != UINT && t != BOOL) { - /* - * Non-integer types are always illegal for bitfields, - * regardless of BITFIELDTYPE. Integer types not dealt with - * above are okay only if BITFIELDTYPE is in effect. - */ - if (!(bitfieldtype_ok || gflag) || !is_integer(t)) { - unsigned int sz; - - /* illegal bit-field type '%s' */ - warning(35, type_name(tp)); - sz = tp->t_flen; - dsym->s_type = tp = block_dup_type(gettyp(t = INT)); - if ((tp->t_flen = sz) > size_in_bits(t)) - tp->t_flen = size_in_bits(t); - *inout_t = t; - *inout_tp = tp; - } + } else if (!(t == INT || t == UINT || t == BOOL || + (is_integer(t) && (bitfieldtype_ok || allow_gcc)))) { + + /* illegal bit-field type '%s' */ + warning(35, type_name(tp)); + + unsigned int sz = tp->t_flen; + dsym->s_type = tp = block_dup_type(gettyp(t = INT)); + if ((tp->t_flen = sz) > size_in_bits(t)) + tp->t_flen = size_in_bits(t); + *inout_t = t; + *inout_tp = tp; } } @@ -2645,23 +2639,21 @@ static bool check_prototype_declaration(sym_t *arg, sym_t *parg) { type_t *tp, *ptp; - bool dowarn, msg; + bool dowarn; tp = arg->s_type; ptp = parg->s_type; - msg = false; dowarn = false; if (!eqtype(tp, ptp, true, true, &dowarn)) { if (eqtype(tp, ptp, true, false, &dowarn)) { /* type does not match prototype: %s */ - gnuism(58, arg->s_name); - msg = sflag || !gflag; + return gnuism(58, arg->s_name); } else { /* type does not match prototype: %s */ error(58, arg->s_name); - msg = true; + return true; } } else if (dowarn) { if (sflag) @@ -2670,10 +2662,10 @@ check_prototype_declaration(sym_t *arg, else /* type does not match prototype: %s */ warning(58, arg->s_name); - msg = true; + return true; } - return msg; + return false; } static void Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.161 src/usr.bin/xlint/lint1/err.c:1.162 --- src/usr.bin/xlint/lint1/err.c:1.161 Sat Apr 16 15:55:10 2022 +++ src/usr.bin/xlint/lint1/err.c Sat Apr 16 19:18:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.161 2022/04/16 15:55:10 rillig Exp $ */ +/* $NetBSD: err.c,v 1.162 2022/04/16 19:18:17 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.161 2022/04/16 15:55:10 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.162 2022/04/16 19:18:17 rillig Exp $"); #endif #include <sys/types.h> @@ -649,14 +649,15 @@ void { va_list ap; - if (c11flag || gflag) + /* FIXME: C11 mode has nothing to do with GCC mode. */ + if (c11flag || allow_gcc) return; va_start(ap, msgid); verror_at(msgid, &curr_pos, ap); va_end(ap); } -void +bool (gnuism)(int msgid, ...) { va_list ap; @@ -668,4 +669,5 @@ void if (severity == 1) vwarning_at(msgid, &curr_pos, ap); va_end(ap); + return severity > 0; } Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.155 src/usr.bin/xlint/lint1/externs1.h:1.156 --- src/usr.bin/xlint/lint1/externs1.h:1.155 Sat Apr 16 13:25:27 2022 +++ src/usr.bin/xlint/lint1/externs1.h Sat Apr 16 19:18:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.155 2022/04/16 13:25:27 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.156 2022/04/16 19:18:17 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -64,13 +64,12 @@ extern bool allow_gcc; * * 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". + * + GCC", in all calls to gnuism. */ #define tflag (allow_trad && !allow_c90) #define sflag (!allow_trad && !allow_c99) -#define Sflag (!!allow_c99) -#define c11flag (!!allow_c11) -#define gflag (!!allow_gcc) +#define Sflag allow_c99 +#define c11flag allow_c11 extern void norecover(void); @@ -177,7 +176,7 @@ extern void warning_at(int, const pos_t extern void message_at(int, const pos_t *, ...); extern void error(int, ...); extern void warning(int, ...); -extern void gnuism(int, ...); +extern bool gnuism(int, ...); extern void c99ism(int, ...); extern void c11ism(int, ...); extern void internal_error(const char *, int, const char *, ...) Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.120 src/usr.bin/xlint/lint1/lex.c:1.121 --- src/usr.bin/xlint/lint1/lex.c:1.120 Sat Apr 16 18:13:54 2022 +++ src/usr.bin/xlint/lint1/lex.c Sat Apr 16 19:18:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.120 2022/04/16 18:13:54 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.121 2022/04/16 19:18:17 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.120 2022/04/16 18:13:54 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.121 2022/04/16 19:18:17 rillig Exp $"); #endif #include <ctype.h> @@ -417,9 +417,10 @@ initscan(void) for (kw = keywords; kw->kw_name != NULL; kw++) { if ((kw->kw_c90 || kw->kw_c99) && tflag) continue; - if (kw->kw_c99 && !(Sflag || gflag)) + /* FIXME: C99 and GCC are independent. */ + if (kw->kw_c99 && !(Sflag || allow_gcc)) continue; - if (kw->kw_gcc && !gflag) + if (kw->kw_gcc && !allow_gcc) continue; if (kw->kw_plain) add_keyword(kw, false, false); @@ -1228,9 +1229,9 @@ lex_slash_slash_comment(void) { int c; - if (!Sflag && !gflag) + if (!allow_c99 && !allow_gcc) /* %s does not support // comments */ - gnuism(312, tflag ? "traditional C" : "C90"); + gnuism(312, allow_c90 ? "C90" : "traditional C"); while ((c = inpc()) != EOF && c != '\n') continue; Index: src/usr.bin/xlint/lint1/lint1.h diff -u src/usr.bin/xlint/lint1/lint1.h:1.151 src/usr.bin/xlint/lint1/lint1.h:1.152 --- src/usr.bin/xlint/lint1/lint1.h:1.151 Sun Apr 10 12:14:10 2022 +++ src/usr.bin/xlint/lint1/lint1.h Sat Apr 16 19:18:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lint1.h,v 1.151 2022/04/10 12:14:10 rillig Exp $ */ +/* $NetBSD: lint1.h,v 1.152 2022/04/16 19:18:17 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -492,10 +492,11 @@ check_printf(const char *fmt, ...) wrap_check_printf_at(message_at, msgid, pos, ##args) # define wrap_check_printf(func, msgid, args...) \ - do { \ + ({ \ check_printf(__CONCAT(MSG_, msgid), ##args); \ (func)(msgid, ##args); \ - } while (false) + /* LINTED 129 */ \ + }) # define error(msgid, args...) wrap_check_printf(error, msgid, ##args) # define warning(msgid, args...) wrap_check_printf(warning, msgid, ##args) Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.428 src/usr.bin/xlint/lint1/tree.c:1.429 --- src/usr.bin/xlint/lint1/tree.c:1.428 Sat Apr 16 14:06:10 2022 +++ src/usr.bin/xlint/lint1/tree.c Sat Apr 16 19:18:17 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.428 2022/04/16 14:06:10 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.429 2022/04/16 19:18:17 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.428 2022/04/16 14:06:10 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.429 2022/04/16 19:18:17 rillig Exp $"); #endif #include <float.h> @@ -200,7 +200,7 @@ bool is_compiler_builtin(const char *name) { /* https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html */ - if (gflag) { + if (allow_gcc) { if (strncmp(name, "__atomic_", 9) == 0 || strncmp(name, "__builtin_", 10) == 0 || strcmp(name, "alloca") == 0 || @@ -245,7 +245,7 @@ build_name_call(sym_t *sym) * they are regular functions compatible with * non-prototype calling conventions. */ - if (gflag && is_gcc_bool_builtin(sym->s_name)) + if (allow_gcc && is_gcc_bool_builtin(sym->s_name)) sym->s_type = gettyp(BOOL); } else if (Sflag) { @@ -3589,13 +3589,14 @@ cast(tnode_t *tn, type_t *tp) if (nt == VOID) { /* - * XXX ANSI C requires scalar types or void (Plauger & Brodie). - * But this seems really questionable. + * C90 6.3.4, C99 6.5.4p2 and C11 6.5.4p2 allow any type to + * be cast to void. The only other allowed casts are from a + * scalar type to a scalar type. */ } else if (nt == UNION) { sym_t *m; struct_or_union *str = tp->t_str; - if (!gflag) { + if (!allow_gcc) { /* union cast is a GCC extension */ error(328); return NULL; @@ -3616,7 +3617,7 @@ cast(tnode_t *tn, type_t *tp) return NULL; } else if (nt == STRUCT || nt == ARRAY || nt == FUNC) { /* Casting to a struct is an undocumented GCC extension. */ - if (!(gflag && nt == STRUCT)) + if (!(allow_gcc && nt == STRUCT)) goto invalid_cast; } else if (ot == STRUCT || ot == UNION) { goto invalid_cast;