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: add type details to message about ...
details: https://anonhg.NetBSD.org/src/rev/3d55450f7ae4
branches: trunk
changeset: 364637:3d55450f7ae4
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Apr 01 23:16:31 2022 +0000
description:
lint: add type details to message about 'sizeof(function)'
The code in add_function is severely broken, it mixes up the return type
of the function with the argument types. For now, at least show the
guessed type in the diagnostic, to allow human readers quickly spot the
bug.
Extend the test cases in decl_direct_abstract.c to show that the
behavior differs unreasonably if the first parameter of the function is
equal to its return type.
diffstat:
tests/usr.bin/xlint/lint1/decl_direct_abstract.c | 115 ++++++++++++++++++++-
tests/usr.bin/xlint/lint1/decl_direct_abstract.exp | 46 ++++++++-
tests/usr.bin/xlint/lint1/msg_012.c | 4 +-
tests/usr.bin/xlint/lint1/msg_012.exp | 2 +-
tests/usr.bin/xlint/lint1/msg_014.c | 4 +-
tests/usr.bin/xlint/lint1/msg_014.exp | 2 +-
tests/usr.bin/xlint/lint1/msg_144.c | 7 +-
tests/usr.bin/xlint/lint1/msg_144.exp | 2 +-
tests/usr.bin/xlint/lint1/parse_type_name.c | 4 +-
tests/usr.bin/xlint/lint1/parse_type_name.exp | 2 +-
usr.bin/xlint/lint1/err.c | 6 +-
usr.bin/xlint/lint1/tree.c | 12 +-
12 files changed, 179 insertions(+), 27 deletions(-)
diffs (truncated from 351 to 300 lines):
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/decl_direct_abstract.c
--- a/tests/usr.bin/xlint/lint1/decl_direct_abstract.c Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_direct_abstract.c Fri Apr 01 23:16:31 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl_direct_abstract.c,v 1.5 2022/04/01 22:28:21 rillig Exp $ */
+/* $NetBSD: decl_direct_abstract.c,v 1.6 2022/04/01 23:16:32 rillig Exp $ */
# 3 "decl_direct_abstract.c"
/*
@@ -77,12 +77,119 @@
/* 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] */
+/* expect+1: error: cannot take size/alignment of function type 'function() returning int' [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] */
+/* TODO: error: cannot take size/alignment of function type 'function(double) returning int' [144] */
unsigned long size_prototype_unnamed = sizeof(int(double));
-/* TODO: error: cannot take size/alignment of function [144] */
+/* TODO: error: cannot take size/alignment of function type 'function(double) returning int' [144] */
unsigned long size_prototype_named = sizeof(int(double dbl));
+
+/* expect+2: error: cannot take size/alignment of function type 'function() returning int' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int size_unspecified_args_return_int[-1000 - (int)sizeof(int())];
+
+/* expect+2: error: cannot take size/alignment of function type 'function() returning char' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int size_unspecified_args_return_char[-1000 - (int)sizeof(char())];
+
+/* FIXME: 'of void' must be 'of function'. */
+/* expect+2: error: cannot take size/alignment of void [146] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int size_prototype_void_return_int[-1000 - (int)sizeof(int(void))];
+
+/* FIXME: 'of void' must be 'of function'. */
+/* expect+2: error: cannot take size/alignment of void [146] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int size_prototype_void_return_double[-1000 - (int)sizeof(double(void))];
+
+/* expect+1: error: negative array dimension (-1008) [20] */
+int size_prototype_unnamed_return_int[-1000 - (int)sizeof(int(double))];
+
+/* expect+1: error: negative array dimension (-1008) [20] */
+int size_prototype_unnamed_return_pchar[-1000 - (int)sizeof(char *(double))];
+
+/* expect+1: error: negative array dimension (-1008) [20] */
+int size_prototype_named_return_int[-1000 - (int)sizeof(int(double dbl))];
+
+/* expect+1: error: negative array dimension (-1008) [20] */
+int size_prototype_named_return_pppchar[-1000 - (int)sizeof(char ***(double dbl))];
+
+
+typedef struct {
+ char a[1];
+} a01;
+
+typedef struct {
+ char a[4];
+} a04;
+
+typedef struct {
+ char a[8];
+} a08;
+
+typedef struct {
+ char a[32];
+} a32;
+
+/* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a01' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int unspecified_args_return_01[-1000 - (int)sizeof(a01())];
+/* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a04' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int unspecified_args_return_04[-1000 - (int)sizeof(a04())];
+/* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a08' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int unspecified_args_return_08[-1000 - (int)sizeof(a08())];
+/* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a32' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int unspecified_args_return_32[-1000 - (int)sizeof(a32())];
+
+/* expect+2: error: cannot take size/alignment of void [146] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int prototype_void_return_01[-1000 - (int)sizeof(a01(void))];
+/* expect+2: error: cannot take size/alignment of void [146] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int prototype_void_return_04[-1000 - (int)sizeof(a04(void))];
+/* expect+2: error: cannot take size/alignment of void [146] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int prototype_void_return_08[-1000 - (int)sizeof(a08(void))];
+/* expect+2: error: cannot take size/alignment of void [146] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int prototype_void_return_32[-1000 - (int)sizeof(a32(void))];
+
+/* expect+1: error: negative array dimension (-1001) [20] */
+int prototype_unnamed_01_return_32[-1000 - (int)sizeof(a32(a01))];
+/* expect+1: error: negative array dimension (-1004) [20] */
+int prototype_unnamed_04_return_32[-1000 - (int)sizeof(a32(a04))];
+/* expect+1: error: negative array dimension (-1008) [20] */
+int prototype_unnamed_08_return_32[-1000 - (int)sizeof(a32(a08))];
+/* expect+2: error: cannot take size/alignment of function type 'function(struct typedef a32) returning struct typedef a32' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int prototype_unnamed_32_return_32[-1000 - (int)sizeof(a32(a32))];
+
+/* expect+1: error: negative array dimension (-1032) [20] */
+int prototype_unnamed_32_return_01[-1000 - (int)sizeof(a01(a32))];
+/* expect+1: error: negative array dimension (-1032) [20] */
+int prototype_unnamed_32_return_04[-1000 - (int)sizeof(a04(a32))];
+/* expect+1: error: negative array dimension (-1032) [20] */
+int prototype_unnamed_32_return_08[-1000 - (int)sizeof(a08(a32))];
+
+/* expect+1: error: negative array dimension (-1001) [20] */
+int prototype_named_01_return_32[-1000 - (int)sizeof(a32(a01 arg))];
+/* expect+1: error: negative array dimension (-1004) [20] */
+int prototype_named_04_return_32[-1000 - (int)sizeof(a32(a04 arg))];
+/* expect+1: error: negative array dimension (-1008) [20] */
+int prototype_named_08_return_32[-1000 - (int)sizeof(a32(a08 arg))];
+/* expect+2: error: cannot take size/alignment of function type 'function(struct typedef a32) returning struct typedef a32' [144] */
+/* expect+1: error: negative array dimension (-1000) [20] */
+int prototype_named_32_return_32[-1000 - (int)sizeof(a32(a32 arg))];
+
+/* expect+1: error: negative array dimension (-1032) [20] */
+int prototype_named_32_return_01[-1000 - (int)sizeof(a01(a32 arg))];
+/* expect+1: error: negative array dimension (-1032) [20] */
+int prototype_named_32_return_04[-1000 - (int)sizeof(a04(a32 arg))];
+/* expect+1: error: negative array dimension (-1032) [20] */
+int prototype_named_32_return_08[-1000 - (int)sizeof(a08(a32 arg))];
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/decl_direct_abstract.exp
--- a/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_direct_abstract.exp Fri Apr 01 23:16:31 2022 +0000
@@ -10,5 +10,49 @@
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(81): error: cannot take size/alignment of function type 'function() returning int' [144]
decl_direct_abstract.c(84): error: cannot take size/alignment of void [146]
+decl_direct_abstract.c(92): error: cannot take size/alignment of function type 'function() returning int' [144]
+decl_direct_abstract.c(92): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(96): error: cannot take size/alignment of function type 'function() returning char' [144]
+decl_direct_abstract.c(96): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(101): error: cannot take size/alignment of void [146]
+decl_direct_abstract.c(101): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(106): error: cannot take size/alignment of void [146]
+decl_direct_abstract.c(106): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(109): error: negative array dimension (-1008) [20]
+decl_direct_abstract.c(112): error: negative array dimension (-1008) [20]
+decl_direct_abstract.c(115): error: negative array dimension (-1008) [20]
+decl_direct_abstract.c(118): error: negative array dimension (-1008) [20]
+decl_direct_abstract.c(139): error: cannot take size/alignment of function type 'function() returning struct typedef a01' [144]
+decl_direct_abstract.c(139): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(142): error: cannot take size/alignment of function type 'function() returning struct typedef a04' [144]
+decl_direct_abstract.c(142): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(145): error: cannot take size/alignment of function type 'function() returning struct typedef a08' [144]
+decl_direct_abstract.c(145): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(148): error: cannot take size/alignment of function type 'function() returning struct typedef a32' [144]
+decl_direct_abstract.c(148): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(152): error: cannot take size/alignment of void [146]
+decl_direct_abstract.c(152): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(155): error: cannot take size/alignment of void [146]
+decl_direct_abstract.c(155): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(158): error: cannot take size/alignment of void [146]
+decl_direct_abstract.c(158): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(161): error: cannot take size/alignment of void [146]
+decl_direct_abstract.c(161): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(164): error: negative array dimension (-1001) [20]
+decl_direct_abstract.c(166): error: negative array dimension (-1004) [20]
+decl_direct_abstract.c(168): error: negative array dimension (-1008) [20]
+decl_direct_abstract.c(171): error: cannot take size/alignment of function type 'function(struct typedef a32) returning struct typedef a32' [144]
+decl_direct_abstract.c(171): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(174): error: negative array dimension (-1032) [20]
+decl_direct_abstract.c(176): error: negative array dimension (-1032) [20]
+decl_direct_abstract.c(178): error: negative array dimension (-1032) [20]
+decl_direct_abstract.c(181): error: negative array dimension (-1001) [20]
+decl_direct_abstract.c(183): error: negative array dimension (-1004) [20]
+decl_direct_abstract.c(185): error: negative array dimension (-1008) [20]
+decl_direct_abstract.c(188): error: cannot take size/alignment of function type 'function(struct typedef a32) returning struct typedef a32' [144]
+decl_direct_abstract.c(188): error: negative array dimension (-1000) [20]
+decl_direct_abstract.c(191): error: negative array dimension (-1032) [20]
+decl_direct_abstract.c(193): error: negative array dimension (-1032) [20]
+decl_direct_abstract.c(195): error: negative array dimension (-1032) [20]
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/msg_012.c
--- a/tests/usr.bin/xlint/lint1/msg_012.c Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_012.c Fri Apr 01 23:16:31 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: msg_012.c,v 1.3 2021/08/26 19:23:25 rillig Exp $ */
+/* $NetBSD: msg_012.c,v 1.4 2022/04/01 23:16:32 rillig Exp $ */
# 3 "msg_012.c"
// Test for message: compiler takes size of function [12]
@@ -7,6 +7,6 @@
unsigned long
example(void)
{
- /* expect+1: error: cannot take size/alignment of function [144] */
+ /* expect+1: error: cannot take size/alignment of function type 'function(void) returning unsigned long' [144] */
return sizeof(example);
}
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/msg_012.exp
--- a/tests/usr.bin/xlint/lint1/msg_012.exp Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_012.exp Fri Apr 01 23:16:31 2022 +0000
@@ -1,1 +1,1 @@
-msg_012.c(11): error: cannot take size/alignment of function [144]
+msg_012.c(11): error: cannot take size/alignment of function type 'function(void) returning unsigned long' [144]
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/msg_014.c
--- a/tests/usr.bin/xlint/lint1/msg_014.c Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_014.c Fri Apr 01 23:16:31 2022 +0000
@@ -1,11 +1,11 @@
-/* $NetBSD: msg_014.c,v 1.3 2021/08/26 19:23:25 rillig Exp $ */
+/* $NetBSD: msg_014.c,v 1.4 2022/04/01 23:16:32 rillig Exp $ */
# 3 "msg_014.c"
// Test for message: compiler takes alignment of function [14]
typedef void function(void);
-/* expect+1: error: cannot take size/alignment of function [144] */
+/* expect+1: error: cannot take size/alignment of function type 'function(void) returning void' [144] */
unsigned long alignof_function = __alignof__(function);
TODO: "Add example code that triggers the above message." /* expect: 249 */
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/msg_014.exp
--- a/tests/usr.bin/xlint/lint1/msg_014.exp Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_014.exp Fri Apr 01 23:16:31 2022 +0000
@@ -1,2 +1,2 @@
-msg_014.c(9): error: cannot take size/alignment of function [144]
+msg_014.c(9): error: cannot take size/alignment of function type 'function(void) returning void' [144]
msg_014.c(11): error: syntax error ':' [249]
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/msg_144.c
--- a/tests/usr.bin/xlint/lint1/msg_144.c Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_144.c Fri Apr 01 23:16:31 2022 +0000
@@ -1,10 +1,11 @@
-/* $NetBSD: msg_144.c,v 1.4 2021/04/02 12:16:50 rillig Exp $ */
+/* $NetBSD: msg_144.c,v 1.5 2022/04/01 23:16:32 rillig Exp $ */
# 3 "msg_144.c"
-// Test for message: cannot take size/alignment of function [144]
+// Test for message: cannot take size/alignment of function type '%s' [144]
unsigned long
example(void)
{
- return sizeof(example); /* expect: 144 */
+ /* expect+1: error: cannot take size/alignment of function type 'function(void) returning unsigned long' [144] */
+ return sizeof(example);
}
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/msg_144.exp
--- a/tests/usr.bin/xlint/lint1/msg_144.exp Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_144.exp Fri Apr 01 23:16:31 2022 +0000
@@ -1,1 +1,1 @@
-msg_144.c(9): error: cannot take size/alignment of function [144]
+msg_144.c(10): error: cannot take size/alignment of function type 'function(void) returning unsigned long' [144]
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/parse_type_name.c
--- a/tests/usr.bin/xlint/lint1/parse_type_name.c Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/parse_type_name.c Fri Apr 01 23:16:31 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse_type_name.c,v 1.7 2021/07/25 22:03:42 rillig Exp $ */
+/* $NetBSD: parse_type_name.c,v 1.8 2022/04/01 23:16:32 rillig Exp $ */
# 3 "parse_type_name.c"
/*
@@ -48,7 +48,7 @@
sink(sizeof(int **[3]));
/* cover 'T_TYPEOF cast_expression' */
- /* expect+1: error: cannot take size/alignment of function [144] */
+ /* expect+1: error: cannot take size/alignment of function type 'function(int) returning int' [144] */
sink(sizeof(int(typeof(12345))));
}
diff -r e1f7f2b857ca -r 3d55450f7ae4 tests/usr.bin/xlint/lint1/parse_type_name.exp
--- a/tests/usr.bin/xlint/lint1/parse_type_name.exp Fri Apr 01 22:28:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/parse_type_name.exp Fri Apr 01 23:16:31 2022 +0000
@@ -1,4 +1,4 @@
-parse_type_name.c(52): error: cannot take size/alignment of function [144]
+parse_type_name.c(52): error: cannot take size/alignment of function type 'function(int) returning int' [144]
parse_type_name.c(72): error: null dimension [17]
parse_type_name.c(76): error: null dimension [17]
parse_type_name.c(118): error: syntax error 'goto' [249]
diff -r e1f7f2b857ca -r 3d55450f7ae4 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Fri Apr 01 22:28:21 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Fri Apr 01 23:16:31 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.154 2022/04/01 22:07:23 rillig Exp $ */
+/* $NetBSD: err.c,v 1.155 2022/04/01 23:16:31 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.154 2022/04/01 22:07:23 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.155 2022/04/01 23:16:31 rillig Exp $");
#endif
Home |
Main Index |
Thread Index |
Old Index