Sat Jul 10 12:10:40 2021 UTC ()
lint: fix assertion failure in declare_argument


(rillig)
diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_lint_assert.c
diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_lint_assert.exp
diff -r1.195 -r1.196 src/usr.bin/xlint/lint1/decl.c

cvs diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_lint_assert.c (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/d_lint_assert.c 2021/02/21 09:07:58 1.3
+++ src/tests/usr.bin/xlint/lint1/d_lint_assert.c 2021/07/10 12:10:39 1.4
@@ -1,15 +1,22 @@ @@ -1,15 +1,22 @@
1/* $NetBSD: d_lint_assert.c,v 1.3 2021/02/21 09:07:58 rillig Exp $ */ 1/* $NetBSD: d_lint_assert.c,v 1.4 2021/07/10 12:10:39 rillig Exp $ */
2# 3 "d_lint_assert.c" 2# 3 "d_lint_assert.c"
3 3
4/* 4/*
5 * Trigger the various assertions in the lint1 code. Several of them are 5 * Trigger the various assertions in the lint1 code. Several of them are
6 * just hard to trigger, but not impossible. 6 * just hard to trigger, but not impossible.
7*/ 7*/
8 8
9enum { 9enum {
10 // Before decl.c 1.118 from 2021-01-10: 10 // Before decl.c 1.118 from 2021-01-10:
11 // lint: assertion "sym->s_scl == EXTERN || sym->s_scl == STATIC" 11 // lint: assertion "sym->s_scl == EXTERN || sym->s_scl == STATIC"
12 // failed in check_global_variable at decl.c:3135 12 // failed in check_global_variable at decl.c:3135
13 // near d_lint_assert.c:14 13 // near d_lint_assert.c:14
14 A = +++ 14 A = +++
15}; /* expect: 249 */ 15}; /* expect: 249 */
 16
 17/*
 18 * Before decl.c 1.196 from 2021-07-10, lint ran into an assertion failure
 19 * for 'sym->s_type != NULL' in declare_argument.
 20 */
 21/* expect+1: warning: old style declaration; add 'int' [1] */
 22c(void());

cvs diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/Attic/d_lint_assert.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/d_lint_assert.exp 2021/03/21 20:44:59 1.3
+++ src/tests/usr.bin/xlint/lint1/Attic/d_lint_assert.exp 2021/07/10 12:10:39 1.4

cvs diff -r1.195 -r1.196 src/usr.bin/xlint/lint1/decl.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/decl.c 2021/07/05 19:55:51 1.195
+++ src/usr.bin/xlint/lint1/decl.c 2021/07/10 12:10:39 1.196
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: decl.c,v 1.195 2021/07/05 19:55:51 rillig Exp $ */ 1/* $NetBSD: decl.c,v 1.196 2021/07/10 12:10:39 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) && !defined(lint) 40#if defined(__RCSID) && !defined(lint)
41__RCSID("$NetBSD: decl.c,v 1.195 2021/07/05 19:55:51 rillig Exp $"); 41__RCSID("$NetBSD: decl.c,v 1.196 2021/07/10 12:10:39 rillig Exp $");
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <limits.h> 45#include <limits.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "lint1.h" 49#include "lint1.h"
50 50
51const char *unnamed = "<unnamed>"; 51const char *unnamed = "<unnamed>";
52 52
53/* shared type structures for arithmetic types and void */ 53/* shared type structures for arithmetic types and void */
54static type_t *typetab; 54static type_t *typetab;
@@ -2420,45 +2420,47 @@ declare_argument(sym_t *sym, bool initfl @@ -2420,45 +2420,47 @@ declare_argument(sym_t *sym, bool initfl
2420 } 2420 }
2421 2421
2422 if (!sym->s_arg) { 2422 if (!sym->s_arg) {
2423 /* declared argument %s is missing */ 2423 /* declared argument %s is missing */
2424 error(53, sym->s_name); 2424 error(53, sym->s_name);
2425 sym->s_arg = true; 2425 sym->s_arg = true;
2426 } 2426 }
2427 2427
2428 if (initflg) { 2428 if (initflg) {
2429 /* cannot initialize parameter: %s */ 2429 /* cannot initialize parameter: %s */
2430 error(52, sym->s_name); 2430 error(52, sym->s_name);
2431 } 2431 }
2432 2432
2433 lint_assert(sym->s_type != NULL); 2433 if (sym->s_type == NULL) /* for c(void()) */
 2434 sym->s_type = gettyp(VOID);
 2435
2434 if ((t = sym->s_type->t_tspec) == ARRAY) { 2436 if ((t = sym->s_type->t_tspec) == ARRAY) {
2435 sym->s_type = derive_type(sym->s_type->t_subt, PTR); 2437 sym->s_type = derive_type(sym->s_type->t_subt, PTR);
2436 } else if (t == FUNC) { 2438 } else if (t == FUNC) {
2437 if (tflag) 2439 if (tflag)
2438 /* a function is declared as an argument: %s */ 2440 /* a function is declared as an argument: %s */
2439 warning(50, sym->s_name); 2441 warning(50, sym->s_name);
2440 sym->s_type = derive_type(sym->s_type, PTR); 2442 sym->s_type = derive_type(sym->s_type, PTR);
2441 } else if (t == FLOAT) { 2443 } else if (t == FLOAT) {
2442 if (tflag) 2444 if (tflag)
2443 sym->s_type = gettyp(DOUBLE); 2445 sym->s_type = gettyp(DOUBLE);
2444 } 2446 }
2445 2447
2446 if (dcs->d_inline) 2448 if (dcs->d_inline)
2447 /* argument declared inline: %s */ 2449 /* argument declared inline: %s */
2448 warning(269, sym->s_name); 2450 warning(269, sym->s_name);
2449 2451
2450 /* 2452 /*
2451 * Arguments must have complete types. lengths() prints the needed 2453 * Arguments must have complete types. length() prints the needed
2452 * error messages (null dimension is impossible because arrays are 2454 * error messages (null dimension is impossible because arrays are
2453 * converted to pointers). 2455 * converted to pointers).
2454 */ 2456 */
2455 if (sym->s_type->t_tspec != VOID) 2457 if (sym->s_type->t_tspec != VOID)
2456 (void)length(sym->s_type, sym->s_name); 2458 (void)length(sym->s_type, sym->s_name);
2457 2459
2458 sym->s_used = dcs->d_used; 2460 sym->s_used = dcs->d_used;
2459 mark_as_set(sym); 2461 mark_as_set(sym);
2460 2462
2461 return sym; 2463 return sym;
2462} 2464}
2463 2465
2464void 2466void