Module Name:    src
Committed By:   rillig
Date:           Mon Sep 13 06:11:51 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_347.c msg_347.exp
        src/usr.bin/xlint/lint1: cgram.y decl.c

Log Message:
lint: continue analysis of wrong type in abstract declaration

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_347.c \
    src/tests/usr.bin/xlint/lint1/msg_347.exp
cvs rdiff -u -r1.361 -r1.362 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.239 -r1.240 src/usr.bin/xlint/lint1/decl.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_347.c
diff -u src/tests/usr.bin/xlint/lint1/msg_347.c:1.2 src/tests/usr.bin/xlint/lint1/msg_347.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_347.c:1.2	Sun Sep 12 17:30:53 2021
+++ src/tests/usr.bin/xlint/lint1/msg_347.c	Mon Sep 13 06:11:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_347.c,v 1.2 2021/09/12 17:30:53 rillig Exp $	*/
+/*	$NetBSD: msg_347.c,v 1.3 2021/09/13 06:11:51 rillig Exp $	*/
 # 3 "msg_347.c"
 
 // Test for message: redeclaration of '%s' with type '%s', expected '%s' [347]
@@ -33,11 +33,32 @@ void function_parameter(void *fs, double
 struct last_arg;
 /*
  * FIXME: The following error is completely wrong.
- * There is no argument that has 'struct last_arg', there are only pointers
- * to it.
+ *  There is no argument that has 'struct last_arg', there are only pointers
+ *  to it.
  */
 /* expect+2: error: '<unnamed>' has incomplete type 'incomplete struct last_arg' [31] */
 /* expect+1: previous declaration of last_arg_struct [260] */
 void last_arg_struct(double, double *(struct last_arg *));
 /* expect+1: error: redeclaration of 'last_arg_struct' with type 'function(double, pointer to function(pointer to incomplete struct last_arg) returning pointer to double) returning void', expected 'function(double, incomplete struct last_arg) returning void' [347] */
 void last_arg_struct(double d, double *fn(struct last_arg *));
+
+
+struct last_param {
+	int member;
+};
+
+/* expect+1: previous declaration of last_param [260] */
+void last_param(double, double *(struct last_param));
+
+/*
+ * FIXME: The type of last_param is completely wrong.  The second parameter
+ *  must be a function, not a struct.
+ */
+/* expect+1: error: cannot initialize 'double' from 'pointer to function(double, struct last_param) returning void' [185] */
+double reveal_type_of_last_param_abstract = last_param;
+
+/* expect+1: error: redeclaration of 'last_param' with type 'function(double, pointer to function(struct last_param) returning pointer to double) returning void', expected 'function(double, struct last_param) returning void' [347] */
+void last_param(double d, double *fn(struct last_param));
+
+/* expect+1: error: cannot initialize 'double' from 'pointer to function(double, pointer to function(struct last_param) returning pointer to double) returning void' [185] */
+double reveal_type_of_last_param_named = last_param;
Index: src/tests/usr.bin/xlint/lint1/msg_347.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_347.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_347.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_347.exp:1.2	Sun Sep 12 17:30:53 2021
+++ src/tests/usr.bin/xlint/lint1/msg_347.exp	Mon Sep 13 06:11:51 2021
@@ -3,4 +3,8 @@ msg_347.c(27): previous declaration of f
 msg_347.c(41): error: '<unnamed>' has incomplete type 'incomplete struct last_arg' [31]
 msg_347.c(43): error: redeclaration of 'last_arg_struct' with type 'function(double, pointer to function(pointer to incomplete struct last_arg) returning pointer to double) returning void', expected 'function(double, incomplete struct last_arg) returning void' [347]
 msg_347.c(41): previous declaration of last_arg_struct [260]
+msg_347.c(58): error: cannot initialize 'double' from 'pointer to function(double, struct last_param) returning void' [185]
+msg_347.c(61): error: redeclaration of 'last_param' with type 'function(double, pointer to function(struct last_param) returning pointer to double) returning void', expected 'function(double, struct last_param) returning void' [347]
+msg_347.c(51): previous declaration of last_param [260]
+msg_347.c(64): error: cannot initialize 'double' from 'pointer to function(double, pointer to function(struct last_param) returning pointer to double) returning void' [185]
 msg_347.c(33): warning: struct last_arg never defined [233]

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.361 src/usr.bin/xlint/lint1/cgram.y:1.362
--- src/usr.bin/xlint/lint1/cgram.y:1.361	Fri Sep 10 20:02:50 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Mon Sep 13 06:11:51 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.361 2021/09/10 20:02:50 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.362 2021/09/13 06:11:51 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.361 2021/09/10 20:02:50 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.362 2021/09/13 06:11:51 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1403,12 +1403,14 @@ abstract_declarator:
 
 /* K&R ---, C90 ???, C99 6.7.6, C11 6.7.7 */
 direct_abstract_declarator:
+	/* TODO: sort rules according to C99 */
 	  T_LPAREN abstract_declarator T_RPAREN {
 		$$ = $2;
 	  }
 	| T_LBRACK T_RBRACK {
 		$$ = add_array(abstract_name(), false, 0);
 	  }
+	/* TODO: T_LBRACK T_ASTERISK T_RBRACK; see below */
 	| T_LBRACK array_size T_RBRACK {
 		$$ = add_array(abstract_name(), true,
 		    to_int_constant($2, false));

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.239 src/usr.bin/xlint/lint1/decl.c:1.240
--- src/usr.bin/xlint/lint1/decl.c:1.239	Mon Sep 13 05:25:27 2021
+++ src/usr.bin/xlint/lint1/decl.c	Mon Sep 13 06:11:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.239 2021/09/13 05:25:27 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.240 2021/09/13 06:11:51 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.239 2021/09/13 05:25:27 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.240 2021/09/13 06:11:51 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -2867,6 +2867,16 @@ abstract_name(void)
 	if (dcs->d_ctx == PROTO_ARG)
 		sym->s_arg = true;
 
+	/*
+	 * At this point, dcs->d_type contains only the basic type.  That
+	 * type will be updated later, adding pointers, arrays and functions
+	 * as necessary.
+	 */
+	/*
+	 * XXX: This is not the correct type.  For example in msg_347, it is
+	 * the type of the last prototype parameter, but it should rather be
+	 * the return type of the function.
+	 */
 	sym->s_type = dcs->d_type;
 	dcs->d_redeclared_symbol = NULL;
 	dcs->d_vararg = false;

Reply via email to