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

Add shadow memory get_field function #7840

Merged

Conversation

esteffin
Copy link
Contributor

@esteffin esteffin commented Aug 8, 2023

Add implementation to shadow memory symex_get_field function.
Add regression tests for symex_get_field.
Fix issue with duplicate_per_byte.

To speed up integration of shadow memory functionalities improving code with proper doxygen and testing is left to a subsequent PR.

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

@esteffin esteffin requested a review from a team August 8, 2023 23:45
@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Patch coverage: 60.06% and project coverage change: -0.63% ⚠️

Comparison is base (1e8a703) 78.81% compared to head (74f6669) 78.19%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7840      +/-   ##
===========================================
- Coverage    78.81%   78.19%   -0.63%     
===========================================
  Files         1698     1698              
  Lines       194821   195117     +296     
===========================================
- Hits        153543   152566     -977     
- Misses       41278    42551    +1273     
Files Changed Coverage Δ
src/goto-symex/shadow_memory_util.cpp 61.25% <57.02%> (-35.30%) ⬇️
src/goto-symex/shadow_memory.cpp 90.90% <73.21%> (+15.21%) ⬆️

... and 51 files with indirect coverage changes

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

@esteffin esteffin force-pushed the esteffin/shadow-memory-get-field-op branch from 3862377 to a8d5223 Compare August 9, 2023 13:48
@esteffin esteffin marked this pull request as ready for review August 9, 2023 13:48

#include "goto_symex_state.h"
#include "shadow_memory_util.h"

// TODO: doxygen?
static exprt
build_if_else_expr(std::vector<std::pair<exprt, exprt>> conds_values)
Copy link
Member

Choose a reason for hiding this comment

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

💡 Alll these static utilities should probably be moved to the _util file in order to keep the main implementation file short and concise.


#include "goto_symex_state.h"
#include "shadow_memory_util.h"

// TODO: doxygen?
Copy link
Member

Choose a reason for hiding this comment

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

Yes, every function needs documentation.

@@ -95,12 +248,323 @@ void shadow_memoryt::symex_set_field(
// To be implemented
}

// TODO: doxygen?
static value_set_dereferencet::valuet get_shadow(
Copy link
Member

Choose a reason for hiding this comment

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

The naming of this function can be improved to get_shadow_dereference at least. It's not returning the "shadow" object, but the shadow object at the offset corresponding to the expr pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

log_try_shadow_address(ns, log, shadowed_address);
if(!are_types_compatible(expr.type(), shadowed_address.address.type()))
{
#ifdef DEBUG_SM
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth moving into a utility to declutter the code.

// result += (expr_match, shadow_dereference.value)
// break;
// result += (base_match & expr_match, shadow_dereference.value)
static std::vector<std::pair<exprt, exprt>> get_field(
Copy link
Member

Choose a reason for hiding this comment

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

The naming of the function can be improved to get_shadow_dereference_candidates or similar.


/// Given a pointer expression `address` checks if any expr in value_set is
/// compatible
bool contains_compatible_address(
Copy link
Member

Choose a reason for hiding this comment

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

This is misnamed and the comment above is wrong. This should be called contains_null_or_invalid.
Also, I think there's potential for simplifications as together with the invalid-by-null replacement the unknown case can probably go away (in a future PR).

{
log.conditional_output(
log.debug(), [ns, field_name, expr](messaget::mstreamt &mstream) {
mstream << "Shadow memory: get_field: " << id2string(field_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ get_field -> get field to match the other messages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually changed the others to reflect the variable name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's ok that it correctly refers to the variable.
I changed the other accordingly instead.

#ifdef DEBUG_SM
log.conditional_output(
log.debug(), [ns, shadowed_address](messaget::mstreamt &mstream) {
mstream << "Shadow memory: trying shadowed address: "
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ message does not match function name

#ifdef DEBUG_SM
log.conditional_output(
log.debug(), [ns, cond_text, cond](messaget::mstreamt &mstream) {
mstream << "Shadow memory: " << cond_text << ": " << format(cond)
Copy link
Contributor

Choose a reason for hiding this comment

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

⛏️ missing cond: in message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cond_text that is logged just before the : is the condition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The condition is in cond_text before the :

@esteffin esteffin force-pushed the esteffin/shadow-memory-get-field-op branch 2 times, most recently from de05afc to 0d39784 Compare August 10, 2023 18:32
Enrico Steffinlongo added 5 commits August 10, 2023 20:54
Add a set of functions to shadow_memory_util.{h,cpp} that will be used
for logging purposes by `shadow_memory::symex_get_field` and its
subfunctions.
Add a set of utility functions to `shadow_memory_util.{h,cpp}` that will
be used by `shadow_memory::symex_get_field` and its subfunctions.
Add implementation to shadow_memoryt::symex_get_field also adding its
subfunctions.
Function `duplicate_per_byte` checks that the `init_expr` is at max
8-bit wide. However `shadow_memoryt::initialize_shadow_memory` was
removing the outer typecast to an 8-bit value, resulting in a call to
`duplicate_per_byte` with an `init_expr` larger than 8-bit.

This commit removes the typecast removal and fixes the issue.
@esteffin esteffin force-pushed the esteffin/shadow-memory-get-field-op branch from 0d39784 to 74f6669 Compare August 10, 2023 19:54
@esteffin esteffin merged commit f40203a into diffblue:develop Aug 10, 2023
33 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.

3 participants