Module Name:    src
Committed By:   rillig
Date:           Fri Apr  1 22:28:21 UTC 2022

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_pr_22119.c d_pr_22119.exp
            decl_direct_abstract.c decl_direct_abstract.exp msg_155.c
            msg_155.exp
        src/usr.bin/xlint/lint1: decl.c tree.c

Log Message:
lint: improve determination of abstract typename

Still not perfect, but at least a step in the right direction.  See
decl_direct_abstract.c for the missing edge cases.

See PR#22119.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_pr_22119.c \
    src/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_pr_22119.exp \
    src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/xlint/lint1/msg_155.c
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_155.exp
cvs rdiff -u -r1.256 -r1.257 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.412 -r1.413 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/d_pr_22119.c
diff -u src/tests/usr.bin/xlint/lint1/d_pr_22119.c:1.3 src/tests/usr.bin/xlint/lint1/d_pr_22119.c:1.4
--- src/tests/usr.bin/xlint/lint1/d_pr_22119.c:1.3	Sat Jan 15 14:22:03 2022
+++ src/tests/usr.bin/xlint/lint1/d_pr_22119.c	Fri Apr  1 22:28:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_pr_22119.c,v 1.3 2022/01/15 14:22:03 rillig Exp $	*/
+/*	$NetBSD: d_pr_22119.c,v 1.4 2022/04/01 22:28:21 rillig Exp $	*/
 # 3 "d_pr_22119.c"
 
 /*
@@ -15,5 +15,7 @@ func1(void)
 
 	/* expect+1: error: 'p' undefined [99] */
 	f1 = (void (*)(void))p;
+	/* expect+2: error: function returns illegal type 'function(void) returning pointer to void' [15] */
+	/* expect+1: error: invalid cast from 'int' to 'function() returning pointer to function(void) returning pointer to void' [147] */
 	f1 = (void *()(void))p;		/* crash before 2021-02-28 */
 }
Index: src/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp
diff -u src/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp:1.3 src/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp:1.4
--- src/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp:1.3	Tue Sep 14 19:06:27 2021
+++ src/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp	Fri Apr  1 22:28:21 2022
@@ -5,8 +5,10 @@ decl_direct_abstract.c(50): error: canno
 decl_direct_abstract.c(52): error: cannot initialize 'double' from 'pointer to function(pointer to pointer to int) returning void' [185]
 decl_direct_abstract.c(54): error: cannot initialize 'double' from 'pointer to function(pointer to array[3] of int) returning void' [185]
 decl_direct_abstract.c(56): error: cannot initialize 'double' from 'pointer to function(pointer to array[unknown_size] of int) returning void' [185]
-decl_direct_abstract.c(59): error: cannot initialize 'double' from 'pointer to function(void) returning void' [185]
+decl_direct_abstract.c(59): error: cannot initialize 'double' from 'pointer to function(pointer to function() returning pointer to int) returning void' [185]
 decl_direct_abstract.c(61): error: cannot initialize 'double' from 'pointer to function(pointer to function(void) returning int) returning void' [185]
 decl_direct_abstract.c(63): error: cannot initialize 'double' from 'pointer to function(pointer to const pointer to function(unsigned int, ...) returning int) returning void' [185]
 decl_direct_abstract.c(70): error: null dimension [17]
 decl_direct_abstract.c(73): error: null dimension [17]
+decl_direct_abstract.c(81): error: cannot take size/alignment of function [144]
+decl_direct_abstract.c(84): error: cannot take size/alignment of void [146]

Index: src/tests/usr.bin/xlint/lint1/d_pr_22119.exp
diff -u src/tests/usr.bin/xlint/lint1/d_pr_22119.exp:1.4 src/tests/usr.bin/xlint/lint1/d_pr_22119.exp:1.5
--- src/tests/usr.bin/xlint/lint1/d_pr_22119.exp:1.4	Sat Jan 15 14:22:03 2022
+++ src/tests/usr.bin/xlint/lint1/d_pr_22119.exp	Fri Apr  1 22:28:21 2022
@@ -1 +1,3 @@
 d_pr_22119.c(17): error: 'p' undefined [99]
