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: track down wrong function type in ...



details:   https://anonhg.NetBSD.org/src/rev/8f621ddf0431
branches:  trunk
changeset: 1023536:8f621ddf0431
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 12 17:30:53 2021 +0000

description:
lint: track down wrong function type in abstract type

diffstat:

 tests/usr.bin/xlint/lint1/msg_347.c   |  16 +++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_347.exp |   4 ++++
 usr.bin/xlint/lint1/decl.c            |  14 +++++++++++---
 3 files changed, 30 insertions(+), 4 deletions(-)

diffs (76 lines):

diff -r 6dc4944c7511 -r 8f621ddf0431 tests/usr.bin/xlint/lint1/msg_347.c
--- a/tests/usr.bin/xlint/lint1/msg_347.c       Sun Sep 12 16:28:44 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_347.c       Sun Sep 12 17:30:53 2021 +0000
@@ -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 *));
diff -r 6dc4944c7511 -r 8f621ddf0431 tests/usr.bin/xlint/lint1/msg_347.exp
--- a/tests/usr.bin/xlint/lint1/msg_347.exp     Sun Sep 12 16:28:44 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_347.exp     Sun Sep 12 17:30:53 2021 +0000
@@ -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]
diff -r 6dc4944c7511 -r 8f621ddf0431 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Sep 12 16:28:44 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Sep 12 17:30:53 2021 +0000
@@ -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 @@
                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;



Home | Main Index | Thread Index | Old Index