Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src tests/lint: demonstrate assertion failure in initialization
details: https://anonhg.NetBSD.org/src/rev/7de8e049f2ee
branches: trunk
changeset: 982580:7de8e049f2ee
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Apr 17 20:36:17 2021 +0000
description:
tests/lint: demonstrate assertion failure in initialization
diffstat:
distrib/sets/lists/tests/mi | 4 +-
tests/usr.bin/xlint/lint1/Makefile | 4 +-
tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c | 30 +++++++++++++++++
tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp | 1 +
tests/usr.bin/xlint/lint1/t_integration.sh | 4 +-
5 files changed, 40 insertions(+), 3 deletions(-)
diffs (93 lines):
diff -r 9523f72b8383 -r 7de8e049f2ee distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sat Apr 17 20:12:55 2021 +0000
+++ b/distrib/sets/lists/tests/mi Sat Apr 17 20:36:17 2021 +0000
@@ -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
diff -r 9523f72b8383 -r 7de8e049f2ee tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile Sat Apr 17 20:12:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile Sat Apr 17 20:36:17 2021 +0000
@@ -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_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
diff -r 9523f72b8383 -r 7de8e049f2ee tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c Sat Apr 17 20:36:17 2021 +0000
@@ -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
+// },
+};
diff -r 9523f72b8383 -r 7de8e049f2ee tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp Sat Apr 17 20:36:17 2021 +0000
@@ -0,0 +1,1 @@
+gcc_init_compound_literal.c(25): error: too many struct/union initializers [172]
diff -r 9523f72b8383 -r 7de8e049f2ee tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh Sat Apr 17 20:12:55 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh Sat Apr 17 20:36:17 2021 +0000
@@ -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_incorrect_array_size
test_case d_long_double_int
+test_case gcc_init_compound_literal
+
test_case op_colon
test_case feat_stacktrace
Home |
Main Index |
Thread Index |
Old Index