Module Name: src
Committed By: rillig
Date: Sun Jul 25 15:58:24 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_typeof.c gcc_typeof.exp
src/usr.bin/xlint/lint1: cgram.y
Log Message:
lint: do not parse 'typeof(0)(void)' as function call
Previously, lint tried to parse 'typeof(0)(void)' as 'typeof'
'(0)(void)', which tries to call 0 as a function.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/gcc_typeof.c \
src/tests/usr.bin/xlint/lint1/gcc_typeof.exp
cvs rdiff -u -r1.336 -r1.337 src/usr.bin/xlint/lint1/cgram.y
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/gcc_typeof.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_typeof.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_typeof.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_typeof.c:1.2 Sun Jul 25 11:19:51 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_typeof.c Sun Jul 25 15:58:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_typeof.c,v 1.2 2021/07/25 11:19:51 rillig Exp $ */
+/* $NetBSD: gcc_typeof.c,v 1.3 2021/07/25 15:58:24 rillig Exp $ */
# 3 "gcc_typeof.c"
/*
@@ -10,16 +10,7 @@
void take_double(typeof(0.0));
void take_function_double_returning_double(
- /*
- * FIXME: lint's grammar uses 'typeof cast_expression', while GCC's
- * c_parser_typeof_specifier uses 'typeof ( expression )'. The crucial
- * difference is that lint parses the following expression as 'typeof
- * ((0.0)(typeof(0.0))', that is, it tries to call the function 0.0,
- * which of course is nonsense.
- */
typeof(0.0)(
- /* FIXME: GCC can parse this */
- /* expect+1: error: syntax error 'typeof' [249] */
typeof(0.0)
)
);
@@ -32,7 +23,7 @@ cast(double(*fn)(double))
/* expect+1: warning: passing 'pointer to function(double) returning double' to incompatible 'double', arg #1 [155] */
take_double(fn);
- /* XXX: oops; GCC detects this type mismatch. probably due to the parse error. */
+ /* expect+1: warning: passing 'double' to incompatible 'pointer to function(double) returning double', arg #1 [155] */
take_function_double_returning_double(0.0);
take_function_double_returning_double(fn);
Index: src/tests/usr.bin/xlint/lint1/gcc_typeof.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_typeof.exp:1.2 src/tests/usr.bin/xlint/lint1/gcc_typeof.exp:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_typeof.exp:1.2 Sun Jul 25 11:19:51 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_typeof.exp Sun Jul 25 15:58:24 2021
@@ -1,2 +1,2 @@
-gcc_typeof.c(23): error: syntax error 'typeof' [249]
-gcc_typeof.c(33): warning: passing 'pointer to function(double) returning double' to incompatible 'double', arg #1 [155]
+gcc_typeof.c(24): warning: passing 'pointer to function(double) returning double' to incompatible 'double', arg #1 [155]
+gcc_typeof.c(27): warning: passing 'double' to incompatible 'pointer to function(double) returning double', arg #1 [155]
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.336 src/usr.bin/xlint/lint1/cgram.y:1.337
--- src/usr.bin/xlint/lint1/cgram.y:1.336 Sun Jul 25 15:48:57 2021
+++ src/usr.bin/xlint/lint1/cgram.y Sun Jul 25 15:58:24 2021
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.336 2021/07/25 15:48:57 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.337 2021/07/25 15:58:24 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.336 2021/07/25 15:48:57 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.337 2021/07/25 15:58:24 rillig Exp $");
#endif
#include <limits.h>
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
%}
-%expect 158
+%expect 156
%union {
val_t *y_val;
@@ -873,8 +873,8 @@ notype_type_specifier: /* see C99 6.7.2
T_TYPE {
$$ = gettyp($1);
}
- | T_TYPEOF cast_expression { /* GCC extension */
- $$ = $2->tn_type;
+ | T_TYPEOF T_LPAREN expression T_RPAREN { /* GCC extension */
+ $$ = $3->tn_type;
}
| struct_or_union_specifier {
end_declaration_level();