tests/lint: add more tests for direct-abstract-declarator

Lint's grammar in this area differs a lot from the grammar in C99. GCC's
parser has a long comment about special cases in this area.  It's tricky
to even parse these type names correctly, let alone assign them the
correct types, that's why it needs more tests before trying to refactor
that code.
This commit is contained in:
rillig 2021-09-13 22:09:06 +00:00
parent 41353bd25a
commit 697a010bb5
4 changed files with 79 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1124 2021/09/12 16:28:44 rillig Exp $
# $NetBSD: mi,v 1.1125 2021/09/13 22:09:06 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -6230,6 +6230,8 @@
./usr/tests/usr.bin/xlint/lint1/decl.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/decl_arg.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/decl_arg.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/decl_direct_abstract.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/decl_enum.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/decl_enum.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/decl_enum_c90.c tests-usr.bin-tests compattestfile,atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.111 2021/09/12 16:28:45 rillig Exp $
# $NetBSD: Makefile,v 1.112 2021/09/13 22:09:06 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 347 # see lint1/err.c
@ -122,6 +122,8 @@ FILES+= decl.c
FILES+= decl.exp
FILES+= decl_arg.c
FILES+= decl_arg.exp
FILES+= decl_direct_abstract.c
FILES+= decl_direct_abstract.exp
FILES+= decl_enum.c
FILES+= decl_enum.exp
FILES+= decl_enum_c90.c

View File

@ -0,0 +1,63 @@
/* $NetBSD: decl_direct_abstract.c,v 1.1 2021/09/13 22:09:06 rillig Exp $ */
# 3 "decl_direct_abstract.c"
/*
* Test parsing of direct-abstract-declarator (C99 6.7.6), which are a tricky
* part of the C standard since they require lookahead and are so complicated
* that GCC's parser dedicates 34 lines of comments to this topic.
*
* See msg_155.c.
*/
/*
* The following tests do not use int, to avoid confusion with the implicit
* return type.
*/
char func0001(short (*)(long));
/* GCC says 'char (*)(short int (*)(long int))' */
/* Clang says 'char (short (*)(long))' */
/* cdecl says 'function (pointer to function (long) returning short) returning char' */
/* expect+1: 'pointer to function(pointer to function(long) returning short) returning char' */
double type_of_func0001 = func0001;
char func0002(short *(long));
/* GCC says 'char (*)(short int * (*)(long int))' */
/* Clang says 'char (short *(*)(long))' */
/* cdecl says 'syntax error' */
/* FIXME: lint is wrong, it discards the 'short *' */
/* expect+1: 'pointer to function(long) returning char' */
double type_of_func0002 = func0002;
void c99_6_7_6_example_a(int);
void c99_6_7_6_example_b(int *);
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 (*)[*]);
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, ...));
struct incompatible {
int member;
} x;
/* expect+1: 'pointer to function(int) returning void' */
double type_of_c99_6_7_6_example_a = c99_6_7_6_example_a;
/* expect+1: 'pointer to function(pointer to int) returning void' */
double type_of_c99_6_7_6_example_b = c99_6_7_6_example_b;
/* expect+1: 'pointer to function(pointer to pointer to int) returning void' */
double type_of_c99_6_7_6_example_c = c99_6_7_6_example_c;
/* expect+1: 'pointer to function(pointer to array[3] of int) returning void' */
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' */
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;
/* expect+1: 'pointer to function(pointer to const pointer to function(unsigned int, ...) returning int) returning void' */
double type_of_c99_6_7_6_example_h = c99_6_7_6_example_h;

View File

@ -0,0 +1,10 @@
decl_direct_abstract.c(23): error: cannot initialize 'double' from 'pointer to function(pointer to function(long) returning short) returning char' [185]
decl_direct_abstract.c(32): error: cannot initialize 'double' from 'pointer to function(long) returning char' [185]
decl_direct_abstract.c(48): error: cannot initialize 'double' from 'pointer to function(int) returning void' [185]
decl_direct_abstract.c(50): error: cannot initialize 'double' from 'pointer to function(pointer to int) returning void' [185]
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(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]