+d_pr_22119.c(20): error: function returns illegal type 'function(void) returning pointer to void' [15]
+d_pr_22119.c(20): error: invalid cast from 'int' to 'function() returning pointer to function(void) returning pointer to void' [147]
Index: src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c
diff -u src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.4 src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.5
--- src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c:1.4	Tue Sep 14 19:08:40 2021
+++ src/tests/usr.bin/xlint/lint1/decl_direct_abstract.c	Fri Apr  1 22:28:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl_direct_abstract.c,v 1.4 2021/09/14 19:08:40 rillig Exp $	*/
+/*	$NetBSD: decl_direct_abstract.c,v 1.5 2022/04/01 22:28:21 rillig Exp $	*/
 # 3 "decl_direct_abstract.c"
 
 /*
@@ -54,8 +54,8 @@ double type_of_c99_6_7_6_example_c = c99
 double type_of_c99_6_7_6_example_d = c99_6_7_6_example_d;
 /* expect+1: 'pointer to function(pointer to array[unknown_size] of int) returning void' */
 double type_of_c99_6_7_6_example_e = c99_6_7_6_example_e;
-/* FIXME: see msg_155.c, msg_347.c */
-/* expect+1: 'pointer to function(void) returning void' */
+/* Wrong type before decl.c 1.256 from 2022-04-01. */
+/* expect+1: 'pointer to function(pointer to function() returning pointer to int) returning void' */
 double type_of_c99_6_7_6_example_f = c99_6_7_6_example_f;
 /* expect+1: 'pointer to function(pointer to function(void) returning int) returning void' */
 double type_of_c99_6_7_6_example_g = c99_6_7_6_example_g;
@@ -76,3 +76,13 @@ void int_array_array(int[][7]);
 void int_array_3_array(int[3][7]);
 /* supported since cgram.y 1.363 from 2021-09-14 */
 void int_array_ast_array(int[*][7]);
+
+/* expect+1: error: cannot take size/alignment of function [144] */
+unsigned long size_unspecified_args = sizeof(int());
+/* FIXME: Must be 'of function', not 'of void'. */
+/* expect+1: error: cannot take size/alignment of void [146] */
+unsigned long size_prototype_void = sizeof(int(void));
+/* TODO: error: cannot take size/alignment of function [144] */
+unsigned long size_prototype_unnamed = sizeof(int(double));
+/* TODO: error: cannot take size/alignment of function [144] */
+unsigned long size_prototype_named = sizeof(int(double dbl));

Index: src/tests/usr.bin/xlint/lint1/msg_155.c
diff -u src/tests/usr.bin/xlint/lint1/msg_155.c:1.9 src/tests/usr.bin/xlint/lint1/msg_155.c:1.10
--- src/tests/usr.bin/xlint/lint1/msg_155.c:1.9	Wed Jun 30 14:23:50 2021
+++ src/tests/usr.bin/xlint/lint1/msg_155.c	Fri Apr  1 22:28:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_155.c,v 1.9 2021/06/30 14:23:50 rillig Exp $	*/
+/*	$NetBSD: msg_155.c,v 1.10 2022/04/01 22:28:21 rillig Exp $	*/
 # 3 "msg_155.c"
 
 // Test for message: passing '%s' to incompatible '%s', arg #%d [155]
@@ -9,8 +9,8 @@ void c99_6_7_6_example_b(int *);
 void c99_6_7_6_example_c(int *[3]);
 void c99_6_7_6_example_d(int (*)[3]);
 void c99_6_7_6_example_e(int (*)[*]);
-// FIXME: assertion "sym->s_type != NULL" failed in declare_argument at decl.c:2436
-// void c99_6_7_6_example_f(int *());
+/* Wrong type before decl.c 1.256 from 2022-04-01. */
+void c99_6_7_6_example_f(int *());
 void c99_6_7_6_example_g(int (*)(void));
 void c99_6_7_6_example_h(int (*const[])(unsigned int, ...));
 
