Skip to content

fix accesses to exprt::opX() in ansi-c/ #4983

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
merged 2 commits into from
Aug 6, 2019
Merged

fix accesses to exprt::opX() in ansi-c/ #4983

merged 2 commits into from
Aug 6, 2019

Conversation

kroening
Copy link
Member

@kroening kroening commented Aug 4, 2019

This improves type safety.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a 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).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

This seems to be removing a bunch of user-facing error messages. Either these were dead code or we are now going to produce invariant violations that can be triggered by input files, which would be entirely wrong.

@tautschnig tautschnig assigned kroening and unassigned tautschnig Aug 4, 2019
@kroening
Copy link
Member Author

kroening commented Aug 4, 2019

@tautschnig I did think about those error messages: the conditions checked by them should be post-conditions of the parser, i.e., it should be impossible for a user to trigger these.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 117a17c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121881987

@tautschnig
Copy link
Collaborator

@tautschnig I did think about those error messages: the conditions checked by them should be post-conditions of the parser, i.e., it should be impossible for a user to trigger these.

Seems fair. In that case, can all the to_unary_expr, to_binary_expr please be done as early in the control flow as possible? It will not always be possible, but in many cases the typecheck_... method should take a unary_exprt etc rather than doing this conversion within the method, often doing so multiple times.

@kroening
Copy link
Member Author

kroening commented Aug 5, 2019

@tautschnig Yes, agreed -- these should be early. That will touch both the ansi-c and C++ front-ends, and we would need to think about a mechanism similar to what we've done in the simplifier. The problem is that some of the typechecking methods change the type of what's being checked.

@tautschnig
Copy link
Collaborator

The problem is that some of the typechecking methods change the type of what's being checked.

While that's certainly true we don't change the number of operands, do we? So using unary_exprt, binary_exprt should be fine?

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 79b35a6).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121921747

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

I've only reviewed about the first half, but my comments seemed to repeat a lot so I think those should be addressed across the PR (or discussed and resolved) first.

@kroening
Copy link
Member Author

kroening commented Aug 5, 2019

While that's certainly true we don't change the number of operands, do we? So using unary_exprt, binary_exprt should be fine?

Yes, we may change the number of operands, at least in some places.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 7e20208).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121946683

@codecov-io
Copy link

Codecov Report

Merging #4983 into develop will increase coverage by 0.01%.
The diff coverage is 72.63%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4983      +/-   ##
===========================================
+ Coverage    69.24%   69.26%   +0.01%     
===========================================
  Files         1309     1309              
  Lines       108476   108430      -46     
===========================================
- Hits         75117    75102      -15     
+ Misses       33359    33328      -31
Impacted Files Coverage Δ
src/util/std_code.h 92.19% <ø> (+1%) ⬆️
src/ansi-c/ansi_c_convert_type.cpp 82.63% <ø> (+0.19%) ⬆️
src/ansi-c/c_typecheck_base.h 100% <ø> (ø) ⬆️
src/ansi-c/c_typecheck_code.cpp 82.1% <100%> (-0.06%) ⬇️
src/ansi-c/ansi_c_language.cpp 97.26% <100%> (+0.03%) ⬆️
src/ansi-c/parser.y 78.08% <100%> (ø) ⬆️
src/ansi-c/c_typecheck_base.cpp 80.89% <100%> (ø) ⬆️
src/ansi-c/c_typecheck_type.cpp 76.08% <100%> (+0.08%) ⬆️
src/ansi-c/expr2c.cpp 67.04% <30%> (-0.1%) ⬇️
src/ansi-c/c_typecheck_expr.cpp 73.61% <73.17%> (+1.08%) ⬆️
... and 3 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 602e2e8...7e20208. Read the comment docs.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

I've resolved all the comments that won't be fixed in this PR, but some others remain open and I added a few more now that I made it through the entire PR.

exprt &op0=expr.op0();
exprt &op1=expr.op1();
exprt &op0 = to_binary_expr(expr).op0();
exprt &op1 = to_binary_expr(expr).op1();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should do to_binary_expr just once.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

exprt &op0=expr.op0();
exprt &op1=expr.op1();
exprt &op0 = to_binary_expr(expr).op0();
exprt &op1 = to_binary_expr(expr).op1();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should do to_binary_expr just once.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

DATA_INVARIANT(
as_expr.operands().size() == 1,
"typeof of an expression must have one operand");
exprt expr = to_unary_expr(as_expr).op();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this DATA_INVARIANT here when elsewhere we just use to_unary_expr?

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 9ae4c37).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/122016024

@tautschnig tautschnig merged commit 33c00c1 into develop Aug 6, 2019
@tautschnig tautschnig deleted the ansi-c-opX branch August 6, 2019 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants