Module Name: src Committed By: rillig Date: Tue Aug 10 20:43:13 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_115.c msg_115.exp src/usr.bin/xlint/lint1: decl.c init.c tree.c Log Message: lint: fix 3 of the 4 wrong messages about lvalue in initial assignment To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_115.c cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_115.exp cvs rdiff -u -r1.220 -r1.221 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.206 -r1.207 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.331 -r1.332 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/tests/usr.bin/xlint/lint1/msg_115.c diff -u src/tests/usr.bin/xlint/lint1/msg_115.c:1.6 src/tests/usr.bin/xlint/lint1/msg_115.c:1.7 --- src/tests/usr.bin/xlint/lint1/msg_115.c:1.6 Sat Jul 31 10:09:03 2021 +++ src/tests/usr.bin/xlint/lint1/msg_115.c Tue Aug 10 20:43:13 2021 @@ -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 @@ initialize_const_struct_member(void) /* 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; } Index: src/tests/usr.bin/xlint/lint1/msg_115.exp diff -u src/tests/usr.bin/xlint/lint1/msg_115.exp:1.5 src/tests/usr.bin/xlint/lint1/msg_115.exp:1.6 --- src/tests/usr.bin/xlint/lint1/msg_115.exp:1.5 Sat Jul 31 10:09:03 2021 +++ src/tests/usr.bin/xlint/lint1/msg_115.exp Tue Aug 10 20:43:13 2021 @@ -6,6 +6,3 @@ msg_115.c(14): warning: left operand of 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] Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.220 src/usr.bin/xlint/lint1/decl.c:1.221 --- src/usr.bin/xlint/lint1/decl.c:1.220 Tue Aug 10 19:52:14 2021 +++ src/usr.bin/xlint/lint1/decl.c Tue Aug 10 20:43:12 2021 @@ -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 @@ expr_unqualified_type(const type_t *tp) 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; } Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.206 src/usr.bin/xlint/lint1/init.c:1.207 --- src/usr.bin/xlint/lint1/init.c:1.206 Sat Jul 31 19:07:52 2021 +++ src/usr.bin/xlint/lint1/init.c Tue Aug 10 20:43:12 2021 @@ -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 @@ initialization_expr_using_assign(struct 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); Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.331 src/usr.bin/xlint/lint1/tree.c:1.332 --- src/usr.bin/xlint/lint1/tree.c:1.331 Mon Aug 9 20:07:23 2021 +++ src/usr.bin/xlint/lint1/tree.c Tue Aug 10 20:43:12 2021 @@ -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 @@ typeok_colon(const mod_t *mp, } 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 @@ typeok_assign(const mod_t *mp, const tno 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 @@ typeok_op(op_t op, const mod_t *mp, int 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 @@ check_null_effect(const tnode_t *tn) } } -/* - * 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 @@ check_expr_misc(const tnode_t *tn, bool szof); break; } - } /*