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: add query for redundant 'extern' i...



details:   https://anonhg.NetBSD.org/src/rev/be7d03021972
branches:  trunk
changeset: 376609:be7d03021972
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 24 06:55:34 2023 +0000

description:
lint: add query for redundant 'extern' in function declaration

diffstat:

 tests/usr.bin/xlint/lint1/queries.c  |  12 +++++++++---
 tests/usr.bin/xlint/lint1/t_usage.sh |   8 ++++----
 usr.bin/xlint/lint1/decl.c           |  12 ++++++++++--
 usr.bin/xlint/lint1/err.c            |   5 +++--
 4 files changed, 26 insertions(+), 11 deletions(-)

diffs (125 lines):

diff -r f61c292e1e6b -r be7d03021972 tests/usr.bin/xlint/lint1/queries.c
--- a/tests/usr.bin/xlint/lint1/queries.c       Sat Jun 24 05:43:25 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/queries.c       Sat Jun 24 06:55:34 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: queries.c,v 1.15 2023/06/22 13:57:44 rillig Exp $      */
+/*     $NetBSD: queries.c,v 1.16 2023/06/24 06:55:34 rillig Exp $      */
 # 3 "queries.c"
 
 /*
@@ -15,7 +15,7 @@
  *     such as casts between arithmetic types.
  */
 
-/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12 -X 351 */
+/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13 -X 351 */
 
 typedef unsigned char u8_t;
 typedef unsigned short u16_t;
@@ -156,7 +156,7 @@ Q6(int i)
        i = (int)i + 1;
 }
 
-extern void *allocate(void);
+void *allocate(void);
 
 void
 Q7(void)
@@ -397,6 +397,12 @@ Q12(void)
        u16 += u8, u32 += u16;
 }
 
+/* expect+1: redundant 'extern' in function declaration of 'extern_Q13' [Q13] */
+extern void extern_Q13(void);
+void extern_Q13(void);
+/* expect+1: redundant 'extern' in function declaration of 'extern_Q13' [Q13] */
+extern void extern_Q13(void), *extern_ptr;
+
 /*
  * Since queries do not affect the exit status, force a warning to make this
  * test conform to the general expectation that a test that produces output
diff -r f61c292e1e6b -r be7d03021972 tests/usr.bin/xlint/lint1/t_usage.sh
--- a/tests/usr.bin/xlint/lint1/t_usage.sh      Sat Jun 24 05:43:25 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/t_usage.sh      Sat Jun 24 06:55:34 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_usage.sh,v 1.5 2023/06/22 13:57:44 rillig Exp $
+# $NetBSD: t_usage.sh,v 1.6 2023/06/24 06:55:34 rillig Exp $
 #
 # Copyright (c) 2023 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -97,13 +97,13 @@ enable_queries_body()
 
        # The largest known query.
        atf_check \
-           "$lint1" -q 12 code.c /dev/null
+           "$lint1" -q 13 code.c /dev/null
 
        # Larger than the largest known query.
        atf_check \
            -s 'exit:1' \
-           -e "inline:lint1: invalid query ID '13'\n" \
-           "$lint1" -q 13 code.c /dev/null
+           -e "inline:lint1: invalid query ID '14'\n" \
+           "$lint1" -q 14 code.c /dev/null
 
        # Whitespace is not allowed before a query ID.
        atf_check \
diff -r f61c292e1e6b -r be7d03021972 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Jun 24 05:43:25 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Jun 24 06:55:34 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.317 2023/06/09 15:36:31 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.318 2023/06/24 06:55:34 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.317 2023/06/09 15:36:31 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.318 2023/06/24 06:55:34 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1942,6 +1942,14 @@ check_extern_declaration(const sym_t *sy
                warning(351, sym->s_type->t_tspec == FUNC ? "" : " 'extern'",
                    sym->s_name);
        }
+       if (any_query_enabled &&
+           sym->s_type->t_tspec == FUNC &&
+           sym->s_scl == EXTERN &&
+           sym->s_def == DECL &&
+           !in_system_header) {
+               /* redundant 'extern' in function declaration of '%s' */
+               query_message(13, sym->s_name);
+       }
 }
 
 /* Process a single external or 'static' declarator. */
diff -r f61c292e1e6b -r be7d03021972 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Jun 24 05:43:25 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Jun 24 06:55:34 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.200 2023/06/22 13:57:44 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.201 2023/06/24 06:55:34 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.200 2023/06/22 13:57:44 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.201 2023/06/24 06:55:34 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -708,6 +708,7 @@ static const char *queries[] = {
        "chained assignment with '%s' and '%s'",                      /* Q10 */
        "static variable '%s' in function",                           /* Q11 */
        "comma operator with types '%s' and '%s'",                    /* Q12 */
+       "redundant 'extern' in function declaration of '%s'",         /* Q13 */
 };
 
 bool any_query_enabled;                /* for optimizing non-query scenarios */



Home | Main Index | Thread Index | Old Index