Module Name: src
Committed By: rillig
Date: Sun Sep 12 17:30:53 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_347.c msg_347.exp
src/usr.bin/xlint/lint1: decl.c
Log Message:
lint: track down wrong function type in abstract type
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_347.c \
src/tests/usr.bin/xlint/lint1/msg_347.exp
cvs rdiff -u -r1.236 -r1.237 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.1 src/tests/usr.bin/xlint/lint1/msg_347.c:1.2
--- src/tests/usr.bin/xlint/lint1/msg_347.c:1.1 Sun Sep 12 16:28:45 2021
+++ src/tests/usr.bin/xlint/lint1/msg_347.c Sun Sep 12 17:30:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_347.c,v 1.1 2021/09/12 16:28:45 rillig Exp $ */
+/* $NetBSD: msg_347.c,v 1.2 2021/09/12 17:30:53 rillig Exp $ */
# 3 "msg_347.c"
// Test for message: redeclaration of '%s' with type '%s', expected '%s' [347]
@@ -27,3 +27,17 @@
void function_parameter(void *, double *(void *, int));
/* expect+1: error: redeclaration of 'function_parameter' with type 'function(pointer to void, pointer to function(pointer to void, int) returning pointer to double) returning void', expected 'function(pointer to void, int) returning void' [347] */
void function_parameter(void *fs, double *func(void *, int));
+
+
+/* expect+1: warning: struct last_arg never defined [233] */
+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.
+ */
+/* 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 *));
Index: src/tests/usr.bin/xlint/lint1/msg_347.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_347.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_347.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_347.exp:1.1 Sun Sep 12 16:28:45 2021
+++ src/tests/usr.bin/xlint/lint1/msg_347.exp Sun Sep 12 17:30:53 2021
@@ -1,2 +1,6 @@
msg_347.c(29): error: redeclaration of 'function_parameter' with type 'function(pointer to void, pointer to function(pointer to void, int) returning pointer to double) returning void', expected 'function(pointer to void, int) returning void' [347]
msg_347.c(27): previous declaration of function_parameter [260]
+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(33): warning: struct last_arg never defined [233]
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.236 src/usr.bin/xlint/lint1/decl.c:1.237
--- src/usr.bin/xlint/lint1/decl.c:1.236 Sun Sep 12 16:28:45 2021
+++ src/usr.bin/xlint/lint1/decl.c Sun Sep 12 17:30:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.236 2021/09/12 16:28:45 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.237 2021/09/12 17:30:53 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.236 2021/09/12 16:28:45 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.237 2021/09/12 17:30:53 rillig Exp $");
#endif
#include <sys/param.h>
@@ -1398,11 +1398,19 @@ add_function(sym_t *decl, sym_t *args)
dcs->d_next->d_func_args = args;
}
+ /*
+ * XXX: What is this code doing on a semantic level, and why?
+ * Returning decl leads to the wrong function types in msg_347.
+ */
tpp = &decl->s_type;
while (*tpp != NULL && *tpp != dcs->d_next->d_type)
+ /*
+ * XXX: accessing INT->t_subt feels strange, even though it
+ * may even be guaranteed to be NULL.
+ */
tpp = &(*tpp)->t_subt;
if (*tpp == NULL)
- return decl;
+ return decl; /* see msg_347 */
*tpp = tp = getblk(sizeof(*tp));
tp->t_tspec = FUNC;