Module Name: src
Committed By: rillig
Date: Sun Jan 17 15:40:28 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: externs1.h init.c tree.c
Log Message:
lint: fix return type of conaddr
To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.173 -r1.174 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.56 src/usr.bin/xlint/lint1/externs1.h:1.57
--- src/usr.bin/xlint/lint1/externs1.h:1.56 Sat Jan 16 02:40:02 2021
+++ src/usr.bin/xlint/lint1/externs1.h Sun Jan 17 15:40:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.56 2021/01/16 02:40:02 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.57 2021/01/17 15:40:27 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);
extern void check_expr_misc(const tnode_t *, bool, bool, bool,
bool, bool, bool);
-extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *);
+extern bool constant_addr(tnode_t *, sym_t **, ptrdiff_t *);
extern strg_t *cat_strings(strg_t *, strg_t *);
extern int64_t tsize(type_t *);
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.63 src/usr.bin/xlint/lint1/init.c:1.64
--- src/usr.bin/xlint/lint1/init.c:1.63 Sat Jan 16 16:53:23 2021
+++ src/usr.bin/xlint/lint1/init.c Sun Jan 17 15:40:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.63 2021/01/16 16:53:23 rillig Exp $ */
+/* $NetBSD: init.c,v 1.64 2021/01/17 15:40:27 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.63 2021/01/16 16:53:23 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.64 2021/01/17 15:40:27 rillig Exp $");
#endif
#include <stdlib.h>
@@ -646,7 +646,7 @@ mkinit(tnode_t *tn)
if (tn != NULL && tn->tn_op != CON) {
sym = NULL;
offs = 0;
- if (conaddr(tn, &sym, &offs) == -1) {
+ if (!constant_addr(tn, &sym, &offs)) {
if (sc == AUTO || sc == REG) {
/* non-constant initializer */
c99ism(177);
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.173 src/usr.bin/xlint/lint1/tree.c:1.174
--- src/usr.bin/xlint/lint1/tree.c:1.173 Sun Jan 17 15:31:11 2021
+++ src/usr.bin/xlint/lint1/tree.c Sun Jan 17 15:40:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.173 2021/01/17 15:31:11 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.174 2021/01/17 15:40:27 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.173 2021/01/17 15:31:11 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.174 2021/01/17 15:40:27 rillig Exp $");
#endif
#include <float.h>
@@ -4174,8 +4174,7 @@ check_integer_comparison(op_t op, tnode_
}
/*
- * Takes an expression an returns 0 if this expression can be used
- * for static initialisation, otherwise -1.
+ * Return whether the expression can be used for static initialisation.
*
* Constant initialisation expressions must be constant or an address
* of a static object with an optional offset. In the first case,
@@ -4186,8 +4185,8 @@ check_integer_comparison(op_t op, tnode_
* CON. Type conversions are allowed if they do not change binary
* representation (including width).
*/
-int
-conaddr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
+bool
+constant_addr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
{
sym_t *sym;
ptrdiff_t offs1, offs2;
@@ -4196,24 +4195,24 @@ conaddr(tnode_t *tn, sym_t **symp, ptrdi
switch (tn->tn_op) {
case MINUS:
if (tn->tn_right->tn_op == CVT)
- return conaddr(tn->tn_right, symp, offsp);
+ return constant_addr(tn->tn_right, symp, offsp);
else if (tn->tn_right->tn_op != CON)
- return -1;
+ return false;
/* FALLTHROUGH */
case PLUS:
offs1 = offs2 = 0;
if (tn->tn_left->tn_op == CON) {
offs1 = (ptrdiff_t)tn->tn_left->tn_val->v_quad;
- if (conaddr(tn->tn_right, &sym, &offs2) == -1)
- return -1;
+ if (!constant_addr(tn->tn_right, &sym, &offs2))
+ return false;
} else if (tn->tn_right->tn_op == CON) {
offs2 = (ptrdiff_t)tn->tn_right->tn_val->v_quad;
if (tn->tn_op == MINUS)
offs2 = -offs2;
- if (conaddr(tn->tn_left, &sym, &offs1) == -1)
- return -1;
+ if (!constant_addr(tn->tn_left, &sym, &offs1))
+ return false;
} else {
- return -1;
+ return false;
}
*symp = sym;
*offsp = offs1 + offs2;
@@ -4235,7 +4234,7 @@ conaddr(tnode_t *tn, sym_t **symp, ptrdi
ot = tn->tn_left->tn_type->t_tspec;
if ((!is_integer(t) && t != PTR) ||
(!is_integer(ot) && ot != PTR)) {
- return -1;
+ return false;
}
#ifdef notdef
/*
@@ -4250,13 +4249,13 @@ conaddr(tnode_t *tn, sym_t **symp, ptrdi
else if (psize(t) != psize(ot))
return -1;
#endif
- if (conaddr(tn->tn_left, symp, offsp) == -1)
- return -1;
+ if (!constant_addr(tn->tn_left, symp, offsp))
+ return false;
break;
default:
- return -1;
+ return false;
}
- return 0;
+ return true;
}
/*