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 previous_declaration for no...



details:   https://anonhg.NetBSD.org/src/rev/5fc5868ec788
branches:  trunk
changeset: 369715:5fc5868ec788
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 28 19:09:12 2022 +0000

description:
lint: inline previous_declaration for nonconstant message IDs

This adds back the compile-time printf validation in debug mode that was
missing before.

diffstat:

 usr.bin/xlint/lint1/decl.c     |  49 +++++++++++++++++++----------------------
 usr.bin/xlint/lint1/externs1.h |   4 +-
 usr.bin/xlint/lint1/func.c     |   6 ++--
 usr.bin/xlint/lint1/tree.c     |   6 ++--
 4 files changed, 31 insertions(+), 34 deletions(-)

diffs (248 lines):

diff -r 24a4d142f8da -r 5fc5868ec788 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Aug 28 16:07:58 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Aug 28 19:09:12 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.298 2022/08/28 12:04:47 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.299 2022/08/28 19:09:12 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.298 2022/08/28 12:04:47 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.299 2022/08/28 19:09:12 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1780,7 +1780,7 @@
                        /* %s tag '%s' redeclared as %s */
                        error(46, storage_class_name(tag->s_scl),
                            tag->s_name, storage_class_name(scl));
-                       print_previous_declaration(-1, tag);
+                       print_previous_declaration(tag);
                        tag = pushdown(tag);
                        dcs->d_enclosing->d_nonempty_decl = true;
                } else if (semi || decl)
@@ -1896,7 +1896,7 @@
                                 * previous declaration
                                 */
                                if (block_level == 0)
-                                       print_previous_declaration(-1, sym);
+                                       print_previous_declaration(sym);
                        }
                } else {
                        if (hflag)
@@ -1993,7 +1993,7 @@
                                else
                                        /* redeclaration of '%s' */
                                        warning(27, dsym->s_name);
-                               print_previous_declaration(-1, rdsym);
+                               print_previous_declaration(rdsym);
                        }
 
                        /*
@@ -2085,32 +2085,32 @@
        if (rsym->s_scl == ENUM_CONST) {
                /* redeclaration of '%s' */
                error(27, dsym->s_name);
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
                return true;
        }
        if (rsym->s_scl == TYPEDEF) {
                /* typedef '%s' redeclared */
                error(89, dsym->s_name);
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
                return true;
        }
        if (dsym->s_scl == TYPEDEF) {
                /* redeclaration of '%s' */
                error(27, dsym->s_name);
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
                return true;
        }
        if (rsym->s_def == DEF && dsym->s_def == DEF) {
                /* redefinition of '%s' */
                error(28, dsym->s_name);
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
                return true;
        }
        if (!types_compatible(rsym->s_type, dsym->s_type, false, false, dowarn)) {
                /* redeclaration of '%s' with type '%s', expected '%s' */
                error(347, dsym->s_name,
                    type_name(dsym->s_type), type_name(rsym->s_type));
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
                return true;
        }
        if (rsym->s_scl == EXTERN && dsym->s_scl == EXTERN)
@@ -2126,13 +2126,13 @@
                 */
                /* redeclaration of '%s' */
                error(27, dsym->s_name);
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
                return true;
        }
        if (rsym->s_scl == EXTERN) {
                /* '%s' was previously declared extern, becomes static */
                warning(29, dsym->s_name);
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
                return false;
        }
        /*
@@ -2143,7 +2143,7 @@
        if (!allow_trad && !allow_c99) {
                /* redeclaration of '%s'; ANSI C requires static */
                warning(30, dsym->s_name);
-               print_previous_declaration(-1, rsym);
+               print_previous_declaration(rsym);
        }
        dsym->s_scl = STATIC;
        return false;
@@ -2337,9 +2337,10 @@
        }
 
 end:
-       if (msg)
+       if (msg && rflag) {
                /* old style definition */
-               print_previous_declaration(300, rdsym);
+               message_at(300, &rdsym->s_def_pos);
+       }
 
        return msg;
 }
@@ -2577,10 +2578,9 @@
                                arg = arg->s_next;
                        }
                }
-               if (msg) {
+               if (msg && rflag) {
                        /* prototype declaration */
-                       print_previous_declaration(285,
-                           dcs->d_redeclared_symbol);
+                       message_at(285, &dcs->d_redeclared_symbol->s_def_pos);
                }
 
                /* from now on the prototype is valid */
@@ -2793,7 +2793,7 @@
                /* gcc accepts this without a warning, pcc prints an error. */
                /* redeclaration of '%s' */
                warning(27, dsym->s_name);
-               print_previous_declaration(-1, esym);
+               print_previous_declaration(esym);
                return;
        }
 
@@ -2805,11 +2805,11 @@
                if (esym->s_scl == EXTERN) {
                        /* inconsistent redeclaration of extern '%s' */
                        warning(90, dsym->s_name);
-                       print_previous_declaration(-1, esym);
+                       print_previous_declaration(esym);
                } else {
                        /* inconsistent redeclaration of static '%s' */
                        warning(92, dsym->s_name);
-                       print_previous_declaration(-1, esym);
+                       print_previous_declaration(esym);
                }
        }
 
@@ -3280,16 +3280,13 @@
  * Prints information about location of previous definition/declaration.
  */
 void
-print_previous_declaration(int msg, const sym_t *psym)
+print_previous_declaration(const sym_t *psym)
 {
 
        if (!rflag)
                return;
 
-       if (msg != -1) {
-               /* TODO: inline these cases. */
-               (message_at)(msg, &psym->s_def_pos);
-       } else if (psym->s_def == DEF || psym->s_def == TDEF) {
+       if (psym->s_def == DEF || psym->s_def == TDEF) {
                /* previous definition of '%s' */
                message_at(261, &psym->s_def_pos, psym->s_name);
        } else {
diff -r 24a4d142f8da -r 5fc5868ec788 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sun Aug 28 16:07:58 2022 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sun Aug 28 19:09:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.168 2022/08/28 12:04:47 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.169 2022/08/28 19:09:12 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -239,7 +239,7 @@
 extern void    check_usage(dinfo_t *);
 extern void    check_usage_sym(bool, sym_t *);
 extern void    check_global_symbols(void);
-extern void    print_previous_declaration(int, const sym_t *);
+extern void    print_previous_declaration(const sym_t *);
 extern int     to_int_constant(tnode_t *, bool);
 
 /*
diff -r 24a4d142f8da -r 5fc5868ec788 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sun Aug 28 16:07:58 2022 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sun Aug 28 19:09:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.143 2022/07/03 07:33:08 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.144 2022/08/28 19:09:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.143 2022/07/03 07:33:08 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.144 2022/08/28 19:09:12 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -315,7 +315,7 @@
                                else
                                        /* redeclaration of '%s' */
                                        warning(27, fsym->s_name);
-                               print_previous_declaration(-1, rdsym);
+                               print_previous_declaration(rdsym);
                        }
 
                        copy_usage_info(fsym, rdsym);
diff -r 24a4d142f8da -r 5fc5868ec788 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Aug 28 16:07:58 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Aug 28 19:09:12 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.479 2022/08/28 12:04:47 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.480 2022/08/28 19:09:12 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.479 2022/08/28 12:04:47 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.480 2022/08/28 19:09:12 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -2069,7 +2069,7 @@
 
        /* maximum value %d of '%s' does not match maximum array index %d */
        warning(348, (int)max_enum_value, type_name(rt), max_array_index);
-       print_previous_declaration(-1, max_ec);
+       print_previous_declaration(max_ec);
 }
 
 /*



Home | Main Index | Thread Index | Old Index