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 crash for error 108 (invalid t...



details:   https://anonhg.NetBSD.org/src/rev/d2160fc6af66
branches:  trunk
changeset: 979753:d2160fc6af66
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 09 17:21:33 2021 +0000

description:
lint: fix crash for error 108 (invalid type of unary operator)

diffstat:

 tests/usr.bin/xlint/lint1/msg_108.c   |  31 +++++++++++++++++--------------
 tests/usr.bin/xlint/lint1/msg_108.exp |   2 +-
 usr.bin/xlint/lint1/err.c             |   6 +++---
 usr.bin/xlint/lint1/tree.c            |   9 +++++----
 4 files changed, 26 insertions(+), 22 deletions(-)

diffs (106 lines):

diff -r 32167b9bd5a9 -r d2160fc6af66 tests/usr.bin/xlint/lint1/msg_108.c
--- a/tests/usr.bin/xlint/lint1/msg_108.c       Sat Jan 09 17:02:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_108.c       Sat Jan 09 17:21:33 2021 +0000
@@ -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;
 }
diff -r 32167b9bd5a9 -r d2160fc6af66 tests/usr.bin/xlint/lint1/msg_108.exp
--- a/tests/usr.bin/xlint/lint1/msg_108.exp     Sat Jan 09 17:02:19 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_108.exp     Sat Jan 09 17:21:33 2021 +0000
@@ -1,1 +1,1 @@
-msg_108.c(6): syntax error ':' [249]
+msg_108.c(24): operand of '~' has invalid type (struct) [108]
diff -r 32167b9bd5a9 -r d2160fc6af66 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Jan 09 17:02:19 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Jan 09 17:21:33 2021 +0000
@@ -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 @@
        "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 */
diff -r 32167b9bd5a9 -r d2160fc6af66 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Jan 09 17:02:19 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Jan 09 17:21:33 2021 +0000
@@ -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 @@
                /* 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));
        }
 }
 



Home | Main Index | Thread Index | Old Index