Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: migrate gflag to allow_gcc



details:   https://anonhg.NetBSD.org/src/rev/c3aaaafe346d
branches:  trunk
changeset: 365266:c3aaaafe346d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 16 19:18:17 2022 +0000

description:
lint: migrate gflag to allow_gcc

No functional change.

diffstat:

 usr.bin/xlint/lint1/decl.c     |  46 +++++++++++++++++------------------------
 usr.bin/xlint/lint1/err.c      |  10 +++++---
 usr.bin/xlint/lint1/externs1.h |  11 ++++-----
 usr.bin/xlint/lint1/lex.c      |  13 ++++++-----
 usr.bin/xlint/lint1/lint1.h    |   7 +++--
 usr.bin/xlint/lint1/tree.c     |  17 ++++++++-------
 6 files changed, 50 insertions(+), 54 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r bce1f73c4574 -r c3aaaafe346d usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 16 18:41:21 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 16 19:18:17 2022 +0000
@@ -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 @@
                        /* 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 @@
 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 @@
                else
                        /* type does not match prototype: %s */
                        warning(58, arg->s_name);
-               msg = true;
+               return true;
        }
 
-       return msg;
+       return false;
 }
 
 static void
diff -r bce1f73c4574 -r c3aaaafe346d usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Apr 16 18:41:21 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Apr 16 19:18:17 2022 +0000
@@ -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 @@
 {
        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 @@
        if (severity == 1)
                vwarning_at(msgid, &curr_pos, ap);
        va_end(ap);
+       return severity > 0;
 }
diff -r bce1f73c4574 -r c3aaaafe346d usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Apr 16 18:41:21 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Apr 16 19:18:17 2022 +0000
@@ -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 @@
  *
  * 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    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 *, ...)
diff -r bce1f73c4574 -r c3aaaafe346d usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Apr 16 18:41:21 2022 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Apr 16 19:18:17 2022 +0000
@@ -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 @@
        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 @@
 {
        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;
diff -r bce1f73c4574 -r c3aaaafe346d usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Apr 16 18:41:21 2022 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Apr 16 19:18:17 2022 +0000
@@ -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 @@
        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)
diff -r bce1f73c4574 -r c3aaaafe346d usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Apr 16 18:41:21 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Apr 16 19:18:17 2022 +0000
@@ -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 @@
 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 @@
                 * 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 @@
 
        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 @@
                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) {



Home | Main Index | Thread Index | Old Index