Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: ensure initialization ...



details:   https://anonhg.NetBSD.org/src/rev/90d962c5b7b2
branches:  trunk
changeset: 960815:90d962c5b7b2
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Mar 29 22:07:00 2021 +0000

description:
tests/lint: ensure initialization does not modify shared type

In my not yet published rewrite of lint's init.c, I forgot to copy the
array type. Guard against this bug, which would have been hard to find.

Given that in C, the declaration 'int a[], b[]' creates two different
type objects anyway, it's not easy to come up with a test case that
actually triggers this possible bug.  I'm not sure whether this test
indeed catches this bug.  If not, I'll add another test.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_init.c   |  24 +++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/d_c99_init.exp |   1 +
 2 files changed, 24 insertions(+), 1 deletions(-)

diffs (43 lines):

diff -r 8d45c82e6992 -r 90d962c5b7b2 tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c    Mon Mar 29 21:34:17 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c    Mon Mar 29 22:07:00 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_init.c,v 1.20 2021/03/29 17:13:07 rillig Exp $   */
+/*     $NetBSD: d_c99_init.c,v 1.21 2021/03/29 22:07:00 rillig Exp $   */
 # 3 "d_c99_init.c"
 
 /*
@@ -306,3 +306,25 @@
                { 6 },
        }
 };
+
+/*
+ * During initialization of an object of type array of unknown size, the type
+ * information on the symbol is updated in-place.  Ensure that this happens on
+ * a copy of the type.
+ */
+void
+ensure_array_type_is_not_modified_during_initialization(void)
+{
+       typedef int array_of_unknown_size[];
+
+       array_of_unknown_size a1 = { 1, 2, 3};
+
+       switch (4) {
+       case sizeof(array_of_unknown_size):
+       case 0:                 /* expect: duplicate case in switch: 0 */
+       case 3:
+       case 4:
+       case 12:
+               break;
+       }
+}
diff -r 8d45c82e6992 -r 90d962c5b7b2 tests/usr.bin/xlint/lint1/d_c99_init.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_init.exp  Mon Mar 29 21:34:17 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.exp  Mon Mar 29 22:07:00 2021 +0000
@@ -5,3 +5,4 @@
 d_c99_init.c(232): error: too many struct/union initializers [172]
 d_c99_init.c(238): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
 d_c99_init.c(244): error: too many array initializers, expected 8 [173]
+d_c99_init.c(324): error: duplicate case in switch: 0 [199]



Home | Main Index | Thread Index | Old Index