lint: demonstrate bug in handling of nested C9X struct initializers

This commit is contained in:
rillig 2021-01-01 16:50:47 +00:00
parent ec176a5418
commit 59e2f0df9e
6 changed files with 79 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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
};
}

View File

@ -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]

View File

@ -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

View File

@ -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);
}