Skip to content

Fix Bison grammar issues preventing us from parsing CoreFoundation #5438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions regression/ansi-c/enum_with_underlying_type/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
typedef unsigned short USHORT;

enum A : USHORT
{
AV
};
enum B : unsigned short
{
BV
};
enum C : signed long long
{
CV
};

int main(void)
{
return 0;
}
12 changes: 12 additions & 0 deletions regression/ansi-c/enum_with_underlying_type/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
test.c

^EXIT=0$
^SIGNAL=0$
--
^PARSING ERROR$
--
A previous attempt to allow underlying type specifications didn't allow typedef
names or multi word types (e.g. unsigned int). We still don't actually fully
apply the underlying type to the enum, but this at least lets us use parse code
that uses this feature.
15 changes: 15 additions & 0 deletions regression/ansi-c/function_with_postfix_attributes/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
inline int inline_function_with_postfix_attributes(void)
__attribute__((not_a_real_attribute))
{
return 0;
}

int non_inline_with_postfix_attributes(void)
__attribute__((not_a_real_attribute))
{
return 0;
}

int main(void)
{
}
11 changes: 11 additions & 0 deletions regression/ansi-c/function_with_postfix_attributes/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE gcc-only
test.c

^EXIT=0$
^SIGNAL=0$
--
^PARSING ERROR$
--
gcc doesn't support postfix attributes but clang does, and Apples CoreFoundation framework makes use of this for availability macros.

Testing both the inline and non-inline variants because these are different cases in our parser.
14 changes: 11 additions & 3 deletions src/ansi-c/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1837,13 +1837,21 @@ enum_name:
}
;

basic_type_name_list:
basic_type_name
| basic_type_name_list basic_type_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ We probably want something like the following, in order to actually build the list -

  | basic_type_name_list basic_type_name
  {
    $$=merge($1, $2);
  }
  ;

I have added this ℹ️ comment as a note about future work which will likely be needed eventually. This is not a blocking comment.

Copy link
Contributor Author

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue Jul 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For onlookers: actually fully supporting this feature is in the pipeline, just getting this. to parse is higher priority though so it comes first.


enum_underlying_type:
basic_type_name_list
| typedef_name

enum_underlying_type_opt:
/* empty */
{
init($$);
parser_stack($$).make_nil();
}
| ':' basic_type_name
| ':' enum_underlying_type
{
$$=$2;
}
Expand Down Expand Up @@ -2995,14 +3003,14 @@ function_head:
PARSER.add_declarator(parser_stack($$), parser_stack($1));
create_function_scope($$);
}
| declaration_specifier declarator
| declaration_specifier declarator post_declarator_attributes_opt
{
init($$, ID_declaration);
parser_stack($$).type().swap(parser_stack($1));
PARSER.add_declarator(parser_stack($$), parser_stack($2));
create_function_scope($$);
}
| type_specifier declarator
| type_specifier declarator post_declarator_attributes_opt
{
init($$, ID_declaration);
parser_stack($$).type().swap(parser_stack($1));
Expand Down