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: allow system headers to use int as...
details: https://anonhg.NetBSD.org/src/rev/7fa1b2ddfb42
branches: trunk
changeset: 949840:7fa1b2ddfb42
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 17 23:04:09 2021 +0000
description:
lint: allow system headers to use int as bool, even in strict bool mode
diffstat:
tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c | 4 +-
tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp | 1 -
usr.bin/xlint/lint1/externs1.h | 3 +-
usr.bin/xlint/lint1/scan.l | 36 ++++++++++++++----
usr.bin/xlint/lint1/tree.c | 24 +++++++++---
5 files changed, 50 insertions(+), 18 deletions(-)
diffs (185 lines):
diff -r d0e27faceb98 -r 7fa1b2ddfb42 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c Sun Jan 17 23:00:41 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c Sun Jan 17 23:04:09 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_bool_strict_syshdr.c,v 1.1 2021/01/17 23:00:41 rillig Exp $ */
+/* $NetBSD: d_c99_bool_strict_syshdr.c,v 1.2 2021/01/17 23:04:09 rillig Exp $ */
# 3 "d_c99_bool_strict_syshdr.c"
/*
@@ -26,7 +26,7 @@
# 27 "d_c99_bool_strict_syshdr.c" 3 4
do {
println("nothing");
- } while (/*CONSTCOND*/0); /*FIXME*//* expect: 333 */
+ } while (/*CONSTCOND*/0); /* ok */
# 32 "d_c99_bool_strict_syshdr.c"
do {
diff -r d0e27faceb98 -r 7fa1b2ddfb42 tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp Sun Jan 17 23:00:41 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp Sun Jan 17 23:04:09 2021 +0000
@@ -1,5 +1,4 @@
d_c99_bool_strict_syshdr.c(24): controlling expression must be bool, not 'int' [333]
-d_c99_bool_strict_syshdr.c(29): controlling expression must be bool, not 'int' [333]
d_c99_bool_strict_syshdr.c(34): controlling expression must be bool, not 'int' [333]
d_c99_bool_strict_syshdr.c(71): operands of '=' have incompatible types (_Bool != int) [107]
d_c99_bool_strict_syshdr.c(77): operands of '=' have incompatible types (int != _Bool) [107]
diff -r d0e27faceb98 -r 7fa1b2ddfb42 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Sun Jan 17 23:00:41 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Sun Jan 17 23:04:09 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.57 2021/01/17 15:40:27 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.58 2021/01/17 23:04:09 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -71,6 +71,7 @@
extern bool attron;
extern pos_t curr_pos;
extern pos_t csrc_pos;
+extern bool in_system_header;
extern symt_t symtyp;
extern FILE *yyin;
extern uint64_t qbmasks[], qlmasks[], qumasks[];
diff -r d0e27faceb98 -r 7fa1b2ddfb42 usr.bin/xlint/lint1/scan.l
--- a/usr.bin/xlint/lint1/scan.l Sun Jan 17 23:00:41 2021 +0000
+++ b/usr.bin/xlint/lint1/scan.l Sun Jan 17 23:04:09 2021 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: scan.l,v 1.120 2021/01/17 15:09:56 rillig Exp $ */
+/* $NetBSD: scan.l,v 1.121 2021/01/17 23:04:09 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.120 2021/01/17 15:09:56 rillig Exp $");
+__RCSID("$NetBSD: scan.l,v 1.121 2021/01/17 23:04:09 rillig Exp $");
#endif
#include <ctype.h>
@@ -63,6 +63,8 @@
/* Are we parsing a gcc attribute? */
bool attron;
+bool in_system_header = false;
+
static void incline(void);
static void badchar(int);
static sbuf_t *allocsb(void);
@@ -1115,6 +1117,29 @@
return c;
}
+/* See https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html */
+static void
+parse_line_directive_flags(const char *p)
+{
+
+ in_system_header = false;
+
+ while (ch_isspace(*p))
+ p++;
+ while (ch_isdigit(*p)) {
+ if (*p == '3' && !ch_isdigit(p[1]))
+ in_system_header = true;
+ p++;
+ while (ch_isspace(*p))
+ p++;
+ }
+
+#if 0
+ if (c != '\0')
+ warning("extra character(s) after directive");
+#endif
+}
+
/*
* Called for preprocessor directives. Currently implemented are:
* # lineno
@@ -1158,12 +1183,7 @@
goto error;
if ((fnl = cp++ - fn) > PATH_MAX)
goto error;
- while ((c = *cp++) == ' ' || c == '\t')
- continue;
-#if 0
- if (c != '\0')
- warning("extra character(s) after directive");
-#endif
+ parse_line_directive_flags(cp);
/* empty string means stdin */
if (fnl == 0) {
diff -r d0e27faceb98 -r 7fa1b2ddfb42 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Jan 17 23:00:41 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Jan 17 23:04:09 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.180 2021/01/17 17:16:47 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.181 2021/01/17 23:04:09 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.180 2021/01/17 17:16:47 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.181 2021/01/17 23:04:09 rillig Exp $");
#endif
#include <float.h>
@@ -723,6 +723,15 @@
return tn;
}
+static bool
+is_bool_compatible(tspec_t t, const tnode_t *tn)
+{
+ if (t == BOOL)
+ return true;
+ return in_system_header && t == INT && tn->tn_op == CON &&
+ (tn->tn_val->v_quad == 0 || tn->tn_val->v_quad == 1);
+}
+
/* In strict bool mode, see if the node's type is compatible with bool. */
bool
is_strict_bool(const tnode_t *tn)
@@ -732,7 +741,7 @@
tn = before_conversion(tn);
t = tn->tn_type->t_tspec;
- if (t == BOOL)
+ if (is_bool_compatible(t, tn))
return true;
/* For enums that are used as bit sets, allow "flags & FLAG". */
@@ -1115,11 +1124,14 @@
* behavior.
*/
static bool
-typeok_strict_bool_compatible(op_t op, int arg, tspec_t lt, tspec_t rt)
+typeok_strict_bool_compatible(op_t op, int arg,
+ const tnode_t *ln, tspec_t lt,
+ const tnode_t *rn, tspec_t rt)
{
+
if (!needs_compatible_types(op))
return true;
- if ((lt == BOOL) == (rt == BOOL))
+ if (is_bool_compatible(lt, ln) == is_bool_compatible(rt, rn))
return true;
if (op == FARG) {
@@ -1158,7 +1170,7 @@
rt = NOTSPEC;
}
- if (!typeok_strict_bool_compatible(op, arg, lt, rt))
+ if (!typeok_strict_bool_compatible(op, arg, ln, lt, rn, rt))
return false;
if (mp->m_requires_bool || op == QUEST) {
Home |
Main Index |
Thread Index |
Old Index