lint: continue analysis of wrong type in abstract declaration

No functional change.
This commit is contained in:
rillig 2021-09-13 06:11:51 +00:00
parent c67e0c13ab
commit e6898815f6
4 changed files with 44 additions and 7 deletions

View File

@ -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 *func(void *, int));
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;

View File

@ -3,4 +3,8 @@ 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(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]

View File

@ -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));

View File

@ -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;