Skip to content

fix exprt::opX() accesses in cpp/ #4984

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 1 commit into from
Oct 22, 2019
Merged

fix exprt::opX() accesses in cpp/ #4984

merged 1 commit into from
Oct 22, 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.

Various requests for somewhat minor changes.

side_effect_expr_function_callt &func_ini=
to_side_effect_expr_function_call(initializer.op0());
side_effect_expr_function_callt &func_ini =
to_side_effect_expr_function_call(to_unary_expr(initializer).op());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems wrong: we above assert that it's a statement expression.

Copy link
Member Author

Choose a reason for hiding this comment

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

The side_effect_expr_function_call is the operand of the statement expression.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, sorry, my comment was unclear: I think using to_unary_expr on something that actually is a codet seems wrong (even when the type system currently permits it).

Copy link
Member Author

Choose a reason for hiding this comment

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

Now using side_effect_expr_statement_expressiont

assert(decl.op0().op0().id()==ID_symbol);
value = decl.op0().op0();
DATA_INVARIANT(
to_unary_expr(decl).op().op0().id() == ID_symbol,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How do we know that the .op0() is safe here?

Copy link
Member Author

Choose a reason for hiding this comment

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

added a check

assign.copy_to_operands(op0.as_expr());
assign.op0().add_source_location() = source_location;
assign.copy_to_operands(op1);
assign.copy_to_operands(op0.as_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.

Could use the side_effect_exprt constructor that also takes operands?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, done

assign.op0().add_source_location() = source_location;
assign.copy_to_operands(op1);
assign.copy_to_operands(op0.as_expr(), op1);
to_binary_expr(assign).op0().add_source_location() = source_location;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doing to_binary_expr on a side_effect_exprt feels very wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

now uses side_effect_expr_assignt

assign.op1().add_source_location() = source_location;

to_binary_expr(assign).op0().add_source_location() = source_location;
to_binary_expr(assign).op1().add_source_location() = source_location;
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above: use the side_effect_exprt constructor that takes operands, and use some other approach instead of applying to_binary_expr on a side_effect_exprt.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed as above

@@ -295,7 +294,7 @@ void cpp_typecheckt::default_assignop(
cpctor.operands().push_back(exprt(ID_cpp_declarator));
cpctor.add_source_location()=source_location;

cpp_declaratort &declarator=(cpp_declaratort&) cpctor.op0();
cpp_declaratort &declarator = (cpp_declaratort &)cpctor.op0();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like a whitespace-only change, but maybe we can actually get rid of the C-style cast?

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

assert(returned_value.id()==ID_dereference &&
is_reference(returned_value.op0().type()));
assert(
returned_value.id() == ID_dereference &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems unnecessary as the second conjunct now uses to_dereference_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

assert(src.operands().size()==2);
return convert(src.op0())+"["+convert(src.op1())+"]";
return convert(to_binary_expr(src).op0()) + "[" +
convert(to_binary_expr(src).op1()) + "]";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use to_extractbit_expr instead?

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

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: 7f48ddc).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/121919890

@codecov-io
Copy link

codecov-io commented Aug 5, 2019

Codecov Report

Merging #4984 into develop will decrease coverage by <.01%.
The diff coverage is 71.07%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4984      +/-   ##
===========================================
- Coverage    69.56%   69.56%   -0.01%     
===========================================
  Files         1314     1314              
  Lines       108922   108945      +23     
===========================================
+ Hits         75776    75786      +10     
- Misses       33146    33159      +13
Impacted Files Coverage Δ
src/cpp/cpp_typecheck.cpp 79.13% <ø> (ø) ⬆️
src/cpp/cpp_typecheck_conversions.cpp 70.95% <0%> (-0.72%) ⬇️
src/cpp/expr2cpp.cpp 42.37% <0%> (-0.49%) ⬇️
src/cpp/cpp_static_assert.h 100% <100%> (ø) ⬆️
src/cpp/cpp_typecheck_constructor.cpp 83.33% <100%> (+0.11%) ⬆️
src/cpp/cpp_typecheck_function.cpp 94.44% <100%> (+0.21%) ⬆️
src/cpp/cpp_constructor.cpp 69.07% <100%> (+0.32%) ⬆️
src/cpp/cpp_typecheck_resolve.cpp 65.61% <100%> (+0.04%) ⬆️
src/cpp/cpp_typecheck_fargs.cpp 86.66% <100%> (ø) ⬆️
src/cpp/cpp_typecheck_compound_type.cpp 85.64% <100%> (ø) ⬆️
... and 5 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 b8302cf...e8c4be1. Read the comment docs.

@kroening kroening force-pushed the cpp-opX branch 2 times, most recently from 8f1a0be to 37fe7c7 Compare August 13, 2019 13:55
@kroening kroening assigned tautschnig and unassigned kroening Aug 13, 2019
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: 37fe7c7).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/123007942

@kroening kroening force-pushed the cpp-opX branch 3 times, most recently from 887e2b1 to e8c4be1 Compare August 23, 2019 14:26
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: e8c4be1).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/124393808

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: f69bbac).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/131395568

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: 9ff2a56).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/131642359

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.

Looks good except for one new issue that needs to be fixed.

Comment on lines 201 to 204
DATA_INVARIANT(
to_code_decl(to_code(to_unary_expr(decl).op())).symbol().id() ==
ID_symbol,
"declaration must have symbol as operand");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This DATA_INVARIANT cannot fail, because to_code_decl will already fail its code_declt::check(code);

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

@tautschnig tautschnig assigned kroening and unassigned tautschnig Oct 18, 2019
This improves type safety.
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: 6457a5e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/132910648

@kroening kroening merged commit 7a70b13 into develop Oct 22, 2019
@kroening kroening deleted the cpp-opX branch October 22, 2019 01:15
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