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

Conversation

hannes-steffenhagen-diffblue
Copy link
Contributor

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue commented Jul 30, 2020

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

There are currently two issues preventing us from parsing Apple's CoreFoundation framework: For one, we still don't quite parse underlying enum types correctly, so for example

enum A : unsigned int { AV };

and

enum B : uint32_t { BV };

would previously fail to parse, and we didn't allow gcc-style attributes after a functions parameter list:

int some_function(int argument) __attribute__((this_previously_wasn't_allowed));

which gcc itself doesn't permit either but is valid in Clang's C dialect, and used this way by Apple across their frameworks for their API_AVAILABLE and API_UNAVAILABLE macros.

This fixes both of these issues.

Our previous attempt only worked with names like `short` or `unsigned`, but not
with e.g. `unsigned short` or `uint32_t`. This patch rectifies that.

Note that unlike clang we currently don't allow CV qualifiers for underlying
types. Since these are ignored by clang anyway, we don't expect to see too much
code in the wild making use of that feature however.
--
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ Missing newline.

@@ -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.

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue force-pushed the tmp/grammar-issues branch 2 times, most recently from c4840a3 to 712c221 Compare July 30, 2020 19:30
With postfix attributes we mean something like

    int f() __attribute__((in this position));

This is used in Apple's CoreFoundation framework so our inability to parse this
was limiting CBMC usability for code written for Apple operating systems.
@codecov
Copy link

codecov bot commented Jul 30, 2020

Codecov Report

Merging #5438 into develop will decrease coverage by 35.95%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #5438       +/-   ##
============================================
- Coverage    68.21%   32.26%   -35.96%     
============================================
  Files         1178      923      -255     
  Lines        97561    81128    -16433     
============================================
- Hits         66554    26178    -40376     
- Misses       31007    54950    +23943     
Flag Coverage Δ
#cproversmt2 ?
#regression ?
#unit 32.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/ansi-c/parser.y 24.20% <ø> (-53.84%) ⬇️
src/cpp/cpp_id.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_scope.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_token.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_name.cpp 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_util.cpp 0.00% <0.00%> (-100.00%) ⬇️
src/util/identifier.h 0.00% <0.00%> (-100.00%) ⬇️
src/xmllang/graphml.h 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/cpp_is_pod.cpp 0.00% <0.00%> (-100.00%) ⬇️
src/cpp/template_map.h 0.00% <0.00%> (-100.00%) ⬇️
... and 897 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b45ff46...7d2a23b. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 30, 2020

Codecov Report

Merging #5438 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5438   +/-   ##
========================================
  Coverage    68.21%   68.21%           
========================================
  Files         1178     1178           
  Lines        97561    97561           
========================================
  Hits         66554    66554           
  Misses       31007    31007           
Flag Coverage Δ
#cproversmt2 42.77% <ø> (ø)
#regression 65.38% <ø> (ø)
#unit 32.26% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/ansi-c/parser.y 78.03% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b45ff46...7d2a23b. Read the comment docs.

Copy link
Contributor

@chrisr-diffblue chrisr-diffblue left a comment

Choose a reason for hiding this comment

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

My Yacc skills are quite rusty.... but I think this looks OK to me.

@hannes-steffenhagen-diffblue hannes-steffenhagen-diffblue merged commit eefd06f into diffblue:develop Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants