lint: revert resolving grammar conflicts for labeled statements

Restore the grammar rule for labeled_statement as it was before cgram.y
1.400 from 2022-04-24.  This allows labels with attributes again.  Fix
the wrong interpretation in the tests; the attributes belong to the
label, not to the statement.

Today in the morning, when I thought that the change in cgram.y 1.400
were innocent, I accidentally ran lint only with the options '-Sw' but
forgot the option '-g' for GNU mode.  Without that option, the token
'__attribute__' is unknown, which unsurprisingly leads to lots of syntax
errors, and these didn't change with that commit.  The actual change was
only visible in GNU mode.
This commit is contained in:
rillig 2022-04-28 21:38:38 +00:00
parent c465128a4e
commit 154b5ed632
7 changed files with 35 additions and 32 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1199 2022/04/26 22:48:53 blymn Exp $
# $NetBSD: mi,v 1.1200 2022/04/28 21:38:38 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -6505,7 +6505,7 @@
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_func.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_func.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_label.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp tests-obsolete obsolete
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_label.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_stmt.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/gcc_attribute_type.c tests-usr.bin-tests compattestfile,atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.120 2022/04/16 20:18:52 rillig Exp $
# $NetBSD: Makefile,v 1.121 2022/04/28 21:38:38 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 348 # see lint1/err.c
@ -165,6 +165,7 @@ FILES+= gcc_attribute_enum.exp
FILES+= gcc_attribute_func.c
FILES+= gcc_attribute_func.exp
FILES+= gcc_attribute_label.c
FILES+= gcc_attribute_label.exp
FILES+= gcc_attribute_stmt.c
FILES+= gcc_attribute_stmt.exp
FILES+= gcc_attribute_type.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: gcc_attribute_label.c,v 1.2 2021/07/11 19:24:42 rillig Exp $ */
/* $NetBSD: gcc_attribute_label.c,v 1.3 2022/04/28 21:38:38 rillig Exp $ */
# 3 "gcc_attribute_label.c"
/*
@ -23,3 +23,27 @@ hot:
if (i < 0)
goto error;
}
/* GCC allows a label to be marked as (possibly) unused. */
void
unused_labels(int x)
{
switch (x) {
case 3:
__attribute__((__unused__))
break;
case 4:
goto label;
label:
__attribute__((__unused__))
return;
}
/*
* The GCC attributes may only occur after a label; they cannot occur
* before an arbitrary statement.
*/
__attribute__((__unused__))
/* expect+1: error: syntax error 'return' [249] */
return;
}

View File

@ -0,0 +1 @@
gcc_attribute_label.c(48): error: syntax error 'return' [249]

View File

@ -1,4 +1,4 @@
/* $NetBSD: gcc_attribute_stmt.c,v 1.2 2022/04/28 07:10:39 rillig Exp $ */
/* $NetBSD: gcc_attribute_stmt.c,v 1.3 2022/04/28 21:38:38 rillig Exp $ */
# 3 "gcc_attribute_stmt.c"
/*
@ -34,24 +34,3 @@ attribute_fallthrough(int i)
__attribute__((__fallthrough__));
}
}
/*
* Despite being undocumented, GCC 10 accepts __attribute__((__unused__))
* at the beginning of a statement.
*/
void
unused_statements(int x)
{
switch (x) {
case 3:
__attribute__((__unused__))
/* expect+1: error: syntax error 'break' [249] */
break;
case 4:
goto label;
label:
__attribute__((__unused__))
/* expect+1: error: syntax error 'return' [249] */
return;
}
}

View File

@ -1,3 +1 @@
gcc_attribute_stmt.c(34): error: syntax error '__attribute__' [249]
gcc_attribute_stmt.c(49): error: syntax error 'break' [249]
gcc_attribute_stmt.c(55): error: syntax error 'return' [249]

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: cgram.y,v 1.402 2022/04/24 20:08:22 rillig Exp $ */
/* $NetBSD: cgram.y,v 1.403 2022/04/28 21:38:38 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.402 2022/04/24 20:08:22 rillig Exp $");
__RCSID("$NetBSD: cgram.y,v 1.403 2022/04/28 21:38:38 rillig Exp $");
#endif
#include <limits.h>
@ -126,7 +126,7 @@ anonymize(sym_t *s)
%}
%expect 128
%expect 132
%union {
val_t *y_val;
@ -1655,7 +1655,7 @@ non_expr_statement: /* helper for C99 6.8 */
;
labeled_statement: /* C99 6.8.1 */
label statement
label type_attribute_opt statement
;
label: