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: merge duplicate grammar rules for ...



details:   https://anonhg.NetBSD.org/src/rev/ffd733f01215
branches:  trunk
changeset: 366060:ffd733f01215
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 12 20:57:49 2022 +0000

description:
lint: merge duplicate grammar rules for __alignof__ expr

This allows expressions like '__alignof__(ptr)->member', just as with
'sizeof'.

The upper rule in the grammar was preferred over the lower rule since it
shifted the T_LPAREN instead of reducing unary_expression.  Its
implementation invoked undefined behavior if the expression was NULL
since it didn't assign anything to $$.

diffstat:

 tests/usr.bin/xlint/lint1/d_alignof.c   |   5 +----
 tests/usr.bin/xlint/lint1/d_alignof.exp |   2 --
 usr.bin/xlint/lint1/cgram.y             |  16 +++++-----------
 3 files changed, 6 insertions(+), 17 deletions(-)

diffs (76 lines):

diff -r 496a2fd0e652 -r ffd733f01215 tests/usr.bin/xlint/lint1/d_alignof.c
--- a/tests/usr.bin/xlint/lint1/d_alignof.c     Thu May 12 20:49:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.c     Thu May 12 20:57:49 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_alignof.c,v 1.6 2022/05/12 20:49:21 rillig Exp $     */
+/*     $NetBSD: d_alignof.c,v 1.7 2022/05/12 20:57:49 rillig Exp $     */
 # 3 "d_alignof.c"
 
 /* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */
@@ -65,8 +65,5 @@
                unsigned long member;
        } var = { 0 }, *ptr = &var;
 
-       /* FIXME: the syntax error is wrong, this is perfectly valid */
-       /* expect+1: error: syntax error '->' [249] */
        return __alignof__(ptr)->member + ptr->member;
 }
-/* expect-1: warning: function alignof_pointer_to_member falls off bottom without returning value [217] */
diff -r 496a2fd0e652 -r ffd733f01215 tests/usr.bin/xlint/lint1/d_alignof.exp
--- a/tests/usr.bin/xlint/lint1/d_alignof.exp   Thu May 12 20:49:21 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.exp   Thu May 12 20:57:49 2022 +0000
@@ -4,5 +4,3 @@
 d_alignof.c(46): error: 'alignof' undefined [99]
 d_alignof.c(46): error: syntax error '3' [249]
 d_alignof.c(47): warning: function plain_alignof_expr falls off bottom without returning value [217]
-d_alignof.c(70): error: syntax error '->' [249]
-d_alignof.c(71): warning: function alignof_pointer_to_member falls off bottom without returning value [217]
diff -r 496a2fd0e652 -r ffd733f01215 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Thu May 12 20:49:21 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Thu May 12 20:57:49 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.414 2022/05/12 20:22:58 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.415 2022/05/12 20:57:49 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.414 2022/05/12 20:22:58 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.415 2022/05/12 20:57:49 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -126,7 +126,7 @@
 
 %}
 
-%expect 130
+%expect 129
 
 %union {
        val_t   *y_val;
@@ -618,18 +618,12 @@
                        check_expr_misc($2,
                            false, false, false, false, false, true);
          }
-       /* gcc */
-       | T_ALIGNOF T_LPAREN unary_expression T_RPAREN {
-               /* non type argument to alignof is a GCC extension */
-               gnuism(349);
-               if ($3 != NULL)
-                       $$ = build_alignof($3->tn_type);
-         }
        | T_SIZEOF T_LPAREN type_name T_RPAREN {
                $$ = build_sizeof($3);
          }
-       /* GCC extension */
        | T_ALIGNOF unary_expression {
+               /* non type argument to alignof is a GCC extension */
+               gnuism(349);
                lint_assert($2 != NULL);
                $$ = build_alignof($2->tn_type);
          }



Home | Main Index | Thread Index | Old Index