summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-06-30 21:06:18 +0000
committerrillig <rillig@NetBSD.org>2023-06-30 21:06:18 +0000
commitede616db90b634153005dcefd498f6509c6506d3 (patch)
tree19cb0442994c3c5233a189a70d18356962cbffa4 /tests
parent311fddb0e0819530edb41b9bd3f4613ea332d891 (diff)
lint: fix handling of unnamed struct/union members
The support for unnamed struct/union members that was added in decl.c 1.60 from 2015-10-13 was simple but wrong. It didn't cover initializers of these structures and computed wrong sizes for structures containing anonymous unions. At that time, the handling of initializers was broken as well, it was fixed 6 years later in init.c 1.229 from 2021-12-22. Real-life examples for code that lint couldn't handle are: * external/bsd/jemalloc/dist/src/jemalloc.c * external/mit/xorg/lib/dri.old/Makefile
Diffstat (limited to 'tests')
-rw-r--r--tests/usr.bin/xlint/lint1/expr_sizeof.c5
-rw-r--r--tests/usr.bin/xlint/lint1/init_braces.c4
-rw-r--r--tests/usr.bin/xlint/lint1/msg_102.c10
3 files changed, 5 insertions, 14 deletions
diff --git a/tests/usr.bin/xlint/lint1/expr_sizeof.c b/tests/usr.bin/xlint/lint1/expr_sizeof.c
index 88b4edf987e..313f2b2bc24 100644
--- a/tests/usr.bin/xlint/lint1/expr_sizeof.c
+++ b/tests/usr.bin/xlint/lint1/expr_sizeof.c
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_sizeof.c,v 1.11 2023/06/30 16:39:17 rillig Exp $ */
+/* $NetBSD: expr_sizeof.c,v 1.12 2023/06/30 21:06:18 rillig Exp $ */
# 3 "expr_sizeof.c"
/*
@@ -152,8 +152,7 @@ anonymous_struct_and_union(void)
unsigned char uc32[32];
};
} su_16_32;
- /* FIXME: Must be 32, not 48. */
- /* expect+1: error: negative array dimension (-48) [20] */
+ /* expect+1: error: negative array dimension (-32) [20] */
typedef int sizeof_su_16_32[-(int)sizeof(su_16_32)];
union {
diff --git a/tests/usr.bin/xlint/lint1/init_braces.c b/tests/usr.bin/xlint/lint1/init_braces.c
index b17ded3991a..ceb2dad558a 100644
--- a/tests/usr.bin/xlint/lint1/init_braces.c
+++ b/tests/usr.bin/xlint/lint1/init_braces.c
@@ -1,4 +1,4 @@
-/* $NetBSD: init_braces.c,v 1.4 2023/06/30 09:21:52 rillig Exp $ */
+/* $NetBSD: init_braces.c,v 1.5 2023/06/30 21:06:18 rillig Exp $ */
# 3 "init_braces.c"
/*
@@ -86,8 +86,6 @@ init_anonymous_struct_and_union(void)
struct outer var = { /* struct outer */
{ /* anonymous union */
{ /* anonymous struct */
-/* FIXME: GCC and Clang both compile this initializer. */
-/* expect+1: error: type 'struct time' does not have member 'times' [101] */
.times = {
.t0 = { .ns = 0, },
.t1 = { .ns = 0, },
diff --git a/tests/usr.bin/xlint/lint1/msg_102.c b/tests/usr.bin/xlint/lint1/msg_102.c
index de682870b76..91c9aea2fc4 100644
--- a/tests/usr.bin/xlint/lint1/msg_102.c
+++ b/tests/usr.bin/xlint/lint1/msg_102.c
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_102.c,v 1.5 2023/06/30 09:21:52 rillig Exp $ */
+/* $NetBSD: msg_102.c,v 1.6 2023/06/30 21:06:18 rillig Exp $ */
# 3 "msg_102.c"
// Test for message: illegal use of member '%s' [102]
@@ -31,14 +31,8 @@ static struct bit_fields_and_bits *b1, *b2;
static inline _Bool
eq(int x)
{
- /*
- * TODO: Once this is fixed, enable lint in
- * external/mit/xorg/lib/dri.old/Makefile again.
- */
-
if (x == 0)
- /* expect+2: error: illegal use of member 'bits' [102] */
- /* expect+1: error: illegal use of member 'bits' [102] */
+ /* Accessing a member from an unnamed struct member. */
return u1->bits == u2->bits;
/*