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: merge almost duplicate code from '...
details: https://anonhg.NetBSD.org/src/rev/4285f23986b2
branches: trunk
changeset: 1022735:4285f23986b2
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Aug 03 21:09:26 2021 +0000
description:
lint: merge almost duplicate code from 'sametype' into 'eqtype'
In 'sametype', the branch for comparing array types was unreachable
since it requires both tspecs to be the same, but t2 underwent the
array-to-pointer conversion.
Previously, lint warned about enum type mismatches, even without -e for
strict enum mode. Instead, it got the case for 'char *' wrong, which is
now fixed. Now lint behaves like GCC 10.3.0 in this regard. The
warning about enum mismatch is useful though, so it may be re-added in a
future commit.
diffstat:
tests/usr.bin/xlint/lint1/gcc_cast_union.c | 8 +++--
tests/usr.bin/xlint/lint1/gcc_cast_union.exp | 6 ++--
usr.bin/xlint/lint1/tree.c | 37 +++------------------------
3 files changed, 12 insertions(+), 39 deletions(-)
diffs (106 lines):
diff -r a218c655dbef -r 4285f23986b2 tests/usr.bin/xlint/lint1/gcc_cast_union.c
--- a/tests/usr.bin/xlint/lint1/gcc_cast_union.c Tue Aug 03 20:59:20 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_cast_union.c Tue Aug 03 21:09:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_cast_union.c,v 1.1 2021/08/03 20:34:23 rillig Exp $ */
+/* $NetBSD: gcc_cast_union.c,v 1.2 2021/08/03 21:09:26 rillig Exp $ */
# 3 "gcc_cast_union.c"
/*
@@ -11,6 +11,8 @@
* https://gcc.gnu.org/onlinedocs/gcc/Cast-to-Union.html
*/
+/* lint1-extra-flags: -e */
+
union anything {
_Bool m_bool;
char m_char;
@@ -79,9 +81,9 @@
any = (union anything)E1;
any = (union anything)E2;
/* GCC allows enum mismatch even with -Wenum-conversion */
- /* expect+1: error: type 'enum other_enum' is not a member of 'union anything' [329] */
+ /* XXX: Lint should warn about enum type mismatch */
any = (union anything)OTHER;
- /* GCC strictly complains that 'char *' is not in the union. */
+ /* expect+1: error: type 'pointer to char' is not a member of 'union anything' [329] */
any = (union anything)"char *";
any = (union anything)(const char *)"char *";
/* expect+1: error: type 'pointer to double' is not a member of 'union anything' [329] */
diff -r a218c655dbef -r 4285f23986b2 tests/usr.bin/xlint/lint1/gcc_cast_union.exp
--- a/tests/usr.bin/xlint/lint1/gcc_cast_union.exp Tue Aug 03 20:59:20 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_cast_union.exp Tue Aug 03 21:09:26 2021 +0000
@@ -1,4 +1,4 @@
-gcc_cast_union.c(83): error: type 'enum other_enum' is not a member of 'union anything' [329]
-gcc_cast_union.c(88): error: type 'pointer to double' is not a member of 'union anything' [329]
+gcc_cast_union.c(87): error: type 'pointer to char' is not a member of 'union anything' [329]
gcc_cast_union.c(90): error: type 'pointer to double' is not a member of 'union anything' [329]
-gcc_cast_union.c(92): error: type 'pointer to int' is not a member of 'union anything' [329]
+gcc_cast_union.c(92): error: type 'pointer to double' is not a member of 'union anything' [329]
+gcc_cast_union.c(94): error: type 'pointer to int' is not a member of 'union anything' [329]
diff -r a218c655dbef -r 4285f23986b2 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Tue Aug 03 20:59:20 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Tue Aug 03 21:09:26 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.329 2021/08/03 20:57:06 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.330 2021/08/03 21:09:26 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.329 2021/08/03 20:57:06 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.330 2021/08/03 21:09:26 rillig Exp $");
#endif
#include <float.h>
@@ -102,36 +102,6 @@
return modtab[op].m_name;
}
-static bool
-sametype(const type_t *t1, const type_t *t2)
-{
-
- /* Maybe this can be merged into 'eqtype'. */
-
- if (t1->t_tspec != t2->t_tspec)
- return false;
-
- /* Ignore const/volatile */
-
- switch (t1->t_tspec) {
- case ARRAY:
- if (t1->t_dim != t2->t_dim)
- return false;
- /*FALLTHROUGH*/
- case PTR:
- return sametype(t1->t_subt, t2->t_subt);
- case ENUM:
- return strcmp(t1->t_enum->en_tag->s_name,
- t2->t_enum->en_tag->s_name) == 0;
- case STRUCT:
- case UNION:
- return strcmp(t1->t_str->sou_tag->s_name,
- t2->t_str->sou_tag->s_name) == 0;
- default:
- return true;
- }
-}
-
/* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */
type_t *
derive_type(type_t *tp, tspec_t t)
@@ -3401,7 +3371,8 @@
return NULL;
}
for (m = str->sou_first_member; m != NULL; m = m->s_next) {
- if (sametype(m->s_type, tn->tn_type)) {
+ if (eqtype(m->s_type, tn->tn_type,
+ false, false, NULL)) {
tn = expr_zalloc_tnode();
tn->tn_op = CVT;
tn->tn_type = tp;
Home |
Main Index |
Thread Index |
Old Index