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: do not parse 'typeof(0)(void)' as ...



details:   https://anonhg.NetBSD.org/src/rev/ba85a2db43e8
branches:  trunk
changeset: 1022573:ba85a2db43e8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jul 25 15:58:24 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/gcc_typeof.c   |  13 ++-----------
 tests/usr.bin/xlint/lint1/gcc_typeof.exp |   4 ++--
 usr.bin/xlint/lint1/cgram.y              |  10 +++++-----
 3 files changed, 9 insertions(+), 18 deletions(-)

diffs (82 lines):

diff -r f33d8be08423 -r ba85a2db43e8 tests/usr.bin/xlint/lint1/gcc_typeof.c
--- a/tests/usr.bin/xlint/lint1/gcc_typeof.c    Sun Jul 25 15:51:32 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_typeof.c    Sun Jul 25 15:58:24 2021 +0000
@@ -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 @@
        /* 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);
diff -r f33d8be08423 -r ba85a2db43e8 tests/usr.bin/xlint/lint1/gcc_typeof.exp
--- a/tests/usr.bin/xlint/lint1/gcc_typeof.exp  Sun Jul 25 15:51:32 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_typeof.exp  Sun Jul 25 15:58:24 2021 +0000
@@ -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]
diff -r f33d8be08423 -r ba85a2db43e8 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sun Jul 25 15:51:32 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sun Jul 25 15:58:24 2021 +0000
@@ -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 @@
 
 %}
 
-%expect 158
+%expect 156
 
 %union {
        val_t   *y_val;
@@ -873,8 +873,8 @@
          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();



Home | Main Index | Thread Index | Old Index