Skip to content

Byte-update lowering: handle sub-byte sized bit fields #5390

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
Nov 7, 2020

Conversation

tautschnig
Copy link
Collaborator

Extend the value to be updated to the update size immediately to avoid
extractbits operations that attempt to extract bits that do not exist.

Fixes: #5389

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

@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #5390 (e16b7db) into develop (bf62883) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #5390   +/-   ##
========================================
  Coverage    68.52%   68.52%           
========================================
  Files         1187     1187           
  Lines        98265    98271    +6     
========================================
+ Hits         67339    67345    +6     
  Misses       30926    30926           
Flag Coverage Δ
cproversmt2 43.08% <72.00%> (+0.11%) ⬆️
regression 65.70% <64.00%> (+0.01%) ⬆️
unit 32.26% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
src/solvers/lowering/byte_operators.cpp 83.96% <100.00%> (+0.12%) ⬆️

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 bf62883...e16b7db. Read the comment docs.

@@ -2136,10 +2136,30 @@ static exprt lower_byte_update(
instantiate_byte_array(value_as_byte_array, 0, (type_bits + 7) / 8, ns);
}

const std::size_t update_size = update_bytes.size();
Copy link
Contributor

Choose a reason for hiding this comment

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

While we're here: recommend always using unit suffixes in this code (update_size_bytes, width_bits)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,8 @@
CORE
Copy link
Contributor

Choose a reason for hiding this comment

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

Tests: can we test behaviour in the other endianness somehow?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Setting the --arch flags appropriately should do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think endianness actually matters in this test?

if(b.dummy <= sizeof(struct blob))
memset(&b, 0, b.dummy);

assert(b1.dummy != sizeof(struct blob) || b.bit == 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Brutal! If you are need to change things in this PR, please could you add a comment or two here to explain what you are testing because I fear that people without your knowledge of C struct packing rules and how they relate to bit-fields might miss some of the subtlety here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

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.

Looks good.

@@ -0,0 +1,8 @@
CORE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Setting the --arch flags appropriately should do it.

@feliperodri
Copy link
Collaborator

@tautschnig can we merge this PR and close #5389?

@feliperodri feliperodri added the aws Bugs or features of importance to AWS CBMC users label Oct 15, 2020
Extend the value to be updated to the update size immediately to avoid
extractbits operations that attempt to extract bits that do not exist.

Fixes: diffblue#5389
Use variable names that immediately clarify that widths are measured in
bits.
@tautschnig tautschnig force-pushed the fix-bitfield-byte-update branch from 54411e0 to e16b7db Compare November 6, 2020 23:04
@tautschnig tautschnig self-assigned this Nov 6, 2020
@tautschnig tautschnig merged commit b4d939b into diffblue:develop Nov 7, 2020
@tautschnig tautschnig deleted the fix-bitfield-byte-update branch November 7, 2020 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invariant check failed when using memset
4 participants