Module Name: src
Committed By: rillig
Date: Sun Feb 21 15:02:16 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: externs1.h init.c tree.c
Log Message:
lint: extract check_non_constant_initializer from init_using_expr
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.215 -r1.216 src/usr.bin/xlint/lint1/tree.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/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.70 src/usr.bin/xlint/lint1/externs1.h:1.71
--- src/usr.bin/xlint/lint1/externs1.h:1.70 Sun Feb 21 07:59:17 2021
+++ src/usr.bin/xlint/lint1/externs1.h Sun Feb 21 15:02:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.70 2021/02/21 07:59:17 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.71 2021/02/21 15:02:16 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -219,7 +219,7 @@ extern val_t *constant(tnode_t *, bool);
extern void expr(tnode_t *, bool, bool, bool, bool);
extern void check_expr_misc(const tnode_t *, bool, bool, bool,
bool, bool, bool);
-extern bool constant_addr(tnode_t *, sym_t **, ptrdiff_t *);
+extern bool constant_addr(const tnode_t *, sym_t **, ptrdiff_t *);
extern strg_t *cat_strings(strg_t *, strg_t *);
extern int64_t tsize(type_t *);
#ifdef DEBUG
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.86 src/usr.bin/xlint/lint1/init.c:1.87
--- src/usr.bin/xlint/lint1/init.c:1.86 Sun Feb 21 14:57:25 2021
+++ src/usr.bin/xlint/lint1/init.c Sun Feb 21 15:02:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.86 2021/02/21 14:57:25 rillig Exp $ */
+/* $NetBSD: init.c,v 1.87 2021/02/21 15:02:16 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.86 2021/02/21 14:57:25 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.87 2021/02/21 15:02:16 rillig Exp $");
#endif
#include <stdlib.h>
@@ -742,6 +742,26 @@ check_bit_field_init(const tnode_t *ln,
}
}
+static void
+check_non_constant_initializer(const tnode_t *tn, scl_t sclass)
+{
+ if (tn == NULL || tn->tn_op == CON)
+ return;
+
+ sym_t *sym;
+ ptrdiff_t offs;
+ if (constant_addr(tn, &sym, &offs))
+ return;
+
+ if (sclass == AUTO || sclass == REG) {
+ /* non-constant initializer */
+ c99ism(177);
+ } else {
+ /* non-constant initializer */
+ error(177);
+ }
+}
+
void
init_using_expr(tnode_t *tn)
{
@@ -840,19 +860,7 @@ init_using_expr(tnode_t *tn)
if (lt != rt || (initstk->i_type->t_bitfield && tn->tn_op == CON))
tn = convert(INIT, 0, initstk->i_type, tn);
- if (tn != NULL && tn->tn_op != CON) {
- sym_t *sym;
- ptrdiff_t offs;
- if (!constant_addr(tn, &sym, &offs)) {
- if (sclass == AUTO || sclass == REG) {
- /* non-constant initializer */
- c99ism(177);
- } else {
- /* non-constant initializer */
- error(177);
- }
- }
- }
+ check_non_constant_initializer(tn, sclass);
debug_initstack();
debug_leave();
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.215 src/usr.bin/xlint/lint1/tree.c:1.216
--- src/usr.bin/xlint/lint1/tree.c:1.215 Sun Feb 21 11:23:33 2021
+++ src/usr.bin/xlint/lint1/tree.c Sun Feb 21 15:02:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.216 2021/02/21 15:02:16 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.216 2021/02/21 15:02:16 rillig Exp $");
#endif
#include <float.h>
@@ -4185,7 +4185,7 @@ check_integer_comparison(op_t op, tnode_
* representation (including width).
*/
bool
-constant_addr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
+constant_addr(const tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
{
sym_t *sym;
ptrdiff_t offs1, offs2;