Module Name: src
Committed By: rillig
Date: Sat Jan 9 17:21:33 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_108.c msg_108.exp
src/usr.bin/xlint/lint1: err.c tree.c
Log Message:
lint: fix crash for error 108 (invalid type of unary operator)
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_108.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_108.exp
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.136 -r1.137 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_108.c
diff -u src/tests/usr.bin/xlint/lint1/msg_108.c:1.2 src/tests/usr.bin/xlint/lint1/msg_108.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_108.c:1.2 Sat Jan 9 17:02:19 2021
+++ src/tests/usr.bin/xlint/lint1/msg_108.c Sat Jan 9 17:21:33 2021
@@ -1,22 +1,25 @@
-/* $NetBSD: msg_108.c,v 1.2 2021/01/09 17:02:19 rillig Exp $ */
+/* $NetBSD: msg_108.c,v 1.3 2021/01/09 17:21:33 rillig Exp $ */
# 3 "msg_108.c"
// Test for message: operand of '%s' has incompatible type (%s != %s) [108]
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message.";
-
-struct s {
- int member;
-};
-
+/*
+ * Before tree.c 1.137 from 2021-01-19, taking the complement of a struct
+ * (an absurd idea, by the way), resulted in an internal error because the
+ * message 108 had two operands, the second of which was always NOTSPEC, as
+ * could be expected for a unary operator.
+ *
+ * Since an error "invalid type (none)" doesn't make sense, lint rather
+ * chooses to crash than to generate such an error.
+ */
void
-example(void)
+complement_of_a_struct(void)
{
- struct s s;
+ struct s {
+ int member;
+ } s = {
+ 0
+ };
- // FIXME: msg_108.c(14): lint error: common/tyname.c, 190: tspec_name(0)
- // basic_type_name (t=NOTSPEC)
- // warn_incompatible_types (op=COMPL, lt=STRUCT, rt=NOTSPEC)
- //s = ~s;
+ s = ~s;
}
Index: src/tests/usr.bin/xlint/lint1/msg_108.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_108.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_108.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_108.exp:1.1 Sat Jan 2 10:22:43 2021
+++ src/tests/usr.bin/xlint/lint1/msg_108.exp Sat Jan 9 17:21:33 2021
@@ -1 +1 @@
-msg_108.c(6): syntax error ':' [249]
+msg_108.c(24): operand of '~' has invalid type (struct) [108]
Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.64 src/usr.bin/xlint/lint1/err.c:1.65
--- src/usr.bin/xlint/lint1/err.c:1.64 Sun Jan 3 18:48:37 2021
+++ src/usr.bin/xlint/lint1/err.c Sat Jan 9 17:21:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.64 2021/01/03 18:48:37 rillig Exp $ */
+/* $NetBSD: err.c,v 1.65 2021/01/09 17:21:33 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.64 2021/01/03 18:48:37 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.65 2021/01/09 17:21:33 rillig Exp $");
#endif
#include <sys/types.h>
@@ -167,7 +167,7 @@ const char *msgs[] = {
"non-unique member requires struct/union %s", /* 105 */
"left operand of '->' must be pointer", /* 106 */
"operands of '%s' have incompatible types (%s != %s)", /* 107 */
- "operand of '%s' has incompatible type (%s != %s)", /* 108 */
+ "operand of '%s' has invalid type (%s)", /* 108 */
"void type illegal in expression", /* 109 */
"pointer to function is not allowed here", /* 110 */
"unacceptable operand of '%s'", /* 111 */
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.136 src/usr.bin/xlint/lint1/tree.c:1.137
--- src/usr.bin/xlint/lint1/tree.c:1.136 Sat Jan 9 14:10:15 2021
+++ src/usr.bin/xlint/lint1/tree.c Sat Jan 9 17:21:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.136 2021/01/09 14:10:15 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.137 2021/01/09 17:21:33 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.136 2021/01/09 14:10:15 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.137 2021/01/09 17:21:33 rillig Exp $");
#endif
#include <float.h>
@@ -2182,8 +2182,9 @@ warn_incompatible_types(op_t op, tspec_t
/* operands of '%s' have incompatible types (%s != %s) */
error(107, mp->m_name, tspec_name(lt), tspec_name(rt));
} else {
- /* operand of '%s' has incompatible type (%s != %s) */
- error(108, mp->m_name, tspec_name(lt), tspec_name(rt));
+ lint_assert(rt == NOTSPEC);
+ /* operand of '%s' has invalid type (%s) */
+ error(108, mp->m_name, tspec_name(lt));
}
}