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: inline macro 'sflag'



details:   https://anonhg.NetBSD.org/src/rev/c62b48b6e594
branches:  trunk
changeset: 365886:c62b48b6e594
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 30 22:31:23 2022 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  19 ++++++++++++-----
 usr.bin/xlint/lint1/decl.c     |  44 +++++++++++++++++++++++++++--------------
 usr.bin/xlint/lint1/err.c      |  12 +++++++---
 usr.bin/xlint/lint1/externs1.h |  14 +------------
 usr.bin/xlint/lint1/func.c     |  11 ++++++---
 usr.bin/xlint/lint1/lex.c      |  16 +++++++++-----
 usr.bin/xlint/lint1/tree.c     |  20 ++++++++++++------
 7 files changed, 81 insertions(+), 55 deletions(-)

diffs (truncated from 435 to 300 lines):

diff -r c42884ecf4ab -r c62b48b6e594 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Apr 30 21:38:03 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Apr 30 22:31:23 2022 +0000
@@ -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 @@
 
 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 @@
                $$ = $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 @@
          }
        | 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 @@
  */
 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) {
diff -r c42884ecf4ab -r c62b48b6e594 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 30 21:38:03 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 30 22:31:23 2022 +0000
@@ -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 @@
                 */
                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 @@
                                }
                                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 @@
 #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 @@
        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 @@
                        /* 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 @@
                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 @@
                        /* 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 @@
                    !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 @@
         * "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 @@
        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 @@
                        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 @@
 
        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 {
diff -r c42884ecf4ab -r c62b48b6e594 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Apr 30 21:38:03 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Apr 30 22:31:23 2022 +0000
@@ -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 @@
 (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 @@
 (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)
diff -r c42884ecf4ab -r c62b48b6e594 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Apr 30 21:38:03 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Apr 30 22:31:23 2022 +0000
@@ -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_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);
 
 /*
diff -r c42884ecf4ab -r c62b48b6e594 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Apr 30 21:38:03 2022 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Apr 30 22:31:23 2022 +0000
@@ -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 @@
                         * 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 */



Home | Main Index | Thread Index | Old Index