Skip to content

protect instructiont::code #5908

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
Mar 15, 2021
Merged

protect instructiont::code #5908

merged 2 commits into from
Mar 15, 2021

Conversation

kroening
Copy link
Member

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

@codecov
Copy link

codecov bot commented Mar 10, 2021

Codecov Report

Merging #5908 (99afbae) into develop (76ad937) will increase coverage by 0.00%.
The diff coverage is 70.64%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5908   +/-   ##
========================================
  Coverage    73.54%   73.55%           
========================================
  Files         1431     1431           
  Lines       155229   155245   +16     
========================================
+ Hits        114163   114188   +25     
+ Misses       41066    41057    -9     
Impacted Files Coverage Δ
src/analyses/cfg_dominators.h 100.00% <ø> (ø)
src/analyses/global_may_alias.cpp 0.00% <0.00%> (ø)
src/goto-cc/linker_script_merge.cpp 0.00% <0.00%> (ø)
.../goto-instrument/accelerate/acceleration_utils.cpp 2.27% <0.00%> (ø)
...o-instrument/accelerate/polynomial_accelerator.cpp 0.00% <0.00%> (ø)
src/goto-instrument/concurrency.cpp 0.00% <0.00%> (ø)
src/goto-instrument/dot.cpp 0.00% <0.00%> (ø)
src/goto-instrument/function_modifies.cpp 0.00% <0.00%> (ø)
src/goto-instrument/rw_set.cpp 0.00% <0.00%> (ø)
src/goto-instrument/thread_instrumentation.cpp 0.00% <0.00%> (ø)
... and 82 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 e0a6f44...99afbae. 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 am aware that quite a few of my comments amount to shooting-the-messenger, but I really think we need to use this opportunity to fix the code.

Comment on lines 425 to +426
instr_it->type=ASSIGN;
instr_it->code=assignment;
instr_it->code_nonconst() = assignment;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't we instead replace the entire instruction here?

@@ -93,7 +93,7 @@ static std::pair<goto_programt::targett, bool> insert_nondet_init_code(
// We only expect to find nondets in the rhs of an assignments, and in return
// statements if remove_returns has not been run, but we do a more general
// check on all operands in case this changes
for(exprt &op : target->code.operands())
for(exprt &op : target->code_nonconst().operands())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be replaced by a call to instructiont::transform.

Comment on lines +247 to +249
if(
target->is_target() && (contains_instanceof(target->get_code()) ||
contains_instanceof(target->guard)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be handled via instructiont::transform.

Comment on lines +284 to 286
target_instruction->code_nonconst() = code_returnt(inserted_expr);
target_instruction->code_nonconst().add_source_location() =
target_instruction->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.

Why did we ever need to replace the entire code - wouldn't the return_value() suffice?

Comment on lines +298 to 301
target_instruction->code_nonconst() =
code_assignt(nondet_var, inserted_expr);
target_instruction->code_nonconst().add_source_location() =
target_instruction->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.

Just like the above: it's an ASSIGN instruction already, don't we just need to replace lhs/rhs here?

@@ -61,7 +61,7 @@ void label_function_pointer_call_sites(goto_modelt &goto_model)

goto_function.second.body.insert_before_swap(it, assign_instruction);
const auto next = std::next(it);
to_code_function_call(next->code).function() =
to_code_function_call(next->code_nonconst()).function() =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use set_function_call

@@ -36,7 +36,7 @@ static void rename_symbols_in_function(

for(auto &instruction : function.body.instructions)
{
rename_symbol(instruction.code);
rename_symbol(instruction.code_nonconst());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use instructiont::transform

}

{
goto_programt::targett assignment = tmp.add(goto_programt::make_assignment(
member(lhs, whatt::SIZE),
member(rhs, whatt::SIZE),
target->source_location));
assignment->code.add_source_location()=target->source_location;
assignment->code_nonconst().add_source_location() = target->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.

This line should not be necessary.

}

{
goto_programt::targett assignment = tmp.add(goto_programt::make_assignment(
member(lhs, whatt::LENGTH),
member(rhs, whatt::LENGTH),
target->source_location));
assignment->code.add_source_location()=target->source_location;
assignment->code_nonconst().add_source_location() = target->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.

This line should not be necessary.

@@ -882,5 +882,5 @@ void string_instrumentationt::invalidate_buffer(
const side_effect_expr_nondett nondet(
buf_type.subtype(), target->source_location);

invalidate->code=code_assignt(deref, nondet);
invalidate->code_nonconst() = code_assignt(deref, nondet);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use set_assign

@kroening
Copy link
Member Author

The suggested changes are all agreed -- but should come as a separate PR, to keep this reviewable.

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.

Approving under the assumption that the follow-up PR will be created that cleans up most (all?) uses of code_nonconst() as suggested in my earlier comments.

This replaces direct access to instructiont::code to the provided API for
the case of assignment and function call instructions.
This PR is a step towards removing direct access to instructiont::code, with
the long-term goal of removing the use of codet expressions in goto programs.
@kroening kroening merged commit 1ea6f18 into develop Mar 15, 2021
@kroening kroening deleted the code_nonconst branch March 15, 2021 11:48
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.

3 participants