Skip to content
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

Extend expr_initializer to support byte-wise initialization #7392

Merged
merged 5 commits into from
Aug 1, 2023

Conversation

peterschrammel
Copy link
Member

Each byte of the expression is initialized to the given initialization expression, if possible.

This building block will be required for the shadow memory implementation.

  • 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.
  • 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).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Nov 28, 2022

Codecov Report

Patch coverage: 98.62% and project coverage change: -0.04% ⚠️

Comparison is base (f868847) 78.68% compared to head (e049de7) 78.64%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7392      +/-   ##
===========================================
- Coverage    78.68%   78.64%   -0.04%     
===========================================
  Files         1698     1698              
  Lines       194124   194608     +484     
===========================================
+ Hits        152740   153052     +312     
- Misses       41384    41556     +172     
Files Changed Coverage Δ
src/util/expr_initializer.cpp 83.07% <89.39%> (-3.45%) ⬇️
unit/util/expr_initializer.cpp 99.83% <99.80%> (-0.17%) ⬇️

... and 24 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tautschnig
Copy link
Collaborator

Given I don't have enough context just yet the following may be a stupid idea, apologies for that: couldn't you instead use byte_extract(array_of<char[sizeof(target-type)]>(init_value), 0, target-type)?

@peterschrammel
Copy link
Member Author

peterschrammel commented Feb 12, 2023

Given I don't have enough context just yet the following may be a stupid idea, apologies for that: couldn't you instead use byte_extract(array_of<char[sizeof(target-type)]>(init_value), 0, target-type)?

That may not be as stupid as it sounds. Let me try. If it works then the entire expr_initializer class can be replaced by this single statement.

@kroening
Copy link
Member

Given I don't have enough context just yet the following may be a stupid idea, apologies for that: couldn't you instead use byte_extract(array_of<char[sizeof(target-type)]>(init_value), 0, target-type)?

That may not be as stupid as it sounds. Let me try. If it works then the entire expr_initializer class can be replaced by this single statement.

Please keep in mind that Goto programs are meant to be consumed by a broad variety of analysis methods. Virtually all but symex will choke on the above.

@peterschrammel peterschrammel mentioned this pull request Feb 18, 2023
4 tasks
@esteffin
Copy link
Contributor

esteffin commented Jul 6, 2023

Given I don't have enough context just yet the following may be a stupid idea, apologies for that: couldn't you instead use byte_extract(array_of<char[sizeof(target-type)]>(init_value), 0, target-type)?

That may not be as stupid as it sounds. Let me try. If it works then the entire expr_initializer class can be replaced by this single statement.

Please keep in mind that Goto programs are meant to be consumed by a broad variety of analysis methods. Virtually all but symex will choke on the above.

I agree. We should create a goto that can be consumed by analysis methods other than symex.
An option can be to run lower_byte_operators to the output of the byte_extract(array_of<char[sizeof(target-type)]>(init_value), 0, target-type) call, but it seems not so clean compared to what is in this PR (just an extension of the already existing expr_initializert).

Copy link
Contributor

@esteffin esteffin 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 although it needs unit tests + a few minor comments

src/util/expr_initializer.cpp Outdated Show resolved Hide resolved
src/util/expr_initializer.cpp Outdated Show resolved Hide resolved
src/util/expr_initializer.cpp Outdated Show resolved Hide resolved
@esteffin
Copy link
Contributor

esteffin commented Jul 6, 2023

Rebased to the latest origin/develop.

@esteffin esteffin force-pushed the per-byte-initializer branch 2 times, most recently from 39fd090 to c45da05 Compare July 18, 2023 18:57
We can now pass in 0 and nondet, and can then extend it to
take more general initialization expressions.
Each byte of the expression is initialized to the given
initialization expression.

This building block will be required for the shadow
memory implementation.
@esteffin
Copy link
Contributor

PR rebased, added tests and ready to review.

@esteffin esteffin marked this pull request as ready for review July 31, 2023 16:56
Copy link
Member Author

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

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

LGTM

Function `duplicate_per_byte` now has a PRECONDITION checking that the
`init_byte_expr` is either a boolean or a bitvector of maximum size 8.

Also the computation of the number of duplication correctly accounts the
case when the destination is not divisible by 8. In this case the input
is duplicated one extra (including the sign bit if any) time and then
truncated to the output size.
@tautschnig tautschnig merged commit 12c8f62 into diffblue:develop Aug 1, 2023
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants