Module Name:    src
Committed By:   rillig
Date:           Mon Mar 29 22:07:00 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/xlint/lint1/d_c99_init.exp

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.20 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.21
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.20	Mon Mar 29 17:13:07 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c	Mon Mar 29 22:07:00 2021
@@ -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 @@ short c99_6_7_8_p29_example6c[4][3][2] =
 		{ 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;
+	}
+}

Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.14 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.15
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.14	Sun Mar 28 18:48:32 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp	Mon Mar 29 22:07:00 2021
@@ -5,3 +5,4 @@ d_c99_init.c(145): error: syntax error '
 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]

Reply via email to