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: improve determination of abstract ...
details: https://anonhg.NetBSD.org/src/rev/e1f7f2b857ca
branches: trunk
changeset: 364636:e1f7f2b857ca
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Apr 01 22:28:21 2022 +0000
description:
lint: improve determination of abstract typename
Still not perfect, but at least a step in the right direction. See
decl_direct_abstract.c for the missing edge cases.
See PR#22119.
diffstat:
tests/usr.bin/xlint/lint1/d_pr_22119.c | 4 +++-
tests/usr.bin/xlint/lint1/d_pr_22119.exp | 2 ++
tests/usr.bin/xlint/lint1/decl_direct_abstract.c | 16 +++++++++++++---
tests/usr.bin/xlint/lint1/decl_direct_abstract.exp | 4 +++-
tests/usr.bin/xlint/lint1/msg_155.c | 10 +++++-----
tests/usr.bin/xlint/lint1/msg_155.exp | 2 +-
usr.bin/xlint/lint1/decl.c | 6 ++++--
usr.bin/xlint/lint1/tree.c | 13 +++----------
8 files changed, 34 insertions(+), 23 deletions(-)
diffs (179 lines):
diff -r fcc790240901 -r e1f7f2b857ca tests/usr.bin/xlint/lint1/d_pr_22119.c
--- a/tests/usr.bin/xlint/lint1/d_pr_22119.c Fri Apr 01 22:07:23 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_pr_22119.c Fri Apr 01 22:28:21 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_pr_22119.c,v 1.3 2022/01/15 14:22:03 rillig Exp $ */
+/* $NetBSD: d_pr_22119.c,v 1.4 2022/04/01 22:28:21 rillig Exp $ */
# 3 "d_pr_22119.c"
/*
@@ -15,5 +15,7 @@
/* expect+1: error: 'p' undefined [99] */
f1 = (void (*)(void))p;
+ /* expect+2: error: function returns illegal type 'function(void) returning pointer to void' [15] */
+ /* expect+1: error: invalid cast from 'int' to 'function() returning pointer to function(void) returning pointer to void' [147] */
f1 = (void *()(void))p; /* crash before 2021-02-28 */
}
diff -r fcc790240901 -r e1f7f2b857ca tests/usr.bin/xlint/lint1/d_pr_22119.exp
--- a/tests/usr.bin/xlint/lint1/d_pr_22119.exp Fri Apr 01 22:07:23 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_pr_22119.exp Fri Apr 01 22:28:21 2022 +0000
@@ -1,1 +1,3 @@
d_pr_22119.c(17): error: 'p' undefined [99]
+d_pr_22119.c(20): error: function returns illegal type 'function(void) returning pointer to void' [15]
+d_pr_22119.c(20): error: invalid cast from 'int' to 'function() returning pointer to function(void) returning pointer to void' [147]
diff -r fcc790240901 -r e1f7f2b857ca tests/usr.bin/xlint/lint1/decl_direct_abstract.c
--- a/tests/usr.bin/xlint/lint1/decl_direct_abstract.c Fri Apr 01 22:07:23 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_direct_abstract.c Fri Apr 01 22:28:21 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl_direct_abstract.c,v 1.4 2021/09/14 19:08:40 rillig Exp $ */
+/* $NetBSD: decl_direct_abstract.c,v 1.5 2022/04/01 22:28:21 rillig Exp $ */
# 3 "decl_direct_abstract.c"
/*
@@ -54,8 +54,8 @@
double type_of_c99_6_7_6_example_d = c99_6_7_6_example_d;
/* expect+1: 'pointer to function(pointer to array[unknown_size] of int) returning void' */
double type_of_c99_6_7_6_example_e = c99_6_7_6_example_e;
-/* FIXME: see msg_155.c, msg_347.c */
-/* expect+1: 'pointer to function(void) returning void' */
+/* Wrong type before decl.c 1.256 from 2022-04-01. */
+/* expect+1: 'pointer to function(pointer to function() returning pointer to int) returning void' */
double type_of_c99_6_7_6_example_f = c99_6_7_6_example_f;
/* expect+1: 'pointer to function(pointer to function(void) returning int) returning void' */
double type_of_c99_6_7_6_example_g = c99_6_7_6_example_g;
@@ -76,3 +76,13 @@
void int_array_3_array(int[3][7]);
/* supported since cgram.y 1.363 from 2021-09-14 */
void int_array_ast_array(int[*][7]);
+
+/* expect+1: error: cannot take size/alignment of function [144] */
+unsigned long size_unspecified_args = sizeof(int());
+/* FIXME: Must be 'of function', not 'of void'. */
+/* expect+1: error: cannot take size/alignment of void [146] */
+unsigned long size_prototype_void = sizeof(int(void));
+/* TODO: error: cannot take size/alignment of function [144] */
+unsigned long size_prototype_unnamed = sizeof(int(double));
+/* TODO: error: cannot take size/alignment of function [144] */
+unsigned long size_prototype_named = sizeof(int(double dbl));
diff -r fcc790240901 -r e1f7f2b857ca tests/usr.bin/xlint/lint1/decl_direct_abstract.exp
--- a/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp Fri Apr 01 22:07:23 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp Fri Apr 01 22:28:21 2022 +0000
@@ -5,8 +5,10 @@
decl_direct_abstract.c(52): error: cannot initialize 'double' from 'pointer to function(pointer to pointer to int) returning void' [185]
decl_direct_abstract.c(54): error: cannot initialize 'double' from 'pointer to function(pointer to array[3] of int) returning void' [185]
decl_direct_abstract.c(56): error: cannot initialize 'double' from 'pointer to function(pointer to array[unknown_size] of int) returning void' [185]
-decl_direct_abstract.c(59): error: cannot initialize 'double' from 'pointer to function(void) returning void' [185]
+decl_direct_abstract.c(59): error: cannot initialize 'double' from 'pointer to function(pointer to function() returning pointer to int) returning void' [185]
decl_direct_abstract.c(61): error: cannot initialize 'double' from 'pointer to function(pointer to function(void) returning int) returning void' [185]
decl_direct_abstract.c(63): error: cannot initialize 'double' from 'pointer to function(pointer to const pointer to function(unsigned int, ...) returning int) returning void' [185]
decl_direct_abstract.c(70): error: null dimension [17]
decl_direct_abstract.c(73): error: null dimension [17]
+decl_direct_abstract.c(81): error: cannot take size/alignment of function [144]
+decl_direct_abstract.c(84): error: cannot take size/alignment of void [146]
diff -r fcc790240901 -r e1f7f2b857ca tests/usr.bin/xlint/lint1/msg_155.c
--- a/tests/usr.bin/xlint/lint1/msg_155.c Fri Apr 01 22:07:23 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_155.c Fri Apr 01 22:28:21 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_155.c,v 1.9 2021/06/30 14:23:50 rillig Exp $ */
+/* $NetBSD: msg_155.c,v 1.10 2022/04/01 22:28:21 rillig Exp $ */
# 3 "msg_155.c"
// Test for message: passing '%s' to incompatible '%s', arg #%d [155]
@@ -9,8 +9,8 @@
void c99_6_7_6_example_c(int *[3]);
void c99_6_7_6_example_d(int (*)[3]);
void c99_6_7_6_example_e(int (*)[*]);
-// FIXME: assertion "sym->s_type != NULL" failed in declare_argument at decl.c:2436
-// void c99_6_7_6_example_f(int *());
+/* Wrong type before decl.c 1.256 from 2022-04-01. */
+void c99_6_7_6_example_f(int *());
void c99_6_7_6_example_g(int (*)(void));
void c99_6_7_6_example_h(int (*const[])(unsigned int, ...));
@@ -37,8 +37,8 @@
/* expect+1: 'pointer to array[unknown_size] of int' */
c99_6_7_6_example_e(arg);
- /* TODO: C99 says 'function with no parameter specification returning a pointer to int' */
- /* expect+1: function 'c99_6_7_6_example_f' implicitly declared */
+ /* Wrong type before decl.c 1.256 from 2022-04-01. */
+ /* expect+1: 'pointer to function() returning pointer to int' */
c99_6_7_6_example_f(arg);
/* expect+1: 'pointer to function(void) returning int' */
diff -r fcc790240901 -r e1f7f2b857ca tests/usr.bin/xlint/lint1/msg_155.exp
--- a/tests/usr.bin/xlint/lint1/msg_155.exp Fri Apr 01 22:07:23 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_155.exp Fri Apr 01 22:28:21 2022 +0000
@@ -3,7 +3,7 @@
msg_155.c(32): warning: passing 'struct incompatible' to incompatible 'pointer to pointer to int', arg #1 [155]
msg_155.c(35): warning: passing 'struct incompatible' to incompatible 'pointer to array[3] of int', arg #1 [155]
msg_155.c(38): warning: passing 'struct incompatible' to incompatible 'pointer to array[unknown_size] of int', arg #1 [155]
-msg_155.c(42): error: function 'c99_6_7_6_example_f' implicitly declared to return int [215]
+msg_155.c(42): warning: passing 'struct incompatible' to incompatible 'pointer to function() returning pointer to int', arg #1 [155]
msg_155.c(45): warning: passing 'struct incompatible' to incompatible 'pointer to function(void) returning int', arg #1 [155]
msg_155.c(48): warning: passing 'struct incompatible' to incompatible 'pointer to const pointer to function(unsigned int, ...) returning int', arg #1 [155]
msg_155.c(69): warning: passing 'enum Day' to incompatible 'struct incompatible', arg #1 [155]
diff -r fcc790240901 -r e1f7f2b857ca usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Fri Apr 01 22:07:23 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c Fri Apr 01 22:28:21 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.256 2022/04/01 22:07:23 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.257 2022/04/01 22:28:21 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.256 2022/04/01 22:07:23 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.257 2022/04/01 22:28:21 rillig Exp $");
#endif
#include <sys/param.h>
@@ -1399,6 +1399,8 @@
* Returning decl leads to the wrong function types in msg_347.
*/
tpp = &decl->s_type;
+ if (*tpp == NULL)
+ decl->s_type = dcs->d_next->d_type;
while (*tpp != NULL && *tpp != dcs->d_next->d_type)
/*
* XXX: accessing INT->t_subt feels strange, even though it
diff -r fcc790240901 -r e1f7f2b857ca usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Fri Apr 01 22:07:23 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c Fri Apr 01 22:28:21 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.412 2022/04/01 01:06:26 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.413 2022/04/01 22:28:21 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.412 2022/04/01 01:06:26 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.413 2022/04/01 22:28:21 rillig Exp $");
#endif
#include <float.h>
@@ -3578,16 +3578,9 @@
if (tn == NULL)
return NULL;
- /*
- * XXX: checking for tp == NULL is only a quick fix for PR 22119.
- * The proper fix needs to be investigated properly.
- * See d_pr_22119.c for how to get here.
- */
- if (tp == NULL)
- return NULL;
-
tn = cconv(tn);
+ lint_assert(tp != NULL);
nt = tp->t_tspec;
ot = tn->tn_type->t_tspec;
Home |
Main Index |
Thread Index |
Old Index