Module Name: src Committed By: rillig Date: Thu May 12 20:57:49 UTC 2022
Modified Files: src/tests/usr.bin/xlint/lint1: d_alignof.c d_alignof.exp src/usr.bin/xlint/lint1: cgram.y Log Message: 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 $$. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/d_alignof.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_alignof.exp cvs rdiff -u -r1.414 -r1.415 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/d_alignof.c diff -u src/tests/usr.bin/xlint/lint1/d_alignof.c:1.6 src/tests/usr.bin/xlint/lint1/d_alignof.c:1.7 --- src/tests/usr.bin/xlint/lint1/d_alignof.c:1.6 Thu May 12 20:49:21 2022 +++ src/tests/usr.bin/xlint/lint1/d_alignof.c Thu May 12 20:57:49 2022 @@ -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 @@ alignof_pointer_to_member(void) 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] */ Index: src/tests/usr.bin/xlint/lint1/d_alignof.exp diff -u src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.4 src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.5 --- src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.4 Thu May 12 20:49:21 2022 +++ src/tests/usr.bin/xlint/lint1/d_alignof.exp Thu May 12 20:57:49 2022 @@ -4,5 +4,3 @@ d_alignof.c(25): warning: function plain 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] Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.414 src/usr.bin/xlint/lint1/cgram.y:1.415 --- src/usr.bin/xlint/lint1/cgram.y:1.414 Thu May 12 20:22:58 2022 +++ src/usr.bin/xlint/lint1/cgram.y Thu May 12 20:57:49 2022 @@ -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 @@ anonymize(sym_t *s) %} -%expect 130 +%expect 129 %union { val_t *y_val; @@ -618,18 +618,12 @@ unary_expression: 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); }