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: continue analysis of wrong type in...
details: https://anonhg.NetBSD.org/src/rev/a6b85a9514ce
branches: trunk
changeset: 1023540:a6b85a9514ce
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Sep 13 06:11:51 2021 +0000
description:
lint: continue analysis of wrong type in abstract declaration
No functional change.
diffstat:
tests/usr.bin/xlint/lint1/msg_347.c | 27 ++++++++++++++++++++++++---
tests/usr.bin/xlint/lint1/msg_347.exp | 4 ++++
usr.bin/xlint/lint1/cgram.y | 6 ++++--
usr.bin/xlint/lint1/decl.c | 14 ++++++++++++--
4 files changed, 44 insertions(+), 7 deletions(-)
diffs (125 lines):
diff -r 1fe21af11e5d -r a6b85a9514ce tests/usr.bin/xlint/lint1/msg_347.c
--- a/tests/usr.bin/xlint/lint1/msg_347.c Mon Sep 13 05:25:27 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_347.c Mon Sep 13 06:11:51 2021 +0000
@@ -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 @@
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;
diff -r 1fe21af11e5d -r a6b85a9514ce tests/usr.bin/xlint/lint1/msg_347.exp
--- a/tests/usr.bin/xlint/lint1/msg_347.exp Mon Sep 13 05:25:27 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_347.exp Mon Sep 13 06:11:51 2021 +0000
@@ -3,4 +3,8 @@
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]
diff -r 1fe21af11e5d -r a6b85a9514ce usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Mon Sep 13 05:25:27 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Mon Sep 13 06:11:51 2021 +0000
@@ -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 @@
/* 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));
diff -r 1fe21af11e5d -r a6b85a9514ce usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Mon Sep 13 05:25:27 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Mon Sep 13 06:11:51 2021 +0000
@@ -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 @@
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;
Home |
Main Index |
Thread Index |
Old Index