Module Name:    src
Committed By:   rillig
Date:           Sun Apr 18 08:00:13 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: init.c lex.c

Log Message:
lint: fix storage class of compound literal in initializer

A compound literal that occurs at block_level 0 does not have storage
class AUTO.  Instead, its storage class is either EXTERN or STATIC.

While removing the temporary objects from the symbol table had prevented
the assertion, it did not properly fix the underlying problem, which was
that since C99 the initializers can contain references to unnamed
objects that are created on-the-fly.  For C90 it was correct to always
use AUTO as the storage class of a temporary symbol.


To generate a diff of this commit:
cvs rdiff -u -r1.195 -r1.196 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/xlint/lint1/lex.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.195 src/usr.bin/xlint/lint1/init.c:1.196
--- src/usr.bin/xlint/lint1/init.c:1.195	Sat Apr 17 21:20:08 2021
+++ src/usr.bin/xlint/lint1/init.c	Sun Apr 18 08:00:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.195 2021/04/17 21:20:08 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.196 2021/04/18 08:00:13 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.195 2021/04/17 21:20:08 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.196 2021/04/18 08:00:13 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -994,17 +994,6 @@ 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)
 {
@@ -1048,9 +1037,6 @@ end_initialization(void)
 	debug_indentation--;
 #endif
 	debug_step0("end initialization");
-
-	if (init == NULL)
-		discard_temporary_objects();
 }
 
 void

Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.27 src/usr.bin/xlint/lint1/lex.c:1.28
--- src/usr.bin/xlint/lint1/lex.c:1.27	Mon Apr 12 15:55:26 2021
+++ src/usr.bin/xlint/lint1/lex.c	Sun Apr 18 08:00:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.27 2021/04/12 15:55:26 christos Exp $ */
+/* $NetBSD: lex.c,v 1.28 2021/04/18 08:00:13 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.27 2021/04/12 15:55:26 christos Exp $");
+__RCSID("$NetBSD: lex.c,v 1.28 2021/04/18 08:00:13 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -1486,14 +1486,19 @@ mktempsym(type_t *t)
 	int h;
 	char *s = getlblk(block_level, 64);
 	sym_t *sym = getblk(sizeof(*sym));
+	scl_t scl;
 
 	(void)snprintf(s, 64, "%.8d_tmp", n++);
 	h = hash(s);
 
+	scl = dcs->d_scl;
+	if (scl == NOSCL)
+		scl = block_level > 0 ? AUTO : EXTERN;
+
 	sym->s_name = s;
 	sym->s_type = t;
 	sym->s_block_level = block_level;
-	sym->s_scl = AUTO;
+	sym->s_scl = scl;
 	sym->s_kind = FVFT;
 	sym->s_used = true;
 	sym->s_set = true;

Reply via email to