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: demonstrate bug in handling of nes...



details:   https://anonhg.NetBSD.org/src/rev/e4373e89282b
branches:  trunk
changeset: 979570:e4373e89282b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jan 01 16:50:47 2021 +0000

description:
lint: demonstrate bug in handling of nested C9X struct initializers

diffstat:

 distrib/sets/lists/tests/mi                     |   4 +-
 tests/usr.bin/xlint/lint1/Makefile              |   4 +-
 tests/usr.bin/xlint/lint1/d_init_pop_member.c   |  58 +++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/d_init_pop_member.exp |   4 +
 tests/usr.bin/xlint/lint1/t_integration.sh      |   3 +-
 usr.bin/xlint/lint1/init.c                      |  14 +++--
 6 files changed, 79 insertions(+), 8 deletions(-)

diffs (170 lines):

diff -r 7cab815058da -r e4373e89282b distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jan 01 14:57:14 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jan 01 16:50:47 2021 +0000
@@ -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
diff -r 7cab815058da -r e4373e89282b tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Fri Jan 01 14:57:14 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Fri Jan 01 16:50:47 2021 +0000
@@ -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_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
diff -r 7cab815058da -r e4373e89282b tests/usr.bin/xlint/lint1/d_init_pop_member.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_pop_member.c     Fri Jan 01 16:50:47 2021 +0000
@@ -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
+       };
+}
diff -r 7cab815058da -r e4373e89282b tests/usr.bin/xlint/lint1/d_init_pop_member.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_pop_member.exp   Fri Jan 01 16:50:47 2021 +0000
@@ -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]
diff -r 7cab815058da -r e4373e89282b tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Fri Jan 01 14:57:14 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Fri Jan 01 16:50:47 2021 +0000
@@ -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 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
diff -r 7cab815058da -r e4373e89282b usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Fri Jan 01 14:57:14 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Fri Jan 01 16:50:47 2021 +0000
@@ -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 @@
 #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 @@
        } 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);
        }



Home | Main Index | Thread Index | Old Index