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: try harder to recover after syntax...



details:   https://anonhg.NetBSD.org/src/rev/609a92b204bc
branches:  trunk
changeset: 364649:609a92b204bc
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 02 20:12:45 2022 +0000

description:
lint: try harder to recover after syntax errors

lint: assertion "false" failed in declarator_name at decl.c:1596
    near msg_022.c:22

diffstat:

 tests/usr.bin/xlint/lint1/msg_022.c   |  27 +++++++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/msg_022.exp |   6 +++++-
 usr.bin/xlint/lint1/decl.c            |   7 +++++--
 usr.bin/xlint/lint1/err.c             |   5 +++--
 usr.bin/xlint/lint1/func.c            |   6 ++++--
 5 files changed, 42 insertions(+), 9 deletions(-)

diffs (127 lines):

diff -r cee6a7b9d737 -r 609a92b204bc tests/usr.bin/xlint/lint1/msg_022.c
--- a/tests/usr.bin/xlint/lint1/msg_022.c       Sat Apr 02 19:19:12 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_022.c       Sat Apr 02 20:12:45 2022 +0000
@@ -1,7 +1,30 @@
-/*     $NetBSD: msg_022.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_022.c,v 1.3 2022/04/02 20:12:46 rillig Exp $       */
 # 3 "msg_022.c"
 
 // Test for message: incomplete or misplaced function definition [22]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
+/*
+ * Before decl.c 1.264 and func.c 1.130 from 2022-04-02, lint ran into
+ * assertion failures after trying to recover from the below syntax error.
+ */
+/* expect+1: error: syntax error 'f' [249] */
+unsigned long asdf = sizeof(int f() {});
+
+/* Give the parser a chance to recover. */
+/* expect+1: warning: empty declaration [0] */
+;
+
+/*
+ * Before decl.c 1.264 and func.c 1.130 from 2022-04-02, lint ran into
+ * assertion failures after trying to recover from the below syntax error.
+ */
+/* expect+1: error: syntax error 'param1' [249] */
+unsigned long sz = sizeof(int(param1, param2));
+
+/* Give the parser a chance to recover. */
+/* expect+1: warning: empty declaration [0] */
+;
+
+/* expect+1: error: syntax error ':' [249] */
+TODO: "Add example code that triggers the above message."
 TODO: "Add example code that almost triggers the above message."
diff -r cee6a7b9d737 -r 609a92b204bc tests/usr.bin/xlint/lint1/msg_022.exp
--- a/tests/usr.bin/xlint/lint1/msg_022.exp     Sat Apr 02 19:19:12 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_022.exp     Sat Apr 02 20:12:45 2022 +0000
@@ -1,1 +1,5 @@
-msg_022.c(6): error: syntax error ':' [249]
+msg_022.c(11): error: syntax error 'f' [249]
+msg_022.c(15): warning: empty declaration [0]
+msg_022.c(22): error: syntax error 'param1' [249]
+msg_022.c(26): warning: empty declaration [0]
+msg_022.c(29): error: syntax error ':' [249]
diff -r cee6a7b9d737 -r 609a92b204bc usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 02 19:19:12 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 02 20:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.263 2022/04/02 18:15:43 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.264 2022/04/02 20:12:45 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.263 2022/04/02 18:15:43 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.264 2022/04/02 20:12:45 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1613,6 +1613,9 @@
                        sym->s_def = DECL;
                }
                break;
+       case ABSTRACT:          /* try to continue after syntax errors */
+               sc = NOSCL;
+               break;
        default:
                lint_assert(/*CONSTCOND*/false);
        }
diff -r cee6a7b9d737 -r 609a92b204bc usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sat Apr 02 19:19:12 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Sat Apr 02 20:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.155 2022/04/01 23:16:31 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.156 2022/04/02 20:12:46 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.155 2022/04/01 23:16:31 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.156 2022/04/02 20:12:46 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -596,6 +596,7 @@
            "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
            cond, func, file, line, fn, curr_pos.p_line);
        print_stack_trace();
+       (void)fflush(stdout);
        abort();
 }
 
diff -r cee6a7b9d737 -r 609a92b204bc usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Apr 02 19:19:12 2022 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Apr 02 20:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.129 2022/04/02 14:28:30 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.130 2022/04/02 20:12:46 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.129 2022/04/02 14:28:30 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.130 2022/04/02 20:12:46 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -1161,6 +1161,8 @@
         * fine.  See test gcc_attribute.c, function_with_unknown_attribute.
         */
        in_gcc_attribute = false;
+       while (dcs->d_enclosing != NULL)
+               end_declaration_level();
 }
 
 /*



Home | Main Index | Thread Index | Old Index