Module Name:    src
Committed By:   rillig
Date:           Fri Jan  1 16:50:47 UTC 2021

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh
        src/usr.bin/xlint/lint1: init.c
Added Files:
        src/tests/usr.bin/xlint/lint1: d_init_pop_member.c
            d_init_pop_member.exp

Log Message:
lint: demonstrate bug in handling of nested C9X struct initializers


To generate a diff of this commit:
cvs rdiff -u -r1.1005 -r1.1006 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.23 -r1.24 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/d_init_pop_member.c \
    src/tests/usr.bin/xlint/lint1/d_init_pop_member.exp
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/t_integration.sh
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/xlint/lint1/init.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1005 src/distrib/sets/lists/tests/mi:1.1006
--- src/distrib/sets/lists/tests/mi:1.1005	Fri Jan  1 01:07:07 2021
+++ src/distrib/sets/lists/tests/mi	Fri Jan  1 16:50:47 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1005 2021/01/01 01:07:07 rillig Exp $
+# $NetBSD: mi,v 1.1006 2021/01/01 16:50:47 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5793,6 +5793,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_gcc_variable_array_init.c	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_incorrect_array_size.c	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_incorrect_array_size.exp	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_init_pop_member.c		tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_init_pop_member.exp		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_long_double_int.c		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_long_double_int.exp		tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_nested_structs.c		tests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.23 src/tests/usr.bin/xlint/lint1/Makefile:1.24
--- src/tests/usr.bin/xlint/lint1/Makefile:1.23	Fri Jan  1 01:07:08 2021
+++ src/tests/usr.bin/xlint/lint1/Makefile	Fri Jan  1 16:50:47 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.23 2021/01/01 01:07:08 rillig Exp $
+# $NetBSD: Makefile,v 1.24 2021/01/01 16:50:47 rillig Exp $
 
 NOMAN=		# defined
 
@@ -61,6 +61,8 @@ FILES+=		d_gcc_func.c
 FILES+=		d_gcc_variable_array_init.c
 FILES+=		d_incorrect_array_size.c
 FILES+=		d_incorrect_array_size.exp
+FILES+=		d_init_pop_member.c
+FILES+=		d_init_pop_member.exp
 FILES+=		d_long_double_int.c
 FILES+=		d_long_double_int.exp
 FILES+=		d_nested_structs.c

Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.16 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.17
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.16	Fri Jan  1 01:07:08 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Fri Jan  1 16:50:47 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.16 2021/01/01 01:07:08 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.17 2021/01/01 16:50:47 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -76,6 +76,7 @@ test_case cast_typeof
 test_case decl_old_style_arguments
 test_case fold_test
 test_case gcc_extension
+test_case init_pop_member
 test_case return_type
 test_case type_question_colon
 test_case typefun

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.50 src/usr.bin/xlint/lint1/init.c:1.51
--- src/usr.bin/xlint/lint1/init.c:1.50	Fri Jan  1 11:41:01 2021
+++ src/usr.bin/xlint/lint1/init.c	Fri Jan  1 16:50:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.50 2021/01/01 11:41:01 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.51 2021/01/01 16:50:47 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.50 2021/01/01 11:41:01 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.51 2021/01/01 16:50:47 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -78,13 +78,17 @@ static	int	initstack_string(tnode_t *);
 #endif
 
 void
-push_member(sb)
-	sbuf_t *sb;
+push_member(sbuf_t *sb)
 {
 	namlist_t *nam = xcalloc(1, sizeof (namlist_t));
 	nam->n_name = sb->sb_name;
 	DPRINTF(("%s: %s %p\n", __func__, nam->n_name, nam));
 	if (namedmem == NULL) {
+		/*
+		 * XXX: Why is this a circular list?
+		 * XXX: Why is this a doubly-linked list?
+		 * A simple stack should suffice.
+		 */
 		nam->n_prev = nam->n_next = nam;
 		namedmem = nam;
 	} else {
@@ -105,7 +109,7 @@ pop_member(void)
 	} else {
 		namlist_t *nam = namedmem;
 		namedmem = namedmem->n_next;
-		namedmem->n_next = nam->n_next;
+		namedmem->n_next = nam->n_next; /* FIXME: inner circle */
 		namedmem->n_prev = nam->n_prev;
 		free(nam);
 	}

Added files:

Index: src/tests/usr.bin/xlint/lint1/d_init_pop_member.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_init_pop_member.c:1.1
--- /dev/null	Fri Jan  1 16:50:48 2021
+++ src/tests/usr.bin/xlint/lint1/d_init_pop_member.c	Fri Jan  1 16:50:47 2021
@@ -0,0 +1,58 @@
+# 2
+
+/*
+ * Between init.c 1.27 from 2015-07-28 and init.c 1.52 from 2021-01-01,
+ * a bug in memberpop or pop_member led to a wrong error message
+ * "undefined struct/union member: capital [101]" in the second and third
+ * named initializer.
+ */
+
+struct rgb {
+	unsigned red;
+	unsigned green;
+	unsigned blue;
+};
+
+struct hobbies {
+	unsigned dancing: 1;
+	unsigned running: 1;
+	unsigned swimming: 1;
+};
+
+struct person {
+	struct hobbies hobbies;
+	struct rgb favorite_color;
+};
+
+struct city {
+	struct person major;
+};
+
+struct state {
+	struct city capital;
+};
+
+void func(void)
+{
+	struct state st = {
+	    .capital.major.hobbies.dancing = 1,
+	    /*
+	     * Between 2015-07-28 and 2021-01-01:
+	     * wrong "undefined struct/union member: capital [101]"
+	     */
+	    /*
+	     * As of 2020-01-01:
+	     * wrong "warning: bit-field initializer does not fit [180]"
+	     */
+	    .capital.major.favorite_color.green = 0xFF,
+	    /*
+	     * Between 2015-07-28 and 2021-01-01:
+	     * wrong "undefined struct/union member: capital [101]"
+	     */
+	    /*
+	     * As of 2020-01-01:
+	     * wrong "warning: bit-field initializer does not fit [180]"
+	     */
+	    .capital.major.favorite_color.red = 0xFF
+	};
+}
Index: src/tests/usr.bin/xlint/lint1/d_init_pop_member.exp
diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_init_pop_member.exp:1.1
--- /dev/null	Fri Jan  1 16:50:48 2021
+++ src/tests/usr.bin/xlint/lint1/d_init_pop_member.exp	Fri Jan  1 16:50:47 2021
@@ -0,0 +1,4 @@
+(47): undefined struct/union member: capital [101]
+(47): warning: bit-field initializer does not fit [180]
+(57): undefined struct/union member: capital [101]
+(57): warning: bit-field initializer does not fit [180]

Reply via email to