lint: fix parsing of GNU __attribute__ after __asm

GCC only accepts them in the order __asm __attribute__, not the other
way round.  So should lint.
This commit is contained in:
rillig 2021-07-25 17:40:04 +00:00
parent b51ebfa06f
commit c127a42574
3 changed files with 26 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse_init_declarator.c,v 1.1 2021/07/25 17:27:07 rillig Exp $ */
/* $NetBSD: parse_init_declarator.c,v 1.2 2021/07/25 17:40:04 rillig Exp $ */
# 3 "parse_init_declarator.c"
/*
@ -12,8 +12,6 @@ int global_var;
int *init_declarator_without_initializer
__asm("") __attribute__((deprecated));
/* expect-1: error: syntax error '__attribute__' [249] */
/* FIXME */
/* XXX: GCC does not accept this, neither should lint. */
int *init_declarator_without_initializer_wrong_order
@ -21,8 +19,6 @@ int *init_declarator_without_initializer_wrong_order
int *init_declarator_with_initializer
__asm("") __attribute__((deprecated)) = &global_var;
/* expect-1: error: syntax error '__attribute__' [249] */
/* FIXME */
/* XXX: GCC does not accept this, neither should lint. */
int *init_declarator_with_initializer_wrong_order

View File

@ -1,3 +1 @@
parse_init_declarator.c(14): error: syntax error '__attribute__' [249]
parse_init_declarator.c(23): error: syntax error '__attribute__' [249]
parse_init_declarator.c(33): error: syntax error '__attribute__' [249]
parse_init_declarator.c(29): error: syntax error '__attribute__' [249]

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: cgram.y,v 1.338 2021/07/25 16:57:23 rillig Exp $ */
/* $NetBSD: cgram.y,v 1.339 2021/07/25 17:40:04 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.338 2021/07/25 16:57:23 rillig Exp $");
__RCSID("$NetBSD: cgram.y,v 1.339 2021/07/25 17:40:04 rillig Exp $");
#endif
#include <limits.h>
@ -124,7 +124,7 @@ anonymize(sym_t *s)
%}
%expect 156
%expect 159
%union {
val_t *y_val;
@ -833,11 +833,7 @@ type_attribute_opt:
;
type_attribute: /* See C11 6.7 declaration-specifiers */
T_ATTRIBUTE T_LPAREN T_LPAREN {
attron = true;
} gcc_attribute_spec_list {
attron = false;
} T_RPAREN T_RPAREN
gcc_attribute
/* TODO: c11ism */
| T_ALIGNAS T_LPAREN align_as T_RPAREN
| T_PACKED {
@ -1592,11 +1588,11 @@ asm_or_symbolrename_opt: /* GCC extensions */
/* empty */ {
$$ = NULL;
}
| T_ASM T_LPAREN T_STRING T_RPAREN {
| T_ASM T_LPAREN T_STRING T_RPAREN gcc_attribute_list_opt {
freeyyv(&$3, T_STRING);
$$ = NULL;
}
| T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN {
| T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN gcc_attribute_list_opt {
$$ = $3;
}
;
@ -2006,6 +2002,24 @@ arg_declaration:
| begin_type_declaration_specifiers error
;
gcc_attribute_list_opt:
/* empty */
| gcc_attribute_list
;
gcc_attribute_list:
gcc_attribute
| gcc_attribute_list gcc_attribute
;
gcc_attribute:
T_ATTRIBUTE T_LPAREN T_LPAREN {
attron = true;
} gcc_attribute_spec_list {
attron = false;
} T_RPAREN T_RPAREN
;
gcc_attribute_spec_list:
gcc_attribute_spec
| gcc_attribute_spec_list T_COMMA gcc_attribute_spec