Module Name: src Committed By: rillig Date: Sat Apr 17 20:36:17 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh Added Files: src/tests/usr.bin/xlint/lint1: gcc_init_compound_literal.c gcc_init_compound_literal.exp Log Message: tests/lint: demonstrate assertion failure in initialization To generate a diff of this commit: cvs rdiff -u -r1.1041 -r1.1042 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.42 -r1.43 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r0 -r1.1 \ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c \ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp cvs rdiff -u -r1.41 -r1.42 src/tests/usr.bin/xlint/lint1/t_integration.sh 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.1041 src/distrib/sets/lists/tests/mi:1.1042 --- src/distrib/sets/lists/tests/mi:1.1041 Thu Apr 15 19:02:29 2021 +++ src/distrib/sets/lists/tests/mi Sat Apr 17 20:36:17 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1041 2021/04/15 19:02:29 rillig Exp $ +# $NetBSD: mi,v 1.1042 2021/04/17 20:36:17 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6186,6 +6186,8 @@ ./usr/tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/feat_stacktrace.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_000.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_000.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_001.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.42 src/tests/usr.bin/xlint/lint1/Makefile:1.43 --- src/tests/usr.bin/xlint/lint1/Makefile:1.42 Wed Apr 14 18:27:11 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Sat Apr 17 20:36:17 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.42 2021/04/14 18:27:11 rillig Exp $ +# $NetBSD: Makefile,v 1.43 2021/04/17 20:36:17 rillig Exp $ NOMAN= # defined MAX_MESSAGE= 343 # see lint1/err.c @@ -102,6 +102,8 @@ FILES+= d_typename_as_var.c FILES+= d_zero_sized_arrays.c FILES+= feat_stacktrace.c FILES+= feat_stacktrace.exp +FILES+= gcc_init_compound_literal.c +FILES+= gcc_init_compound_literal.exp FILES+= ${:U0 ${:U:${:Urange=${MAX_MESSAGE}}}:C,^.$,0&,:C,^..$,0&,:@i@msg_${i}.c msg_${i}.exp@:Nmsg_176.exp} FILES+= op_colon.c FILES+= op_colon.exp Index: src/tests/usr.bin/xlint/lint1/t_integration.sh diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.41 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.42 --- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.41 Wed Apr 14 18:27:11 2021 +++ src/tests/usr.bin/xlint/lint1/t_integration.sh Sat Apr 17 20:36:17 2021 @@ -1,4 +1,4 @@ -# $NetBSD: t_integration.sh,v 1.41 2021/04/14 18:27:11 rillig Exp $ +# $NetBSD: t_integration.sh,v 1.42 2021/04/17 20:36:17 rillig Exp $ # # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. # All rights reserved. @@ -166,6 +166,8 @@ test_case d_type_conv3 test_case d_incorrect_array_size test_case d_long_double_int +test_case gcc_init_compound_literal + test_case op_colon test_case feat_stacktrace Added files: Index: src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.1 --- /dev/null Sat Apr 17 20:36:18 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c Sat Apr 17 20:36:17 2021 @@ -0,0 +1,30 @@ +/* $NetBSD: gcc_init_compound_literal.c,v 1.1 2021/04/17 20:36:17 rillig Exp $ */ +# 3 "gcc_init_compound_literal.c" + +/* + * C99 says in 6.7.8p4: + * + * All the expressions in an initializer for an object that has static + * storage duration shall be constant expressions or string literals. + * + * The term "constant expression" is defined in C99 6.6 and is quite + * restricted, except for a single paragraph, 6.6p10: + * + * An implementation may accept other forms of constant expressions. + * + * GCC additionally allows compound expressions, and these can even use the + * array-to-pointer conversion from C99 6.3.2.1, which allows to initialize a + * pointer object with a pointer to a direct-value statically allocated array. + */ + +// Seen in sys/crypto/aes/aes_ccm.c. +const struct { + const unsigned char *ctxt; +} T = { + (void *)0, + (void *)0, /* expect: too many struct/union initializers */ +// FIXME: lint: assertion "sym->s_scl == EXTERN || sym->s_scl == STATIC" failed +// .ctxt = (const unsigned char[4]){ +// 1, 2, 3, 4 +// }, +}; Index: src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp:1.1 --- /dev/null Sat Apr 17 20:36:18 2021 +++ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp Sat Apr 17 20:36:17 2021 @@ -0,0 +1 @@ +gcc_init_compound_literal.c(25): error: too many struct/union initializers [172]