@@ -37,8 +37,8 @@ provoke_error_messages(struct incompatib
 	/* expect+1: 'pointer to array[unknown_size] of int' */
 	c99_6_7_6_example_e(arg);
 
-	/* TODO: C99 says 'function with no parameter specification returning a pointer to int' */
-	/* expect+1: function 'c99_6_7_6_example_f' implicitly declared */
+	/* Wrong type before decl.c 1.256 from 2022-04-01. */
+	/* expect+1: 'pointer to function() returning pointer to int' */
 	c99_6_7_6_example_f(arg);
 
 	/* expect+1: 'pointer to function(void) returning int' */

Index: src/tests/usr.bin/xlint/lint1/msg_155.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_155.exp:1.11 src/tests/usr.bin/xlint/lint1/msg_155.exp:1.12
--- src/tests/usr.bin/xlint/lint1/msg_155.exp:1.11	Sun Aug 29 17:01:27 2021
+++ src/tests/usr.bin/xlint/lint1/msg_155.exp	Fri Apr  1 22:28:21 2022
@@ -3,7 +3,7 @@ msg_155.c(28): warning: passing 'struct 
 msg_155.c(32): warning: passing 'struct incompatible' to incompatible 'pointer to pointer to int', arg #1 [155]
 msg_155.c(35): warning: passing 'struct incompatible' to incompatible 'pointer to array[3] of int', arg #1 [155]
 msg_155.c(38): warning: passing 'struct incompatible' to incompatible 'pointer to array[unknown_size] of int', arg #1 [155]
-msg_155.c(42): error: function 'c99_6_7_6_example_f' implicitly declared to return int [215]
+msg_155.c(42): warning: passing 'struct incompatible' to incompatible 'pointer to function() returning pointer to int', arg #1 [155]
 msg_155.c(45): warning: passing 'struct incompatible' to incompatible 'pointer to function(void) returning int', arg #1 [155]
 msg_155.c(48): warning: passing 'struct incompatible' to incompatible 'pointer to const pointer to function(unsigned int, ...) returning int', arg #1 [155]
 msg_155.c(69): warning: passing 'enum Day' to incompatible 'struct incompatible', arg #1 [155]

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.256 src/usr.bin/xlint/lint1/decl.c:1.257
--- src/usr.bin/xlint/lint1/decl.c:1.256	Fri Apr  1 22:07:23 2022
+++ src/usr.bin/xlint/lint1/decl.c	Fri Apr  1 22:28:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.256 2022/04/01 22:07:23 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.257 2022/04/01 22:28:21 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.256 2022/04/01 22:07:23 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.257 2022/04/01 22:28:21 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1399,6 +1399,8 @@ add_function(sym_t *decl, sym_t *args)
 	 * Returning decl leads to the wrong function types in msg_347.
 	 */
 	tpp = &decl->s_type;
+	if (*tpp == NULL)
+		decl->s_type = dcs->d_next->d_type;
 	while (*tpp != NULL && *tpp != dcs->d_next->d_type)
 		/*
 		 * XXX: accessing INT->t_subt feels strange, even though it

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.412 src/usr.bin/xlint/lint1/tree.c:1.413
--- src/usr.bin/xlint/lint1/tree.c:1.412	Fri Apr  1 01:06:26 2022
+++ src/usr.bin/xlint/lint1/tree.c	Fri Apr  1 22:28:21 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.412 2022/04/01 01:06:26 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.413 2022/04/01 22:28:21 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.412 2022/04/01 01:06:26 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.413 2022/04/01 22:28:21 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3578,16 +3578,9 @@ cast(tnode_t *tn, type_t *tp)
 	if (tn == NULL)
 		return NULL;
 
-	/*
-	 * XXX: checking for tp == NULL is only a quick fix for PR 22119.
-	 *  The proper fix needs to be investigated properly.
-	 *  See d_pr_22119.c for how to get here.
-	 */
-	if (tp == NULL)
-		return NULL;
-
 	tn = cconv(tn);
 
+	lint_assert(tp != NULL);
 	nt = tp->t_tspec;
 	ot = tn->tn_type->t_tspec;
 

Reply via email to