Module Name: src Committed By: rillig Date: Mon Oct 14 18:43:24 UTC 2024
Modified Files: src/tests/usr.bin/xlint/lint1: msg_086.c msg_087.c msg_088.c src/usr.bin/xlint/lint1: decl.c err.c Log Message: lint: add more details to messages about hidden symbols To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_086.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_087.c \ src/tests/usr.bin/xlint/lint1/msg_088.c cvs rdiff -u -r1.405 -r1.406 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.249 -r1.250 src/usr.bin/xlint/lint1/err.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_086.c diff -u src/tests/usr.bin/xlint/lint1/msg_086.c:1.7 src/tests/usr.bin/xlint/lint1/msg_086.c:1.8 --- src/tests/usr.bin/xlint/lint1/msg_086.c:1.7 Wed Aug 2 18:51:25 2023 +++ src/tests/usr.bin/xlint/lint1/msg_086.c Mon Oct 14 18:43:24 2024 @@ -1,23 +1,26 @@ -/* $NetBSD: msg_086.c,v 1.7 2023/08/02 18:51:25 rillig Exp $ */ +/* $NetBSD: msg_086.c,v 1.8 2024/10/14 18:43:24 rillig Exp $ */ # 3 "msg_086.c" -// Test for message: automatic '%s' hides external declaration [86] +// Test for message: automatic '%s' hides external declaration with type '%s' [86] /* lint1-flags: -S -g -h -w -X 351 */ -extern int identifier; +extern double variable; +void parameter(double); +void err(int, const char *, ...); -int -local_auto(void) -{ - /* expect+1: warning: automatic 'identifier' hides external declaration [86] */ - int identifier = 3; - return identifier; -} +int sink; +void /* XXX: the function parameter does not trigger the warning. */ -int -arg_auto(int identifier) +local_(int parameter) { - return identifier; + /* expect+1: warning: automatic 'variable' hides external declaration with type 'double' [86] */ + int variable = 3; + /* expect+1: warning: automatic 'err' hides external declaration with type 'function(int, pointer to const char, ...) returning void' [86] */ + int err = 5; + + sink = variable; + sink = parameter; + sink = err; } Index: src/tests/usr.bin/xlint/lint1/msg_087.c diff -u src/tests/usr.bin/xlint/lint1/msg_087.c:1.6 src/tests/usr.bin/xlint/lint1/msg_087.c:1.7 --- src/tests/usr.bin/xlint/lint1/msg_087.c:1.6 Tue Mar 28 14:44:34 2023 +++ src/tests/usr.bin/xlint/lint1/msg_087.c Mon Oct 14 18:43:24 2024 @@ -1,16 +1,16 @@ -/* $NetBSD: msg_087.c,v 1.6 2023/03/28 14:44:34 rillig Exp $ */ +/* $NetBSD: msg_087.c,v 1.7 2024/10/14 18:43:24 rillig Exp $ */ # 3 "msg_087.c" -// Test for message: static '%s' hides external declaration [87] +// Test for message: static '%s' hides external declaration with type '%s' [87] /* lint1-flags: -g -h -S -w -X 351 */ -extern int counter; +extern long counter; int count(void) { - /* expect+1: warning: static 'counter' hides external declaration [87] */ + /* expect+1: warning: static 'counter' hides external declaration with type 'long' [87] */ static int counter; return counter++; } Index: src/tests/usr.bin/xlint/lint1/msg_088.c diff -u src/tests/usr.bin/xlint/lint1/msg_088.c:1.6 src/tests/usr.bin/xlint/lint1/msg_088.c:1.7 --- src/tests/usr.bin/xlint/lint1/msg_088.c:1.6 Tue Mar 28 14:44:34 2023 +++ src/tests/usr.bin/xlint/lint1/msg_088.c Mon Oct 14 18:43:24 2024 @@ -1,7 +1,7 @@ -/* $NetBSD: msg_088.c,v 1.6 2023/03/28 14:44:34 rillig Exp $ */ +/* $NetBSD: msg_088.c,v 1.7 2024/10/14 18:43:24 rillig Exp $ */ # 3 "msg_088.c" -// Test for message: typedef '%s' hides external declaration [88] +// Test for message: typedef '%s' hides external declaration with type '%s' [88] /* lint1-flags: -g -h -S -w -X 351 */ @@ -10,6 +10,6 @@ extern int identifier; void func(void) { - /* expect+1: warning: typedef 'identifier' hides external declaration [88] */ + /* expect+1: warning: typedef 'identifier' hides external declaration with type 'int' [88] */ typedef double identifier; } Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.405 src/usr.bin/xlint/lint1/decl.c:1.406 --- src/usr.bin/xlint/lint1/decl.c:1.405 Sat Sep 28 15:51:40 2024 +++ src/usr.bin/xlint/lint1/decl.c Mon Oct 14 18:43:23 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.405 2024/09/28 15:51:40 rillig Exp $ */ +/* $NetBSD: decl.c,v 1.406 2024/10/14 18:43:23 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.405 2024/09/28 15:51:40 rillig Exp $"); +__RCSID("$NetBSD: decl.c,v 1.406 2024/10/14 18:43:23 rillig Exp $"); #endif #include <sys/param.h> @@ -2538,20 +2538,20 @@ check_func_old_style_parameters(void) } static void -check_local_hiding(const sym_t *dsym) +check_local_hiding(const sym_t *dsym, const sym_t *rdsym) { switch (dsym->s_scl) { case AUTO: - /* automatic '%s' hides external declaration */ - warning(86, dsym->s_name); + /* automatic '%s' hides external declaration with type '%s' */ + warning(86, dsym->s_name, type_name(rdsym->s_type)); break; case STATIC: - /* static '%s' hides external declaration */ - warning(87, dsym->s_name); + /* static '%s' hides external declaration with type '%s' */ + warning(87, dsym->s_name, type_name(rdsym->s_type)); break; case TYPEDEF: - /* typedef '%s' hides external declaration */ - warning(88, dsym->s_name); + /* typedef '%s' hides external declaration with type '%s' */ + warning(88, dsym->s_name, type_name(rdsym->s_type)); break; case EXTERN: /* Already checked in declare_external_in_block. */ @@ -2566,7 +2566,7 @@ check_local_redeclaration(const sym_t *d { if (rdsym->s_block_level == 0) { if (hflag) - check_local_hiding(dsym); + check_local_hiding(dsym, rdsym); } else if (rdsym->s_block_level == block_level) { Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.249 src/usr.bin/xlint/lint1/err.c:1.250 --- src/usr.bin/xlint/lint1/err.c:1.249 Sun Sep 29 13:16:57 2024 +++ src/usr.bin/xlint/lint1/err.c Mon Oct 14 18:43:23 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.249 2024/09/29 13:16:57 rillig Exp $ */ +/* $NetBSD: err.c,v 1.250 2024/10/14 18:43:23 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: err.c,v 1.249 2024/09/29 13:16:57 rillig Exp $"); +__RCSID("$NetBSD: err.c,v 1.250 2024/10/14 18:43:23 rillig Exp $"); #endif #include <limits.h> @@ -141,9 +141,9 @@ static const char *const msgs[] = { "storage class after type is obsolescent", // 83 "C90 to C17 require formal parameter before '...'", // 84 "dubious tag declaration '%s %s'", // 85 - "automatic '%s' hides external declaration", // 86 - "static '%s' hides external declaration", // 87 - "typedef '%s' hides external declaration", // 88 + "automatic '%s' hides external declaration with type '%s'", // 86 + "static '%s' hides external declaration with type '%s'", // 87 + "typedef '%s' hides external declaration with type '%s'", // 88 "typedef '%s' redeclared", // 89 "inconsistent redeclaration of extern '%s'", // 90 "declaration of '%s' hides parameter", // 91