Module Name: src Committed By: rillig Date: Sun Aug 28 19:09:12 UTC 2022
Modified Files: src/usr.bin/xlint/lint1: decl.c externs1.h func.c tree.c Log Message: lint: inline previous_declaration for nonconstant message IDs This adds back the compile-time printf validation in debug mode that was missing before. To generate a diff of this commit: cvs rdiff -u -r1.298 -r1.299 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.168 -r1.169 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.143 -r1.144 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.479 -r1.480 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.298 src/usr.bin/xlint/lint1/decl.c:1.299 --- src/usr.bin/xlint/lint1/decl.c:1.298 Sun Aug 28 12:04:47 2022 +++ src/usr.bin/xlint/lint1/decl.c Sun Aug 28 19:09:12 2022 @@ -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 @@ new_tag(sym_t *tag, scl_t scl, bool decl /* %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 @@ enumeration_constant(sym_t *sym, int val * previous declaration */ if (block_level == 0) - print_previous_declaration(-1, sym); + print_previous_declaration(sym); } } else { if (hflag) @@ -1993,7 +1993,7 @@ declare_extern(sym_t *dsym, bool initflg else /* redeclaration of '%s' */ warning(27, dsym->s_name); - print_previous_declaration(-1, rdsym); + print_previous_declaration(rdsym); } /* @@ -2085,32 +2085,32 @@ check_redeclaration(sym_t *dsym, bool *d 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 @@ check_redeclaration(sym_t *dsym, bool *d */ /* 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 @@ check_redeclaration(sym_t *dsym, bool *d 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 @@ check_old_style_definition(sym_t *rdsym, } 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 @@ check_func_old_style_arguments(void) 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 @@ declare_external_in_block(sym_t *dsym) /* 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 @@ declare_external_in_block(sym_t *dsym) 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 @@ check_global_variable_size(const sym_t * * 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 { Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.168 src/usr.bin/xlint/lint1/externs1.h:1.169 --- src/usr.bin/xlint/lint1/externs1.h:1.168 Sun Aug 28 12:04:47 2022 +++ src/usr.bin/xlint/lint1/externs1.h Sun Aug 28 19:09:12 2022 @@ -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 mark_as_used(sym_t *, bool, 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); /* Index: src/usr.bin/xlint/lint1/func.c diff -u src/usr.bin/xlint/lint1/func.c:1.143 src/usr.bin/xlint/lint1/func.c:1.144 --- src/usr.bin/xlint/lint1/func.c:1.143 Sun Jul 3 07:33:08 2022 +++ src/usr.bin/xlint/lint1/func.c Sun Aug 28 19:09:12 2022 @@ -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 @@ funcdef(sym_t *fsym) else /* redeclaration of '%s' */ warning(27, fsym->s_name); - print_previous_declaration(-1, rdsym); + print_previous_declaration(rdsym); } copy_usage_info(fsym, rdsym); Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.479 src/usr.bin/xlint/lint1/tree.c:1.480 --- src/usr.bin/xlint/lint1/tree.c:1.479 Sun Aug 28 12:04:47 2022 +++ src/usr.bin/xlint/lint1/tree.c Sun Aug 28 19:09:12 2022 @@ -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 @@ check_enum_array_index(const tnode_t *ln /* 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); } /*