Skip to content

Interpreter: de-duplicate code #2289

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 7 commits into from
Nov 11, 2020

Conversation

tautschnig
Copy link
Collaborator

evaluate_address(byte_extract) and evaluate(byte_extract) had almost the same
implementation.

This commit previously was part of #2165, but I suspect it is somewhat broken as #2165 previously broke test-gen. Awaiting feedback from the automatic reviewer.

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

@tautschnig tautschnig force-pushed the interpreter-deduplicate branch from 54ed588 to 9bae4ad Compare September 28, 2018 09:46
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: 9bae4ad).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/86270759

@tautschnig tautschnig force-pushed the interpreter-deduplicate branch from 9bae4ad to f36c08c Compare February 25, 2019 08:49
@tautschnig
Copy link
Collaborator Author

We do not have any tests of the interpreter in the code base (which is a shame), and AFAIK this changed caused some trouble. Assigning to @peterschrammel with the hope to receive some guidance, but if anyone else could contribute tests of the interpreter that would be much appreciated.

@tautschnig tautschnig added Needs TG approval 🦉 Only merge with explicit approval from test-gen maintainers and removed do not merge labels Feb 25, 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.

🚫
This PR failed Diffblue compatibility checks (cbmc commit: f36c08c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/102126796
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

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

In principle looks fine (And a preliminary run of TG looks OK too) - but in the interest of helping anyone who ends up git blaming an obsecure bug this introduces could the removal of calling byte_offset_to_memory_offset be some how factored into a separate commit.

else if(expr.id()==ID_byte_extract_little_endian ||
expr.id()==ID_byte_extract_big_endian)
{
if(expr.operands().size()!=2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting this sanity check on byte_extract is being deleted.

mp_integer memory_offset;
// If memory offset is found (which should normally be the case)
// extract the corresponding data from the appropriate memory location
if(!byte_offset_to_memory_offset(
Copy link
Contributor

Choose a reason for hiding this comment

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

You remove this check. No idea what it does, but it should probably be removed in a separate commit to make the move clearer.

numeric_cast_v<std::size_t>(memory_offset + target_type_leaves));
return;
}
// we fail
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesn't seem quite right - we don't fail - we carry on to the next if - perhaps a throw here, or a return?

if(!unbounded_size(expr.type()))
{
dest.resize(numeric_cast_v<std::size_t>(get_size(expr.type())));
read(address, dest);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

This return is redundant. Probably an indication that just pulling out this whole branch into a function might make it a little easier to follow.

@tautschnig tautschnig force-pushed the interpreter-deduplicate branch from f36c08c to 936ca70 Compare November 7, 2020 14:34
@codecov
Copy link

codecov bot commented Nov 7, 2020

Codecov Report

Merging #2289 (eba686f) into develop (37fb0c0) will increase coverage by 0.47%.
The diff coverage is 94.11%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2289      +/-   ##
===========================================
+ Coverage    68.53%   69.01%   +0.47%     
===========================================
  Files         1187     1187              
  Lines        98262    98258       -4     
===========================================
+ Hits         67346    67810     +464     
+ Misses       30916    30448     -468     
Flag Coverage Δ
cproversmt2 43.09% <ø> (ø)
regression 66.21% <94.11%> (+0.49%) ⬆️
unit 32.26% <6.25%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
src/goto-programs/interpreter.cpp 51.60% <92.30%> (+51.60%) ⬆️
src/goto-programs/interpreter_evaluate.cpp 31.99% <93.75%> (+29.99%) ⬆️
.../goto-instrument/goto_instrument_parse_options.cpp 59.31% <100.00%> (+0.52%) ⬆️
src/goto-programs/interpreter_class.h 55.55% <100.00%> (+41.66%) ⬆️
src/util/sparse_vector.h 100.00% <100.00%> (+66.66%) ⬆️
src/big-int/bigint.cc 88.86% <0.00%> (+0.56%) ⬆️
src/util/mp_arith.cpp 48.59% <0.00%> (+8.45%) ⬆️
... and 1 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 37fb0c0...eba686f. Read the comment docs.

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

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

Am fine with the changes but ... can we have a test case because the interpreter is dangerously under tested.

@tautschnig tautschnig force-pushed the interpreter-deduplicate branch 2 times, most recently from d9b0680 to f30ef69 Compare November 11, 2020 02:02
@tautschnig tautschnig force-pushed the interpreter-deduplicate branch 2 times, most recently from 266d167 to c2f20aa Compare November 11, 2020 15:22
This first commit just tests that help output can be generated.
Previous help output was misleading and incomplete.
The iterator was never initialised, but still being compared to, which
is undefined behaviour.
Fix basic execution as sparse vectors do not (yet) support resizing to
smaller sizes (performing a clear+resize instead).
The memory map is (only) printed upon a user's request (using the "m"
command). It should not be necessary to raise verbosity to debug level
to see this output.
"s" without a suffix or with a suffix that is not one of [aeo0-9]
previously resulted in an invariant violation. Also make "r0" actually
work by fixing the assumptions about the structure of the top-level
function.
evaluate_address(byte_extract) and evaluate(byte_extract) had almost the
same implementation. Instead of the duplication, use `evaluate_address`
to implement `evaluate` and just handle the remaining bits in
`evaluate`.

byte_extract still has a number of problems, as the regression test
shows: addressing works at the object level, not at the level of
individual bytes. Thus we can compute the correct address, but still
wouldn't access the right bytes.
@tautschnig tautschnig force-pushed the interpreter-deduplicate branch from c2f20aa to eba686f Compare November 11, 2020 19:38
@tautschnig tautschnig merged commit ff1e81e into diffblue:develop Nov 11, 2020
@tautschnig tautschnig deleted the interpreter-deduplicate branch November 11, 2020 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs TG approval 🦉 Only merge with explicit approval from test-gen maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants