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 'tflag'



details:   https://anonhg.NetBSD.org/src/rev/c42884ecf4ab
branches:  trunk
changeset: 365885:c42884ecf4ab
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 30 21:38:03 2022 +0000

description:
lint: inline macro 'tflag'

The definition of the macro tested both allow_trad and allow_c90, but
there is only a single mode in which allow_c90 is false, therefore it
suffices to test only that.

While double-checking each occurrence of tflag individually, I learned
why lint performs lookups of struct members only by name, independently
of the struct in which they are declared.  See typeok_arrow for details.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  16 ++++++------
 usr.bin/xlint/lint1/decl.c     |  46 ++++++++++++++++++------------------
 usr.bin/xlint/lint1/externs1.h |   5 +--
 usr.bin/xlint/lint1/func.c     |   8 +++---
 usr.bin/xlint/lint1/init.c     |  10 +++---
 usr.bin/xlint/lint1/lex.c      |  26 ++++++++++----------
 usr.bin/xlint/lint1/main1.c    |   6 ++--
 usr.bin/xlint/lint1/tree.c     |  53 +++++++++++++++++++++++------------------
 8 files changed, 88 insertions(+), 82 deletions(-)

diffs (truncated from 701 to 300 lines):

diff -r 0367ed364b47 -r c42884ecf4ab usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Apr 30 20:43:16 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Apr 30 21:38:03 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.408 2022/04/30 19:18:48 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.409 2022/04/30 21:38:03 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.408 2022/04/30 19:18:48 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.409 2022/04/30 21:38:03 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -375,7 +375,7 @@
                if (sflag) {
                        /* empty translation unit */
                        error(272);
-               } else if (!tflag) {
+               } else if (allow_c90) {
                        /* empty translation unit */
                        warning(272);
                }
