Module Name:    src
Committed By:   rillig
Date:           Sat Apr 17 21:20:08 UTC 2021

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

Log Message:
lint: fix assertion failure for temporary objects in initialization


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
    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.194 -r1.195 src/usr.bin/xlint/lint1/init.c

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/gcc_init_compound_literal.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c:1.2	Sat Apr 17 20:57:18 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c	Sat Apr 17 21:20:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_init_compound_literal.c,v 1.2 2021/04/17 20:57:18 rillig Exp $	*/
+/*	$NetBSD: gcc_init_compound_literal.c,v 1.3 2021/04/17 21:20:08 rillig Exp $	*/
 # 3 "gcc_init_compound_literal.c"
 
 /*
@@ -12,6 +12,10 @@
  * Using these address constants, it is possible to reference an unnamed
  * object created by a compound literal (C99 6.5.2.5), using either an
  * explicit '&' or the implicit array-to-pointer conversion from C99 6.3.2.1.
+ *
+ * Before init.c 1.195 from 2021-04-17, lint failed with an assertion failure
+ * in check_global_variable, called by check_global_symbols since these
+ * temporary objects have neither storage class EXTERN nor STATIC.
  */
 
 // Seen in sys/crypto/aes/aes_ccm.c.
@@ -20,10 +24,9 @@ const struct {
 } 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
-//	},
+	.ctxt = (const unsigned char[4]){
+	    1, 2, 3, 4
+	},
 };
 
 struct node {
@@ -36,7 +39,7 @@ struct node {
  * Initial tree for representing the decisions in the classic number guessing
  * game often used in teaching the basics of programming.
  */
-/* TODO: activate after fixing the assertion failure
+/* expect+1: static variable guess unused */
 static const struct node guess = {
 	50,
 	&(struct node){
@@ -54,4 +57,3 @@ static const struct node guess = {
 	},
 	(void *)0
 };
-*/
Index: src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp:1.2 src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp:1.2	Sat Apr 17 20:57:18 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp	Sat Apr 17 21:20:08 2021
@@ -1 +1,2 @@
-gcc_init_compound_literal.c(22): error: too many struct/union initializers [172]
+gcc_init_compound_literal.c(26): error: too many struct/union initializers [172]
+gcc_init_compound_literal.c(43): warning: static variable guess unused [226]

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.194 src/usr.bin/xlint/lint1/init.c:1.195
--- src/usr.bin/xlint/lint1/init.c:1.194	Fri Apr  9 23:03:26 2021
+++ src/usr.bin/xlint/lint1/init.c	Sat Apr 17 21:20:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.194 2021/04/09 23:03:26 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.195 2021/04/17 21:20:08 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.194 2021/04/09 23:03:26 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.195 2021/04/17 21:20:08 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -994,6 +994,17 @@ done:
 static struct initialization *init;
 
 
+static void
+discard_temporary_objects(void)
+{
+	sym_t   *sym;
+
+	for (sym = dcs->d_dlsyms; sym != NULL; sym = sym->s_dlnxt)
+		if (ch_isdigit(sym->s_name[0]))	/* see mktempsym */
+			rmsym(sym);
+}
+
+
 static struct initialization *
 current_init(void)
 {
@@ -1037,6 +1048,9 @@ end_initialization(void)
 	debug_indentation--;
 #endif
 	debug_step0("end initialization");
+
+	if (init == NULL)
+		discard_temporary_objects();
 }
 
 void

Reply via email to