-
Notifications
You must be signed in to change notification settings - Fork 277
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
Conversation
kroening
commented
Mar 10, 2021
- 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 Report
@@ Coverage Diff @@
## develop #5908 +/- ##
========================================
Coverage 73.54% 73.55%
========================================
Files 1431 1431
Lines 155229 155245 +16
========================================
+ Hits 114163 114188 +25
+ Misses 41066 41057 -9
Continue to review full report at Codecov.
|
There was a problem hiding this 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.
instr_it->type=ASSIGN; | ||
instr_it->code=assignment; | ||
instr_it->code_nonconst() = assignment; |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
.
if( | ||
target->is_target() && (contains_instanceof(target->get_code()) || | ||
contains_instanceof(target->guard))) |
There was a problem hiding this comment.
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
.
target_instruction->code_nonconst() = code_returnt(inserted_expr); | ||
target_instruction->code_nonconst().add_source_location() = | ||
target_instruction->source_location; |
There was a problem hiding this comment.
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?
target_instruction->code_nonconst() = | ||
code_assignt(nondet_var, inserted_expr); | ||
target_instruction->code_nonconst().add_source_location() = | ||
target_instruction->source_location; |
There was a problem hiding this comment.
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() = |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use set_assign
The suggested changes are all agreed -- but should come as a separate PR, to keep this reviewable. |
There was a problem hiding this 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.