Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: fix 3 of the 4 wrong messages abou...
details: https://anonhg.NetBSD.org/src/rev/3193e60f1e4d
branches: trunk
changeset: 1022877:3193e60f1e4d
user: rillig <rillig%NetBSD.org@localhost>
date: Tue Aug 10 20:43:12 2021 +0000
description:
lint: fix 3 of the 4 wrong messages about lvalue in initial assignment
diffstat:
tests/usr.bin/xlint/lint1/msg_115.c | 11 ++++-------
tests/usr.bin/xlint/lint1/msg_115.exp | 3 ---
usr.bin/xlint/lint1/decl.c | 12 +++++++++---
usr.bin/xlint/lint1/init.c | 5 +++--
usr.bin/xlint/lint1/tree.c | 21 +++++++++------------
5 files changed, 25 insertions(+), 27 deletions(-)
diffs (183 lines):
diff -r c30202620131 -r 3193e60f1e4d tests/usr.bin/xlint/lint1/msg_115.c
--- a/tests/usr.bin/xlint/lint1/msg_115.c Tue Aug 10 19:52:14 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_115.c Tue Aug 10 20:43:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_115.c,v 1.6 2021/07/31 10:09:03 rillig Exp $ */
+/* $NetBSD: msg_115.c,v 1.7 2021/08/10 20:43:13 rillig Exp $ */
# 3 "msg_115.c"
// Test for message: %soperand of '%s' must be modifiable lvalue [115]
@@ -30,21 +30,18 @@
/* expect+1: warning: left operand of '=' must be modifiable lvalue [115] */
const_member cm1 = (const_member) { 12345 };
if (cm1.member != 0)
- /* FIXME: In a function call, const members can be assigned. */
- /* expect+1: warning: left operand of 'farg' must be modifiable lvalue [115] */
+ /* In a function call, const members can be assigned. */
take_const_member(cm1);
struct {
const_member member;
} cm2 = {
- /* FIXME: In an initialization, const members can be assigned. */
- /* expect+1: warning: left operand of 'init' must be modifiable lvalue [115] */
+ /* In an initialization, const members can be assigned. */
cm1,
};
if (cm2.member.member != 0) {
}
- /* FIXME: In a return statement, const members can be assigned. */
- /* expect+1: warning: left operand of 'return' must be modifiable lvalue [115] */
+ /* In a return statement, const members can be assigned. */
return cm1;
}
diff -r c30202620131 -r 3193e60f1e4d tests/usr.bin/xlint/lint1/msg_115.exp
--- a/tests/usr.bin/xlint/lint1/msg_115.exp Tue Aug 10 19:52:14 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_115.exp Tue Aug 10 20:43:12 2021 +0000
@@ -6,6 +6,3 @@
msg_115.c(15): warning: left operand of '%=' must be modifiable lvalue [115]
msg_115.c(16): warning: operand of 'x++' must be modifiable lvalue [115]
msg_115.c(31): warning: left operand of '=' must be modifiable lvalue [115]
-msg_115.c(35): warning: left operand of 'farg' must be modifiable lvalue [115]
-msg_115.c(42): warning: left operand of 'init' must be modifiable lvalue [115]
-msg_115.c(49): warning: left operand of 'return' must be modifiable lvalue [115]
diff -r c30202620131 -r 3193e60f1e4d usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Tue Aug 10 19:52:14 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Tue Aug 10 20:43:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.220 2021/08/10 19:52:14 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.221 2021/08/10 20:43:12 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: decl.c,v 1.220 2021/08/10 19:52:14 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.221 2021/08/10 20:43:12 rillig Exp $");
#endif
#include <sys/param.h>
@@ -209,7 +209,13 @@
ntp->t_const = false;
ntp->t_volatile = false;
- /* TODO: deep-copy struct/union members; see msg_115.c */
+ /*
+ * In case of a struct or union type, the members should lose their
+ * qualifiers as well, but that would require a deep copy of the
+ * struct or union type. This in turn would defeat the type
+ * comparison in eqtype, which simply tests whether tp1->t_str ==
+ * tp2->t_str.
+ */
return ntp;
}
diff -r c30202620131 -r 3193e60f1e4d usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Tue Aug 10 19:52:14 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c Tue Aug 10 20:43:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.206 2021/07/31 19:07:52 rillig Exp $ */
+/* $NetBSD: init.c,v 1.207 2021/08/10 20:43:12 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.206 2021/07/31 19:07:52 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.207 2021/08/10 20:43:12 rillig Exp $");
#endif
#include <stdlib.h>
@@ -833,6 +833,7 @@
ln = build_name(in->in_sym, 0);
ln->tn_type = expr_unqualified_type(ln->tn_type);
+ /* TODO: allow 'const' on the left-hand side; see msg_115.c */
tn = build_binary(ln, ASSIGN, rn);
expr(tn, false, false, false, false);
diff -r c30202620131 -r 3193e60f1e4d usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Tue Aug 10 19:52:14 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Tue Aug 10 20:43:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.331 2021/08/09 20:07:23 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.332 2021/08/10 20:43:12 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.331 2021/08/09 20:07:23 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.332 2021/08/10 20:43:12 rillig Exp $");
#endif
#include <float.h>
@@ -1048,8 +1048,11 @@
}
static bool
-typeok_assign(const mod_t *mp, const tnode_t *ln, const type_t *ltp, tspec_t lt)
+typeok_assign(op_t op, const tnode_t *ln, const type_t *ltp, tspec_t lt)
{
+ if (op == RETURN || op == INIT || op == FARG)
+ return true;
+
if (!ln->tn_lvalue) {
if (ln->tn_op == CVT && ln->tn_cast &&
ln->tn_left->tn_op == LOAD) {
@@ -1057,19 +1060,17 @@
error(163);
}
/* %soperand of '%s' must be lvalue */
- error(114, "left ", mp->m_name);
+ error(114, "left ", op_name(op));
return false;
} else if (ltp->t_const || ((lt == STRUCT || lt == UNION) &&
has_constant_member(ltp))) {
if (!tflag)
/* %soperand of '%s' must be modifiable lvalue */
- warning(115, "left ", mp->m_name);
+ warning(115, "left ", op_name(op));
}
return true;
}
-
-
/* Check the types using the information from modtab[]. */
static bool
typeok_scalar(op_t op, const mod_t *mp,
@@ -1223,7 +1224,7 @@
case ORASS:
goto assign;
assign:
- if (!typeok_assign(mp, ln, ltp, lt))
+ if (!typeok_assign(op, ln, ltp, lt))
return false;
break;
case COMMA:
@@ -3792,9 +3793,6 @@
}
}
-/*
- * Called by expr() to recursively perform some tests.
- */
/* ARGSUSED */
void
check_expr_misc(const tnode_t *tn, bool vctx, bool tctx,
@@ -3974,7 +3972,6 @@
szof);
break;
}
-
}
/*
Home |
Main Index |
Thread Index |
Old Index