summaryrefslogtreecommitdiff
path: root/usr.bin/xlint
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-07-07 06:03:31 +0000
committerrillig <rillig@NetBSD.org>2023-07-07 06:03:31 +0000
commitf260bdb92f361d3b4e3ab9d23e5f0eb4faafd698 (patch)
treeab7115a0d2c19d8f3c540e8afc852a7403b759f7 /usr.bin/xlint
parenteed2e1f5f354b83b1e2723c0412ffdf22f00d4e8 (diff)
lint: only skip 'unused' warnings after errors, not other warnings
Previously, in -w mode, any warning suppressed further 'unused' warnings, even though there was no need to do that. This can be seen in the test gcc_attribute_var.c, where only the last unused variable from a function was marked as unused, the others slipped through. Fixed by counting the errors and the warnings separately and only combining them if actually desired.
Diffstat (limited to 'usr.bin/xlint')
-rw-r--r--usr.bin/xlint/lint1/decl.c6
-rw-r--r--usr.bin/xlint/lint1/err.c13
-rw-r--r--usr.bin/xlint/lint1/externs1.h5
-rw-r--r--usr.bin/xlint/lint1/main1.c6
-rw-r--r--usr.bin/xlint/lint1/tree.c6
5 files changed, 18 insertions, 18 deletions
diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c
index 55fbb025402..03ae41acc9c 100644
--- a/usr.bin/xlint/lint1/decl.c
+++ b/usr.bin/xlint/lint1/decl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.341 2023/07/03 10:23:12 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.342 2023/07/07 06:03:31 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.341 2023/07/03 10:23:12 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.342 2023/07/07 06:03:31 rillig Exp $");
#endif
#include <sys/param.h>
@@ -2935,7 +2935,7 @@ check_variable_usage(bool novar, sym_t *sym)
return;
/* errors in expressions easily cause lots of these warnings */
- if (nerr != 0)
+ if (seen_error)
return;
/*
diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c
index db6a1891e09..4a009cee293 100644
--- a/usr.bin/xlint/lint1/err.c
+++ b/usr.bin/xlint/lint1/err.c
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.204 2023/07/02 23:40:23 rillig Exp $ */
+/* $NetBSD: err.c,v 1.205 2023/07/07 06:03:31 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.204 2023/07/02 23:40:23 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.205 2023/07/07 06:03:31 rillig Exp $");
#endif
#include <limits.h>
@@ -47,8 +47,8 @@ __RCSID("$NetBSD: err.c,v 1.204 2023/07/02 23:40:23 rillig Exp $");
#include "lint1.h"
-/* number of errors found */
-int nerr;
+bool seen_error;
+bool seen_warning;
/* number of syntax errors */
int sytxerr;
@@ -529,7 +529,7 @@ verror_at(int msgid, const pos_t *pos, va_list ap)
(void)printf("%s(%d): error: ", fn, pos->p_line);
(void)vprintf(msgs[msgid], ap);
(void)printf(" [%d]\n", msgid);
- nerr++;
+ seen_error = true;
print_stack_trace();
}
@@ -550,8 +550,7 @@ vwarning_at(int msgid, const pos_t *pos, va_list ap)
(void)printf("%s(%d): warning: ", fn, pos->p_line);
(void)vprintf(msgs[msgid], ap);
(void)printf(" [%d]\n", msgid);
- if (wflag)
- nerr++;
+ seen_warning = true;
print_stack_trace();
}
diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h
index 712b7a4dc32..66924a1395f 100644
--- a/usr.bin/xlint/lint1/externs1.h
+++ b/usr.bin/xlint/lint1/externs1.h
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.188 2023/07/02 23:40:23 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.189 2023/07/07 06:03:31 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -156,7 +156,8 @@ void debug_leave_func(const char *);
/*
* err.c
*/
-extern int nerr;
+extern bool seen_error;
+extern bool seen_warning;
extern int sytxerr;
extern bool any_query_enabled;
diff --git a/usr.bin/xlint/lint1/main1.c b/usr.bin/xlint/lint1/main1.c
index c115ebef102..c5be6198dd9 100644
--- a/usr.bin/xlint/lint1/main1.c
+++ b/usr.bin/xlint/lint1/main1.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main1.c,v 1.71 2023/07/03 11:16:32 rillig Exp $ */
+/* $NetBSD: main1.c,v 1.72 2023/07/07 06:03:31 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: main1.c,v 1.71 2023/07/03 11:16:32 rillig Exp $");
+__RCSID("$NetBSD: main1.c,v 1.72 2023/07/07 06:03:31 rillig Exp $");
#endif
#include <sys/types.h>
@@ -258,7 +258,7 @@ main(int argc, char *argv[])
outclose();
- return nerr != 0 ? 1 : 0;
+ return seen_error || (wflag && seen_warning) ? 1 : 0;
}
static void __attribute__((noreturn))
diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c
index c86812ec726..5eaefd5f87e 100644
--- a/usr.bin/xlint/lint1/tree.c
+++ b/usr.bin/xlint/lint1/tree.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.547 2023/07/03 21:36:16 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.548 2023/07/07 06:03:31 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.547 2023/07/03 21:36:16 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.548 2023/07/07 06:03:31 rillig Exp $");
#endif
#include <float.h>
@@ -4336,7 +4336,7 @@ integer_constant(tnode_t *tn, bool required)
val_t *v = xcalloc(1, sizeof(*v));
if (tn == NULL) {
- lint_assert(nerr != 0);
+ lint_assert(seen_error);
debug_step("constant node is null; returning 1 instead");
v->v_tspec = INT;
v->u.integer = 1;