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: in strict bool mode, allow mixed t...
details: https://anonhg.NetBSD.org/src/rev/b131cd4a9d3a
branches: trunk
changeset: 984346:b131cd4a9d3a
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jul 04 09:13:59 2021 +0000
description:
lint: in strict bool mode, allow mixed types in generated C code
This allows flex lexers to be run through lint in strict bool mode.
diffstat:
usr.bin/xlint/lint1/Makefile | 3 +--
usr.bin/xlint/lint1/ckbool.c | 11 +++++------
usr.bin/xlint/lint1/lint1.h | 7 +++++--
usr.bin/xlint/lint1/mem1.c | 23 ++++++++++++++++++++---
usr.bin/xlint/lint1/tree.c | 14 +++++++-------
5 files changed, 38 insertions(+), 20 deletions(-)
diffs (174 lines):
diff -r 2157f126e658 -r b131cd4a9d3a usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile Sun Jul 04 08:50:26 2021 +0000
+++ b/usr.bin/xlint/lint1/Makefile Sun Jul 04 09:13:59 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.76 2021/07/04 08:49:41 rillig Exp $
+# $NetBSD: Makefile,v 1.77 2021/07/04 09:13:59 rillig Exp $
.include <bsd.own.mk>
@@ -19,7 +19,6 @@
LINTFLAGS+= -T
LOBJS.${PROG}+= ${SRCS:M*.y:.y=.ln}
LOBJS.${PROG}+= ${SRCS:M*.l:.l=.ln}
-LINTFLAGS.scan.c= -X 107,126,330,331,332,333
CPPFLAGS+= -DIS_LINT1
CPPFLAGS+= -I${.CURDIR}
diff -r 2157f126e658 -r b131cd4a9d3a usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c Sun Jul 04 08:50:26 2021 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c Sun Jul 04 09:13:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.6 2021/07/02 21:22:26 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.7 2021/07/04 09:13:59 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckbool.c,v 1.6 2021/07/02 21:22:26 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.7 2021/07/04 09:13:59 rillig Exp $");
#endif
#include <string.h>
@@ -89,13 +89,12 @@
if ((lt == BOOL) == (rt == BOOL))
return true;
- if ((ln->tn_from_system_header || rn->tn_from_system_header) &&
+ if ((ln->tn_relaxed || rn->tn_relaxed) &&
(is_int_constant_zero(ln, lt) || is_int_constant_zero(rn, rt)))
return true;
if (is_assignment_bool_or_other(op)) {
- return lt != BOOL &&
- (ln->tn_from_system_header || rn->tn_from_system_header);
+ return lt != BOOL && (ln->tn_relaxed || rn->tn_relaxed);
}
return !is_symmetric_bool_or_other(op);
@@ -223,7 +222,7 @@
if (t == BOOL)
return true;
- if (tn->tn_from_system_header && is_scalar(t))
+ if (tn->tn_relaxed && is_scalar(t))
return true;
/* For enums that are used as bit sets, allow "flags & FLAG". */
diff -r 2157f126e658 -r b131cd4a9d3a usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h Sun Jul 04 08:50:26 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h Sun Jul 04 09:13:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.109 2021/07/02 18:22:09 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.110 2021/07/04 09:13:59 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -306,7 +306,10 @@
bool tn_lvalue : 1; /* node is lvalue */
bool tn_cast : 1; /* if tn_op == CVT, it's an explicit cast */
bool tn_parenthesized : 1;
- bool tn_from_system_header : 1;
+ bool tn_relaxed : 1; /* in strict bool mode, allow mixture between
+ * bool and scalar, for backwards
+ * compatibility
+ */
bool tn_system_dependent : 1; /* depends on sizeof or offsetof */
union {
struct {
diff -r 2157f126e658 -r b131cd4a9d3a usr.bin/xlint/lint1/mem1.c
--- a/usr.bin/xlint/lint1/mem1.c Sun Jul 04 08:50:26 2021 +0000
+++ b/usr.bin/xlint/lint1/mem1.c Sun Jul 04 09:13:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mem1.c,v 1.44 2021/06/20 18:51:50 rillig Exp $ */
+/* $NetBSD: mem1.c,v 1.45 2021/07/04 09:13:59 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: mem1.c,v 1.44 2021/06/20 18:51:50 rillig Exp $");
+__RCSID("$NetBSD: mem1.c,v 1.45 2021/07/04 09:13:59 rillig Exp $");
#endif
#include <sys/types.h>
@@ -346,6 +346,16 @@
return xgetblk(&tmblk, s);
}
+static bool
+str_endswith(const char *haystack, const char *needle)
+{
+ size_t hlen = strlen(haystack);
+ size_t nlen = strlen(needle);
+
+ return nlen <= hlen &&
+ memcmp(haystack + hlen - nlen, needle, nlen) == 0;
+}
+
/*
* Return a freshly allocated tree node that is freed at the end of the
* current expression.
@@ -354,7 +364,14 @@
expr_zalloc_tnode(void)
{
tnode_t *tn = expr_zalloc(sizeof(*tn));
- tn->tn_from_system_header = in_system_header;
+ /*
+ * files named *.c that are different from the main translation unit
+ * typically contain generated code that cannot be influenced, such
+ * as a flex lexer or a yacc parser.
+ */
+ tn->tn_relaxed = in_system_header ||
+ (curr_pos.p_file != csrc_pos.p_file &&
+ str_endswith(curr_pos.p_file, ".c"));
return tn;
}
diff -r 2157f126e658 -r b131cd4a9d3a usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Jul 04 08:50:26 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Jul 04 09:13:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.305 2021/07/04 08:19:06 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.306 2021/07/04 09:13:59 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.305 2021/07/04 08:19:06 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.306 2021/07/04 09:13:59 rillig Exp $");
#endif
#include <float.h>
@@ -1642,10 +1642,10 @@
ntn->tn_op = op;
ntn->tn_type = type;
- if (ln->tn_from_system_header)
- ntn->tn_from_system_header = true;
- if (rn != NULL && rn->tn_from_system_header)
- ntn->tn_from_system_header = true;
+ if (ln->tn_relaxed)
+ ntn->tn_relaxed = true;
+ if (rn != NULL && rn->tn_relaxed)
+ ntn->tn_relaxed = true;
ntn->tn_left = ln;
ntn->tn_right = rn;
@@ -1887,7 +1887,7 @@
ntn->tn_op = CVT;
ntn->tn_type = tp;
ntn->tn_cast = op == CVT;
- ntn->tn_from_system_header |= tn->tn_from_system_header;
+ ntn->tn_relaxed |= tn->tn_relaxed;
ntn->tn_right = NULL;
if (tn->tn_op != CON || nt == VOID) {
ntn->tn_left = tn;
Home |
Main Index |
Thread Index |
Old Index