Skip to content

Commit eefd06f

Browse files
Merge pull request #5438 from hannes-steffenhagen-diffblue/tmp/grammar-issues
Fix Bison grammar issues preventing us from parsing CoreFoundation
2 parents c82daba + 7d2a23b commit eefd06f

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
typedef unsigned short USHORT;
2+
3+
enum A : USHORT
4+
{
5+
AV
6+
};
7+
enum B : unsigned short
8+
{
9+
BV
10+
};
11+
enum C : signed long long
12+
{
13+
CV
14+
};
15+
16+
int main(void)
17+
{
18+
return 0;
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^PARSING ERROR$
8+
--
9+
A previous attempt to allow underlying type specifications didn't allow typedef
10+
names or multi word types (e.g. unsigned int). We still don't actually fully
11+
apply the underlying type to the enum, but this at least lets us use parse code
12+
that uses this feature.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
inline int inline_function_with_postfix_attributes(void)
2+
__attribute__((not_a_real_attribute))
3+
{
4+
return 0;
5+
}
6+
7+
int non_inline_with_postfix_attributes(void)
8+
__attribute__((not_a_real_attribute))
9+
{
10+
return 0;
11+
}
12+
13+
int main(void)
14+
{
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE gcc-only
2+
test.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^PARSING ERROR$
8+
--
9+
gcc doesn't support postfix attributes but clang does, and Apples CoreFoundation framework makes use of this for availability macros.
10+
11+
Testing both the inline and non-inline variants because these are different cases in our parser.

src/ansi-c/parser.y

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,13 +1837,21 @@ enum_name:
18371837
}
18381838
;
18391839

1840+
basic_type_name_list:
1841+
basic_type_name
1842+
| basic_type_name_list basic_type_name
1843+
1844+
enum_underlying_type:
1845+
basic_type_name_list
1846+
| typedef_name
1847+
18401848
enum_underlying_type_opt:
18411849
/* empty */
18421850
{
18431851
init($$);
18441852
parser_stack($$).make_nil();
18451853
}
1846-
| ':' basic_type_name
1854+
| ':' enum_underlying_type
18471855
{
18481856
$$=$2;
18491857
}
@@ -2995,14 +3003,14 @@ function_head:
29953003
PARSER.add_declarator(parser_stack($$), parser_stack($1));
29963004
create_function_scope($$);
29973005
}
2998-
| declaration_specifier declarator
3006+
| declaration_specifier declarator post_declarator_attributes_opt
29993007
{
30003008
init($$, ID_declaration);
30013009
parser_stack($$).type().swap(parser_stack($1));
30023010
PARSER.add_declarator(parser_stack($$), parser_stack($2));
30033011
create_function_scope($$);
30043012
}
3005-
| type_specifier declarator
3013+
| type_specifier declarator post_declarator_attributes_opt
30063014
{
30073015
init($$, ID_declaration);
30083016
parser_stack($$).type().swap(parser_stack($1));

0 commit comments

Comments
 (0)