2019-09-12 20:45:07 +09:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
/*
|
|
|
|
|
* C global declaration parser for genksyms.
|
|
|
|
|
* Copyright 1996, 1997 Linux International.
|
|
|
|
|
*
|
|
|
|
|
* New implementation contributed by Richard Henderson <rth@tamu.edu>
|
|
|
|
|
* Based on original work by Bjorn Ekwall <bj0rn@blox.se>
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the Linux modutils.
|
|
|
|
|
*/
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
#include <stdbool.h>
|
2010-11-08 18:31:53 -05:00
|
|
|
#include <stdlib.h>
|
2011-02-03 23:57:09 +01:00
|
|
|
#include <string.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
#include "genksyms.h"
|
|
|
|
|
|
|
|
|
|
static int is_typedef;
|
|
|
|
|
static int is_extern;
|
|
|
|
|
static char *current_name;
|
|
|
|
|
static struct string_list *decl_spec;
|
|
|
|
|
|
|
|
|
|
static void yyerror(const char *);
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
remove_node(struct string_list **p)
|
|
|
|
|
{
|
|
|
|
|
struct string_list *node = *p;
|
|
|
|
|
*p = node->next;
|
|
|
|
|
free_node(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
remove_list(struct string_list **pb, struct string_list **pe)
|
|
|
|
|
{
|
|
|
|
|
struct string_list *b = *pb, *e = *pe;
|
|
|
|
|
*pb = e;
|
|
|
|
|
free_list(b, e);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-08 00:48:29 +02:00
|
|
|
/* Record definition of a struct/union/enum */
|
|
|
|
|
static void record_compound(struct string_list **keyw,
|
|
|
|
|
struct string_list **ident,
|
|
|
|
|
struct string_list **body,
|
|
|
|
|
enum symbol_type type)
|
|
|
|
|
{
|
|
|
|
|
struct string_list *b = *body, *i = *ident, *r;
|
2011-10-08 01:18:35 +02:00
|
|
|
|
|
|
|
|
if (i->in_source_file) {
|
|
|
|
|
remove_node(keyw);
|
|
|
|
|
(*ident)->tag = type;
|
|
|
|
|
remove_list(body, ident);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-10-08 00:48:29 +02:00
|
|
|
r = copy_node(i); r->tag = type;
|
|
|
|
|
r->next = (*keyw)->next; *body = r; (*keyw)->next = NULL;
|
|
|
|
|
add_symbol(i->string, type, b, is_extern);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
%token ASM_KEYW
|
|
|
|
|
%token ATTRIBUTE_KEYW
|
|
|
|
|
%token AUTO_KEYW
|
|
|
|
|
%token BOOL_KEYW
|
2019-06-18 14:10:48 +01:00
|
|
|
%token BUILTIN_INT_KEYW
|
2005-04-16 15:20:36 -07:00
|
|
|
%token CHAR_KEYW
|
|
|
|
|
%token CONST_KEYW
|
|
|
|
|
%token DOUBLE_KEYW
|
|
|
|
|
%token ENUM_KEYW
|
|
|
|
|
%token EXTERN_KEYW
|
2007-08-28 20:28:55 +02:00
|
|
|
%token EXTENSION_KEYW
|
2005-04-16 15:20:36 -07:00
|
|
|
%token FLOAT_KEYW
|
|
|
|
|
%token INLINE_KEYW
|
|
|
|
|
%token INT_KEYW
|
|
|
|
|
%token LONG_KEYW
|
|
|
|
|
%token REGISTER_KEYW
|
|
|
|
|
%token RESTRICT_KEYW
|
|
|
|
|
%token SHORT_KEYW
|
|
|
|
|
%token SIGNED_KEYW
|
|
|
|
|
%token STATIC_KEYW
|
2020-12-01 16:20:18 +01:00
|
|
|
%token STATIC_ASSERT_KEYW
|
2005-04-16 15:20:36 -07:00
|
|
|
%token STRUCT_KEYW
|
|
|
|
|
%token TYPEDEF_KEYW
|
|
|
|
|
%token UNION_KEYW
|
|
|
|
|
%token UNSIGNED_KEYW
|
|
|
|
|
%token VOID_KEYW
|
|
|
|
|
%token VOLATILE_KEYW
|
|
|
|
|
%token TYPEOF_KEYW
|
2016-11-24 03:41:39 +11:00
|
|
|
%token VA_LIST_KEYW
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2025-04-14 00:07:34 +02:00
|
|
|
%token X86_SEG_KEYW
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
%token EXPORT_SYMBOL_KEYW
|
|
|
|
|
|
|
|
|
|
%token ASM_PHRASE
|
|
|
|
|
%token ATTRIBUTE_PHRASE
|
2014-04-03 14:46:37 -07:00
|
|
|
%token TYPEOF_PHRASE
|
2005-04-16 15:20:36 -07:00
|
|
|
%token BRACE_PHRASE
|
|
|
|
|
%token BRACKET_PHRASE
|
|
|
|
|
%token EXPRESSION_PHRASE
|
2020-12-01 16:20:18 +01:00
|
|
|
%token STATIC_ASSERT_PHRASE
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
%token CHAR
|
|
|
|
|
%token DOTS
|
|
|
|
|
%token IDENT
|
|
|
|
|
%token INT
|
|
|
|
|
%token REAL
|
|
|
|
|
%token STRING
|
|
|
|
|
%token TYPE
|
|
|
|
|
%token OTHER
|
|
|
|
|
%token FILENAME
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
declaration_seq:
|
|
|
|
|
declaration
|
|
|
|
|
| declaration_seq declaration
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
declaration:
|
|
|
|
|
{ is_typedef = 0; is_extern = 0; current_name = NULL; decl_spec = NULL; }
|
|
|
|
|
declaration1
|
|
|
|
|
{ free_list(*$2, NULL); *$2 = NULL; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
declaration1:
|
2007-08-28 20:28:55 +02:00
|
|
|
EXTENSION_KEYW TYPEDEF_KEYW { is_typedef = 1; } simple_declaration
|
|
|
|
|
{ $$ = $4; }
|
|
|
|
|
| TYPEDEF_KEYW { is_typedef = 1; } simple_declaration
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $3; }
|
|
|
|
|
| simple_declaration
|
|
|
|
|
| function_definition
|
|
|
|
|
| asm_definition
|
|
|
|
|
| export_definition
|
2020-12-01 16:20:18 +01:00
|
|
|
| static_assert
|
2005-04-16 15:20:36 -07:00
|
|
|
| error ';' { $$ = $2; }
|
|
|
|
|
| error '}' { $$ = $2; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
simple_declaration:
|
|
|
|
|
decl_specifier_seq_opt init_declarator_list_opt ';'
|
|
|
|
|
{ if (current_name) {
|
|
|
|
|
struct string_list *decl = (*$3)->next;
|
|
|
|
|
(*$3)->next = NULL;
|
|
|
|
|
add_symbol(current_name,
|
|
|
|
|
is_typedef ? SYM_TYPEDEF : SYM_NORMAL,
|
|
|
|
|
decl, is_extern);
|
|
|
|
|
current_name = NULL;
|
|
|
|
|
}
|
|
|
|
|
$$ = $3;
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
dont_want_type_specifier = false;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
init_declarator_list_opt:
|
2025-01-03 16:30:38 +09:00
|
|
|
/* empty */ { $$ = NULL; }
|
|
|
|
|
| init_declarator_list { free_list(decl_spec, NULL); $$ = $1; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
init_declarator_list:
|
|
|
|
|
init_declarator
|
|
|
|
|
{ struct string_list *decl = *$1;
|
|
|
|
|
*$1 = NULL;
|
2025-01-03 16:30:38 +09:00
|
|
|
|
|
|
|
|
/* avoid sharing among multiple init_declarators */
|
|
|
|
|
if (decl_spec)
|
|
|
|
|
decl_spec = copy_list_range(decl_spec, NULL);
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
add_symbol(current_name,
|
|
|
|
|
is_typedef ? SYM_TYPEDEF : SYM_NORMAL, decl, is_extern);
|
|
|
|
|
current_name = NULL;
|
|
|
|
|
$$ = $1;
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
dont_want_type_specifier = true;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
2025-01-14 00:00:55 +09:00
|
|
|
| init_declarator_list ',' attribute_opt init_declarator
|
|
|
|
|
{ struct string_list *decl = *$4;
|
|
|
|
|
*$4 = NULL;
|
2005-04-16 15:20:36 -07:00
|
|
|
free_list(*$2, NULL);
|
|
|
|
|
*$2 = decl_spec;
|
2025-01-03 16:30:38 +09:00
|
|
|
|
|
|
|
|
/* avoid sharing among multiple init_declarators */
|
|
|
|
|
if (decl_spec)
|
|
|
|
|
decl_spec = copy_list_range(decl_spec, NULL);
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
add_symbol(current_name,
|
|
|
|
|
is_typedef ? SYM_TYPEDEF : SYM_NORMAL, decl, is_extern);
|
|
|
|
|
current_name = NULL;
|
2025-01-14 00:00:55 +09:00
|
|
|
$$ = $4;
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
dont_want_type_specifier = true;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
init_declarator:
|
|
|
|
|
declarator asm_phrase_opt attribute_opt initializer_opt
|
|
|
|
|
{ $$ = $4 ? $4 : $3 ? $3 : $2 ? $2 : $1; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
/* Hang on to the specifiers so that we can reuse them. */
|
|
|
|
|
decl_specifier_seq_opt:
|
|
|
|
|
/* empty */ { decl_spec = NULL; }
|
|
|
|
|
| decl_specifier_seq
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
decl_specifier_seq:
|
genksyms: fix syntax error for attribute before abstract_declarator
A longstanding issue with genksyms is that it has hidden syntax errors.
When a syntax error occurs, yyerror() is called. However,
error_with_pos() is a no-op unless the -w option is provided.
You can observe syntax errors by manually passing the -w option.
For example, with CONFIG_MODVERSIONS=y on v6.13-rc1:
$ make -s KCFLAGS=-D__GENKSYMS__ init/main.i
$ cat init/main.i | scripts/genksyms/genksyms -w
[ snip ]
./include/linux/efi.h:1225: syntax error
The syntax error occurs in the following code in include/linux/efi.h:
efi_status_t
efi_call_acpi_prm_handler(efi_status_t (__efiapi *handler_addr)(u64, void *),
u64 param_buffer_addr, void *context);
The issue arises from __efiapi, which is defined as either
__attribute__((ms_abi)) or __attribute__((regparm(0))).
This commit allows abstract_declarator to be prefixed with attributes.
To avoid conflicts, I tweaked the rule for decl_specifier_seq. Due to
this change, a standalone attribute cannot become decl_specifier_seq.
Otherwise, I do not know how to resolve the conflicts.
The following code, which was previously accepted by genksyms, will now
result in a syntax error:
void my_func(__attribute__((unused))x);
I do not think it is a big deal because GCC also fails to parse it.
$ echo 'void my_func(__attribute__((unused))x);' | gcc -c -x c -
<stdin>:1:37: error: unknown type name 'x'
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:49 +09:00
|
|
|
attribute_opt decl_specifier { decl_spec = *$2; }
|
2005-04-16 15:20:36 -07:00
|
|
|
| decl_specifier_seq decl_specifier { decl_spec = *$2; }
|
genksyms: fix syntax error for attribute before abstract_declarator
A longstanding issue with genksyms is that it has hidden syntax errors.
When a syntax error occurs, yyerror() is called. However,
error_with_pos() is a no-op unless the -w option is provided.
You can observe syntax errors by manually passing the -w option.
For example, with CONFIG_MODVERSIONS=y on v6.13-rc1:
$ make -s KCFLAGS=-D__GENKSYMS__ init/main.i
$ cat init/main.i | scripts/genksyms/genksyms -w
[ snip ]
./include/linux/efi.h:1225: syntax error
The syntax error occurs in the following code in include/linux/efi.h:
efi_status_t
efi_call_acpi_prm_handler(efi_status_t (__efiapi *handler_addr)(u64, void *),
u64 param_buffer_addr, void *context);
The issue arises from __efiapi, which is defined as either
__attribute__((ms_abi)) or __attribute__((regparm(0))).
This commit allows abstract_declarator to be prefixed with attributes.
To avoid conflicts, I tweaked the rule for decl_specifier_seq. Due to
this change, a standalone attribute cannot become decl_specifier_seq.
Otherwise, I do not know how to resolve the conflicts.
The following code, which was previously accepted by genksyms, will now
result in a syntax error:
void my_func(__attribute__((unused))x);
I do not think it is a big deal because GCC also fails to parse it.
$ echo 'void my_func(__attribute__((unused))x);' | gcc -c -x c -
<stdin>:1:37: error: unknown type name 'x'
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:49 +09:00
|
|
|
| decl_specifier_seq ATTRIBUTE_PHRASE { decl_spec = *$2; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
decl_specifier:
|
|
|
|
|
storage_class_specifier
|
|
|
|
|
{ /* Version 2 checksumming ignores storage class, as that
|
|
|
|
|
is really irrelevant to the linkage. */
|
|
|
|
|
remove_node($1);
|
|
|
|
|
$$ = $1;
|
|
|
|
|
}
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
| type_specifier { dont_want_type_specifier = true; $$ = $1; }
|
2025-01-14 00:00:41 +09:00
|
|
|
| type_qualifier
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
storage_class_specifier:
|
|
|
|
|
AUTO_KEYW
|
|
|
|
|
| REGISTER_KEYW
|
|
|
|
|
| STATIC_KEYW
|
|
|
|
|
| EXTERN_KEYW { is_extern = 1; $$ = $1; }
|
|
|
|
|
| INLINE_KEYW { is_extern = 0; $$ = $1; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
type_specifier:
|
|
|
|
|
simple_type_specifier
|
2014-04-03 14:46:37 -07:00
|
|
|
| TYPEOF_KEYW '(' parameter_declaration ')'
|
|
|
|
|
| TYPEOF_PHRASE
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
/* References to s/u/e's defined elsewhere. Rearrange things
|
|
|
|
|
so that it is easier to expand the definition fully later. */
|
2025-01-14 00:00:52 +09:00
|
|
|
| STRUCT_KEYW attribute_opt IDENT
|
|
|
|
|
{ remove_node($1); (*$3)->tag = SYM_STRUCT; $$ = $3; }
|
2025-01-14 00:00:53 +09:00
|
|
|
| UNION_KEYW attribute_opt IDENT
|
|
|
|
|
{ remove_node($1); (*$3)->tag = SYM_UNION; $$ = $3; }
|
2005-04-16 15:20:36 -07:00
|
|
|
| ENUM_KEYW IDENT
|
|
|
|
|
{ remove_node($1); (*$2)->tag = SYM_ENUM; $$ = $2; }
|
|
|
|
|
|
|
|
|
|
/* Full definitions of an s/u/e. Record it. */
|
2025-01-14 00:00:52 +09:00
|
|
|
| STRUCT_KEYW attribute_opt IDENT class_body
|
|
|
|
|
{ record_compound($1, $3, $4, SYM_STRUCT); $$ = $4; }
|
2025-01-14 00:00:53 +09:00
|
|
|
| UNION_KEYW attribute_opt IDENT class_body
|
|
|
|
|
{ record_compound($1, $3, $4, SYM_UNION); $$ = $4; }
|
2011-02-03 23:57:09 +01:00
|
|
|
| ENUM_KEYW IDENT enum_body
|
2011-10-08 00:48:29 +02:00
|
|
|
{ record_compound($1, $2, $3, SYM_ENUM); $$ = $3; }
|
2011-02-03 23:57:09 +01:00
|
|
|
/*
|
|
|
|
|
* Anonymous enum definition. Tell add_symbol() to restart its counter.
|
|
|
|
|
*/
|
|
|
|
|
| ENUM_KEYW enum_body
|
|
|
|
|
{ add_symbol(NULL, SYM_ENUM, NULL, 0); $$ = $2; }
|
|
|
|
|
/* Anonymous s/u definitions. Nothing needs doing. */
|
2025-01-14 00:00:52 +09:00
|
|
|
| STRUCT_KEYW attribute_opt class_body { $$ = $3; }
|
2025-01-14 00:00:53 +09:00
|
|
|
| UNION_KEYW attribute_opt class_body { $$ = $3; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
simple_type_specifier:
|
|
|
|
|
CHAR_KEYW
|
|
|
|
|
| SHORT_KEYW
|
|
|
|
|
| INT_KEYW
|
|
|
|
|
| LONG_KEYW
|
|
|
|
|
| SIGNED_KEYW
|
|
|
|
|
| UNSIGNED_KEYW
|
|
|
|
|
| FLOAT_KEYW
|
|
|
|
|
| DOUBLE_KEYW
|
|
|
|
|
| VOID_KEYW
|
|
|
|
|
| BOOL_KEYW
|
2016-11-24 03:41:39 +11:00
|
|
|
| VA_LIST_KEYW
|
2019-06-18 14:10:48 +01:00
|
|
|
| BUILTIN_INT_KEYW
|
2005-04-16 15:20:36 -07:00
|
|
|
| TYPE { (*$1)->tag = SYM_TYPEDEF; $$ = $1; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
ptr_operator:
|
2025-01-14 00:00:40 +09:00
|
|
|
'*' type_qualifier_seq_opt
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $2 ? $2 : $1; }
|
|
|
|
|
;
|
|
|
|
|
|
2025-01-14 00:00:40 +09:00
|
|
|
type_qualifier_seq_opt:
|
2005-04-16 15:20:36 -07:00
|
|
|
/* empty */ { $$ = NULL; }
|
2025-01-14 00:00:40 +09:00
|
|
|
| type_qualifier_seq
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
2025-01-14 00:00:40 +09:00
|
|
|
type_qualifier_seq:
|
|
|
|
|
type_qualifier
|
2025-01-14 00:00:48 +09:00
|
|
|
| ATTRIBUTE_PHRASE
|
2025-01-14 00:00:40 +09:00
|
|
|
| type_qualifier_seq type_qualifier { $$ = $2; }
|
2025-01-14 00:00:48 +09:00
|
|
|
| type_qualifier_seq ATTRIBUTE_PHRASE { $$ = $2; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
2025-01-14 00:00:40 +09:00
|
|
|
type_qualifier:
|
2025-04-14 00:07:34 +02:00
|
|
|
X86_SEG_KEYW
|
|
|
|
|
| CONST_KEYW | VOLATILE_KEYW
|
2005-04-16 15:20:36 -07:00
|
|
|
| RESTRICT_KEYW
|
|
|
|
|
{ /* restrict has no effect in prototypes so ignore it */
|
|
|
|
|
remove_node($1);
|
|
|
|
|
$$ = $1;
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
declarator:
|
|
|
|
|
ptr_operator declarator { $$ = $2; }
|
|
|
|
|
| direct_declarator
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
direct_declarator:
|
|
|
|
|
IDENT
|
|
|
|
|
{ if (current_name != NULL) {
|
|
|
|
|
error_with_pos("unexpected second declaration name");
|
|
|
|
|
YYERROR;
|
|
|
|
|
} else {
|
|
|
|
|
current_name = (*$1)->string;
|
|
|
|
|
$$ = $1;
|
|
|
|
|
}
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
dont_want_type_specifier = false;
|
2015-07-20 19:52:48 -04:00
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
| direct_declarator '(' parameter_declaration_clause ')'
|
|
|
|
|
{ $$ = $4; }
|
|
|
|
|
| direct_declarator '(' error ')'
|
|
|
|
|
{ $$ = $4; }
|
|
|
|
|
| direct_declarator BRACKET_PHRASE
|
|
|
|
|
{ $$ = $2; }
|
2026-02-25 15:07:17 -07:00
|
|
|
| '(' attribute_opt declarator ')'
|
|
|
|
|
{ $$ = $4; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
/* Nested declarators differ from regular declarators in that they do
|
|
|
|
|
not record the symbols they find in the global symbol table. */
|
|
|
|
|
nested_declarator:
|
|
|
|
|
ptr_operator nested_declarator { $$ = $2; }
|
|
|
|
|
| direct_nested_declarator
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
direct_nested_declarator:
|
2025-01-14 00:00:46 +09:00
|
|
|
direct_nested_declarator1
|
|
|
|
|
| direct_nested_declarator1 '(' parameter_declaration_clause ')'
|
|
|
|
|
{ $$ = $4; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
direct_nested_declarator1:
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
IDENT { $$ = $1; dont_want_type_specifier = false; }
|
2025-01-14 00:00:46 +09:00
|
|
|
| direct_nested_declarator1 '(' error ')'
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $4; }
|
2025-01-14 00:00:46 +09:00
|
|
|
| direct_nested_declarator1 BRACKET_PHRASE
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $2; }
|
2025-01-14 00:00:50 +09:00
|
|
|
| '(' attribute_opt nested_declarator ')'
|
|
|
|
|
{ $$ = $4; }
|
2005-04-16 15:20:36 -07:00
|
|
|
| '(' error ')'
|
|
|
|
|
{ $$ = $3; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
parameter_declaration_clause:
|
|
|
|
|
parameter_declaration_list_opt DOTS { $$ = $2; }
|
|
|
|
|
| parameter_declaration_list_opt
|
|
|
|
|
| parameter_declaration_list ',' DOTS { $$ = $3; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
parameter_declaration_list_opt:
|
|
|
|
|
/* empty */ { $$ = NULL; }
|
|
|
|
|
| parameter_declaration_list
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
parameter_declaration_list:
|
|
|
|
|
parameter_declaration
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
{ $$ = $1; dont_want_type_specifier = false; }
|
2005-04-16 15:20:36 -07:00
|
|
|
| parameter_declaration_list ',' parameter_declaration
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
{ $$ = $3; dont_want_type_specifier = false; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
parameter_declaration:
|
2025-01-14 00:00:43 +09:00
|
|
|
decl_specifier_seq abstract_declarator_opt
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $2 ? $2 : $1; }
|
|
|
|
|
;
|
|
|
|
|
|
2025-01-14 00:00:43 +09:00
|
|
|
abstract_declarator_opt:
|
|
|
|
|
/* empty */ { $$ = NULL; }
|
|
|
|
|
| abstract_declarator
|
|
|
|
|
;
|
|
|
|
|
|
2025-01-14 00:00:39 +09:00
|
|
|
abstract_declarator:
|
2025-01-14 00:00:43 +09:00
|
|
|
ptr_operator
|
|
|
|
|
| ptr_operator abstract_declarator
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $2 ? $2 : $1; }
|
2025-01-14 00:00:51 +09:00
|
|
|
| direct_abstract_declarator attribute_opt
|
|
|
|
|
{ $$ = $2; dont_want_type_specifier = false; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
2025-01-14 00:00:39 +09:00
|
|
|
direct_abstract_declarator:
|
2025-01-14 00:00:45 +09:00
|
|
|
direct_abstract_declarator1
|
|
|
|
|
| direct_abstract_declarator1 open_paren parameter_declaration_clause ')'
|
|
|
|
|
{ $$ = $4; }
|
|
|
|
|
| open_paren parameter_declaration_clause ')'
|
|
|
|
|
{ $$ = $3; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
direct_abstract_declarator1:
|
2025-01-14 00:00:43 +09:00
|
|
|
IDENT
|
2005-04-16 15:20:36 -07:00
|
|
|
{ /* For version 2 checksums, we don't want to remember
|
|
|
|
|
private parameter names. */
|
|
|
|
|
remove_node($1);
|
|
|
|
|
$$ = $1;
|
|
|
|
|
}
|
2025-01-14 00:00:45 +09:00
|
|
|
| direct_abstract_declarator1 open_paren error ')'
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $4; }
|
2025-01-14 00:00:45 +09:00
|
|
|
| direct_abstract_declarator1 BRACKET_PHRASE
|
2005-04-16 15:20:36 -07:00
|
|
|
{ $$ = $2; }
|
genksyms: fix syntax error for attribute before abstract_declarator
A longstanding issue with genksyms is that it has hidden syntax errors.
When a syntax error occurs, yyerror() is called. However,
error_with_pos() is a no-op unless the -w option is provided.
You can observe syntax errors by manually passing the -w option.
For example, with CONFIG_MODVERSIONS=y on v6.13-rc1:
$ make -s KCFLAGS=-D__GENKSYMS__ init/main.i
$ cat init/main.i | scripts/genksyms/genksyms -w
[ snip ]
./include/linux/efi.h:1225: syntax error
The syntax error occurs in the following code in include/linux/efi.h:
efi_status_t
efi_call_acpi_prm_handler(efi_status_t (__efiapi *handler_addr)(u64, void *),
u64 param_buffer_addr, void *context);
The issue arises from __efiapi, which is defined as either
__attribute__((ms_abi)) or __attribute__((regparm(0))).
This commit allows abstract_declarator to be prefixed with attributes.
To avoid conflicts, I tweaked the rule for decl_specifier_seq. Due to
this change, a standalone attribute cannot become decl_specifier_seq.
Otherwise, I do not know how to resolve the conflicts.
The following code, which was previously accepted by genksyms, will now
result in a syntax error:
void my_func(__attribute__((unused))x);
I do not think it is a big deal because GCC also fails to parse it.
$ echo 'void my_func(__attribute__((unused))x);' | gcc -c -x c -
<stdin>:1:37: error: unknown type name 'x'
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:49 +09:00
|
|
|
| open_paren attribute_opt abstract_declarator ')'
|
|
|
|
|
{ $$ = $4; }
|
2025-01-14 00:00:43 +09:00
|
|
|
| open_paren error ')'
|
|
|
|
|
{ $$ = $3; }
|
|
|
|
|
| BRACKET_PHRASE
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
open_paren:
|
|
|
|
|
'(' { $$ = $1; dont_want_type_specifier = false; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
function_definition:
|
|
|
|
|
decl_specifier_seq_opt declarator BRACE_PHRASE
|
|
|
|
|
{ struct string_list *decl = *$2;
|
|
|
|
|
*$2 = NULL;
|
|
|
|
|
add_symbol(current_name, SYM_NORMAL, decl, is_extern);
|
|
|
|
|
$$ = $3;
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
initializer_opt:
|
|
|
|
|
/* empty */ { $$ = NULL; }
|
|
|
|
|
| initializer
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
/* We never care about the contents of an initializer. */
|
|
|
|
|
initializer:
|
|
|
|
|
'=' EXPRESSION_PHRASE
|
|
|
|
|
{ remove_list($2, &(*$1)->next); $$ = $2; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
class_body:
|
|
|
|
|
'{' member_specification_opt '}' { $$ = $3; }
|
|
|
|
|
| '{' error '}' { $$ = $3; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
member_specification_opt:
|
|
|
|
|
/* empty */ { $$ = NULL; }
|
|
|
|
|
| member_specification
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
member_specification:
|
|
|
|
|
member_declaration
|
|
|
|
|
| member_specification member_declaration { $$ = $2; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
member_declaration:
|
|
|
|
|
decl_specifier_seq_opt member_declarator_list_opt ';'
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
{ $$ = $3; dont_want_type_specifier = false; }
|
2005-04-16 15:20:36 -07:00
|
|
|
| error ';'
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
{ $$ = $2; dont_want_type_specifier = false; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
member_declarator_list_opt:
|
|
|
|
|
/* empty */ { $$ = NULL; }
|
|
|
|
|
| member_declarator_list
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
member_declarator_list:
|
|
|
|
|
member_declarator
|
genksyms: fix 6 shift/reduce conflicts and 5 reduce/reduce conflicts
The genksyms parser has ambiguities in its grammar, which are currently
suppressed by a workaround in scripts/genksyms/Makefile.
Building genksyms with W=1 generates the following warnings:
YACC scripts/genksyms/parse.tab.[ch]
scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
The comment in the parser describes the current problem:
/* This wasn't really a typedef name but an identifier that
shadows one. */
Consider the following simple C code:
typedef int foo;
void my_func(foo foo) {}
In the function parameter list (foo foo), the first 'foo' is a type
specifier (typedef'ed as 'int'), while the second 'foo' is an identifier.
However, the lexer cannot distinguish between the two. Since 'foo' is
already typedef'ed, the lexer returns TYPE for both instances, instead
of returning IDENT for the second one.
To support shadowed identifiers, TYPE can be reduced to either a
simple_type_specifier or a direct_abstract_declarator, which creates
a grammatical ambiguity.
Without analyzing the grammar context, it is very difficult to resolve
this correctly.
This commit introduces a flag, dont_want_type_specifier, which allows
the parser to inform the lexer whether an identifier is expected. When
dont_want_type_specifier is true, the type lookup is suppressed, and
the lexer returns IDENT regardless of any preceding typedef.
After this commit, only 3 shift/reduce conflicts will remain.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Nicolas Schier <n.schier@avm.de>
2025-01-14 00:00:42 +09:00
|
|
|
{ $$ = $1; dont_want_type_specifier = true; }
|
|
|
|
|
| member_declarator_list ',' member_declarator
|
|
|
|
|
{ $$ = $3; dont_want_type_specifier = true; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
member_declarator:
|
|
|
|
|
nested_declarator attribute_opt { $$ = $2 ? $2 : $1; }
|
|
|
|
|
| IDENT member_bitfield_declarator { $$ = $2; }
|
|
|
|
|
| member_bitfield_declarator
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
member_bitfield_declarator:
|
|
|
|
|
':' EXPRESSION_PHRASE { $$ = $2; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
attribute_opt:
|
|
|
|
|
/* empty */ { $$ = NULL; }
|
2025-01-14 00:00:47 +09:00
|
|
|
| attribute_opt ATTRIBUTE_PHRASE { $$ = $2; }
|
2005-04-16 15:20:36 -07:00
|
|
|
;
|
|
|
|
|
|
2011-02-03 23:57:09 +01:00
|
|
|
enum_body:
|
|
|
|
|
'{' enumerator_list '}' { $$ = $3; }
|
|
|
|
|
| '{' enumerator_list ',' '}' { $$ = $4; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
enumerator_list:
|
|
|
|
|
enumerator
|
|
|
|
|
| enumerator_list ',' enumerator
|
|
|
|
|
|
|
|
|
|
enumerator:
|
|
|
|
|
IDENT
|
|
|
|
|
{
|
2025-01-03 16:30:39 +09:00
|
|
|
const char *name = (*$1)->string;
|
2011-02-03 23:57:09 +01:00
|
|
|
add_symbol(name, SYM_ENUM_CONST, NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
| IDENT '=' EXPRESSION_PHRASE
|
|
|
|
|
{
|
2025-01-03 16:30:39 +09:00
|
|
|
const char *name = (*$1)->string;
|
2011-02-03 23:57:09 +01:00
|
|
|
struct string_list *expr = copy_list_range(*$3, *$2);
|
|
|
|
|
add_symbol(name, SYM_ENUM_CONST, expr, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
asm_definition:
|
|
|
|
|
ASM_PHRASE ';' { $$ = $2; }
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
asm_phrase_opt:
|
|
|
|
|
/* empty */ { $$ = NULL; }
|
|
|
|
|
| ASM_PHRASE
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
export_definition:
|
|
|
|
|
EXPORT_SYMBOL_KEYW '(' IDENT ')' ';'
|
|
|
|
|
{ export_symbol((*$3)->string); $$ = $5; }
|
|
|
|
|
;
|
|
|
|
|
|
2020-12-01 16:20:18 +01:00
|
|
|
/* Ignore any module scoped _Static_assert(...) */
|
|
|
|
|
static_assert:
|
|
|
|
|
STATIC_ASSERT_PHRASE ';' { $$ = $2; }
|
|
|
|
|
;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
yyerror(const char *e)
|
|
|
|
|
{
|
|
|
|
|
error_with_pos("%s", e);
|
|
|
|
|
}
|