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.
This commit is contained in:
rillig 2021-04-18 08:00:13 +00:00
parent 73b70e7b0b
commit 1cf5b1560c
2 changed files with 10 additions and 19 deletions

View File

@ -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

View File

@ -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;