@@ -405,7 +405,7 @@
 string:
          T_STRING
        | string T_STRING {
-               if (tflag) {
+               if (!allow_c90) {
                        /* concatenated strings are illegal in traditional C */
                        warning(219);
                }
@@ -590,7 +590,7 @@
                $$ = build_unary(INDIR, $2, $3);
          }
        | T_ADDITIVE sys cast_expression {
-               if (tflag && $1 == PLUS) {
+               if (!allow_c90 && $1 == PLUS) {
                        /* unary + is illegal in traditional C */
                        warning(100);
                }
@@ -1485,7 +1485,7 @@
                if (sflag) {
                        /* ANSI C requires formal parameter before '...' */
                        error(84);
-               } else if (!tflag) {
+               } else if (allow_c90) {
                        /* ANSI C requires formal parameter before '...' */
                        warning(84);
                }
@@ -1922,7 +1922,7 @@
                if (sflag) {
                        /* empty declaration */
                        error(0);
-               } else if (!tflag) {
+               } else if (allow_c90) {
                        /* empty declaration */
                        warning(0);
                }
@@ -1943,7 +1943,7 @@
                if (sflag) {
                        /* old style declaration; add 'int' */
                        error(1);
-               } else if (!tflag) {
+               } else if (allow_c90) {
                        /* old style declaration; add 'int' */
                        warning(1);
                }
diff -r 0367ed364b47 -r c42884ecf4ab usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 30 20:43:16 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 30 21:38:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.278 2022/04/16 19:18:17 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.279 2022/04/30 21:38:03 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.278 2022/04/16 19:18:17 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.279 2022/04/30 21:38:03 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -328,7 +328,7 @@
                dcs->d_rank_mod = NOTSPEC;
                if (!quadflg)
                        /* %s does not support 'long long' */
-                       c99ism(265, tflag ? "traditional C" : "C90");
+                       c99ism(265, allow_c90 ? "C90" : "traditional C");
        }
 
        if (dcs->d_type != NULL && dcs->d_type->t_typedef) {
@@ -410,7 +410,7 @@
        if ((t == SIGNED || t == UNSIGN) &&
            (t2 == CHAR || t2 == SHORT || t2 == INT ||
             t2 == LONG || t2 == QUAD)) {
-               if (!tflag)
+               if (allow_c90)
                        /* modifying typedef with '%s'; only qualifiers... */
                        warning(5, tspec_name(t));
                td = block_dup_type(gettyp(merge_signedness(t2, t)));
@@ -766,7 +766,7 @@
        if (l == LONG && t == FLOAT) {
                l = NOTSPEC;
                t = DOUBLE;
-               if (!tflag)
+               if (allow_c90)
                        /* use 'double' instead of 'long float' */
                        warning(6);
        }
@@ -774,7 +774,7 @@
                l = NOTSPEC;
                t = LDOUBLE;
        }
-       if (t == LDOUBLE && tflag) {
+       if (t == LDOUBLE && !allow_c90) {
                /* 'long double' is illegal in traditional C */
                warning(266);
        }
@@ -974,7 +974,7 @@
                                }
                                return;
                        } else if (tp->t_const || tp->t_volatile) {
-                               if (sflag) {    /* XXX or better !tflag ? */
+                               if (sflag) {    /* XXX or better allow_c90? */
                                        /* function cannot return const... */
                                        warning(228);
                                }
@@ -1414,7 +1414,7 @@
 #endif
 
        if (dcs->d_proto) {
-               if (tflag)
+               if (!allow_c90)
                        /* function prototypes are illegal in traditional C */
                        warning(270);
                args = new_style_function(args);
@@ -1699,7 +1699,7 @@
                        /* a new tag, no empty declaration */
                        dcs->d_enclosing->d_nonempty_decl = true;
                        if (scl == ENUM_TAG && !decl) {
-                               if (!tflag && (sflag || pflag))
+                               if (allow_c90 && (sflag || pflag))
                                        /* forward reference to enum type */
                                        warning(42);
                        }
@@ -1752,7 +1752,7 @@
        if (tag->s_block_level < block_level) {
                if (semi) {
                        /* "struct a;" */
-                       if (!tflag) {
+                       if (allow_c90) {
                                if (!sflag)
                                        /* declaration introduces new ... */
                                        warning(44, storage_class_name(scl),
@@ -2181,10 +2181,10 @@
 static bool
 qualifiers_correspond(const type_t *tp1, const type_t *tp2, bool ignqual)
 {
-       if (tp1->t_const != tp2->t_const && !ignqual && !tflag)
+       if (tp1->t_const != tp2->t_const && !ignqual && allow_c90)
                return false;
 
-       if (tp1->t_volatile != tp2->t_volatile && !ignqual && !tflag)
+       if (tp1->t_volatile != tp2->t_volatile && !ignqual && allow_c90)
                return false;
 
        return true;
@@ -2227,12 +2227,12 @@
                        } else if (t == CHAR || t == SCHAR) {
                                t = INT;
                        } else if (t == UCHAR) {
-                               t = tflag ? UINT : INT;
+                               t = allow_c90 ? INT : UINT;
                        } else if (t == SHORT) {
                                t = INT;
                        } else if (t == USHORT) {
                                /* CONSTCOND */
-                               t = TARG_INT_MAX < TARG_USHRT_MAX || tflag
+                               t = TARG_INT_MAX < TARG_USHRT_MAX || !allow_c90
                                    ? UINT : INT;
                        }
                }
@@ -2255,7 +2255,7 @@
                }
 
                /* don't check prototypes for traditional */
-               if (t == FUNC && !tflag) {
+               if (t == FUNC && allow_c90) {
                        if (tp1->t_proto && tp2->t_proto) {
                                if (!eqargs(tp1, tp2, dowarn))
                                        return false;
@@ -2468,12 +2468,12 @@
        if ((t = sym->s_type->t_tspec) == ARRAY) {
                sym->s_type = block_derive_type(sym->s_type->t_subt, PTR);
        } else if (t == FUNC) {
-               if (tflag)
+               if (!allow_c90)
                        /* a function is declared as an argument: %s */
                        warning(50, sym->s_name);
                sym->s_type = block_derive_type(sym->s_type, PTR);
        } else if (t == FLOAT) {
-               if (tflag)
+               if (!allow_c90)
                        sym->s_type = gettyp(DOUBLE);
        }
 
@@ -2704,10 +2704,10 @@
                /* no hflag, because it's illegal! */
                if (rsym->s_arg) {
                        /*
-                        * if !tflag, a "redeclaration of %s" error
+                        * if allow_c90, a "redeclaration of %s" error
                         * is produced below
                         */
-                       if (tflag) {
+                       if (!allow_c90) {
                                if (hflag)
                                        /* declaration hides parameter: %s */
                                        warning(91, dsym->s_name);
@@ -2758,7 +2758,7 @@
         * functions may be declared inline at local scope, although
         * this has no effect for a later definition of the same
         * function.
-        * XXX it should have an effect if tflag is set. this would
+        * XXX it should have an effect if !allow_c90 is set. this would
         * also be the way gcc behaves.
         */
        if (dcs->d_inline) {
@@ -2983,7 +2983,7 @@
 
        if (length_in_bits(dsym->s_type, dsym->s_name) == 0 &&
            dsym->s_type->t_tspec == ARRAY && dsym->s_type->t_dim == 0) {
-               if (tflag) {
+               if (!allow_c90) {
                        /* empty array declaration: %s */
                        warning(190, dsym->s_name);
                } else {
@@ -3261,7 +3261,7 @@
        if (!sym->s_used)
                check_unused_static_global_variable(sym);
 
-       if (!tflag && sym->s_def == TDEF && sym->s_type->t_const) {
+       if (allow_c90 && sym->s_def == TDEF && sym->s_type->t_const) {
                /* const object %s should have initializer */
                warning_at(227, &sym->s_def_pos, sym->s_name);
        }
@@ -3311,7 +3311,7 @@
 
        if (len_in_bits == 0 &&
            sym->s_type->t_tspec == ARRAY && sym->s_type->t_dim == 0) {
-               if (tflag || (sym->s_scl == EXTERN && !sflag)) {
+               if (!allow_c90 || (sym->s_scl == EXTERN && !sflag)) {
                        /* empty array declaration: %s */
                        warning_at(190, &sym->s_def_pos, sym->s_name);
                } else {
diff -r 0367ed364b47 -r c42884ecf4ab usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sat Apr 30 20:43:16 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sat Apr 30 21:38:03 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.158 2022/04/30 20:24:57 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.159 2022/04/30 21:38:03 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -60,13 +60,12 @@
  * 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 tflag and sflag suspicious.
+ * 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 tflag  (allow_trad && !allow_c90)
 #define sflag  (!allow_trad && !allow_c99)
 
 extern void    norecover(void);
diff -r 0367ed364b47 -r c42884ecf4ab usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Apr 30 20:43:16 2022 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Apr 30 21:38:03 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.133 2022/04/30 19:18:48 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.134 2022/04/30 21:38:03 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index