summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-07-07 19:45:22 +0000
committerrillig <rillig@NetBSD.org>2023-07-07 19:45:22 +0000
commit4175df945b048e5aeed932baf36d22ba89310121 (patch)
treeb9af2533f06e958404f3ad74e19b5786aa20dc89 /usr.bin
parentf0b07974431e15088bc38f5695ef7c1f9da599f8 (diff)
lint: warn about function definitions without header declaration
The existing warning was only issued for function declarations, not for function definitions. The interesting change in the tests is in msg_351.c. Many other tests use non-static functions due to their syntactic brevity. In these tests, the warning is disabled individually, to allow new functions to be added without generating warning 351.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/xlint/lint1/cgram.y5
-rw-r--r--usr.bin/xlint/lint1/decl.c10
-rw-r--r--usr.bin/xlint/lint1/externs1.h3
3 files changed, 11 insertions, 7 deletions
diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y
index 257de50c2fc..fbc85191f5f 100644
--- a/usr.bin/xlint/lint1/cgram.y
+++ b/usr.bin/xlint/lint1/cgram.y
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.446 2023/07/02 23:40:23 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.447 2023/07/07 19:45:22 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.446 2023/07/02 23:40:23 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.447 2023/07/07 19:45:22 rillig Exp $");
#endif
#include <limits.h>
@@ -1970,6 +1970,7 @@ function_definition: /* C99 6.9.1 */
error(64);
YYERROR;
}
+ check_extern_declaration($1);
begin_function($1);
block_level++;
begin_declaration_level(DLK_OLD_STYLE_ARGS);
diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c
index 03ae41acc9c..a154fa2862d 100644
--- a/usr.bin/xlint/lint1/decl.c
+++ b/usr.bin/xlint/lint1/decl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.342 2023/07/07 06:03:31 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.343 2023/07/07 19:45:22 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.342 2023/07/07 06:03:31 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.343 2023/07/07 19:45:22 rillig Exp $");
#endif
#include <sys/param.h>
@@ -1816,14 +1816,16 @@ ends_with(const char *s, const char *suffix)
memcmp(s + s_len - suffix_len, suffix, suffix_len) == 0;
}
-static void
+void
check_extern_declaration(const sym_t *sym)
{
if (sym->s_scl == EXTERN &&
dcs->d_redeclared_symbol == NULL &&
ends_with(curr_pos.p_file, ".c") &&
- !ch_isdigit(sym->s_name[0])) { /* see mktempsym */
+ allow_c90 &&
+ !ch_isdigit(sym->s_name[0]) && /* see mktempsym */
+ strcmp(sym->s_name, "main") != 0) {
/* missing%s header declaration for '%s' */
warning(351, sym->s_type->t_tspec == FUNC ? "" : " 'extern'",
sym->s_name);
diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h
index 66924a1395f..4ec20faaa3d 100644
--- a/usr.bin/xlint/lint1/externs1.h
+++ b/usr.bin/xlint/lint1/externs1.h
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.189 2023/07/07 06:03:31 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.190 2023/07/07 19:45:22 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -213,6 +213,7 @@ qual_ptr *merge_qualified_pointer(qual_ptr *, qual_ptr *);
sym_t *add_pointer(sym_t *, qual_ptr *);
sym_t *add_array(sym_t *, bool, int);
sym_t *add_function(sym_t *, sym_t *);
+void check_extern_declaration(const sym_t *);
void check_function_definition(sym_t *, bool);
sym_t *declarator_name(sym_t *);
sym_t *old_style_function_parameter_name(sym_t *);