Skip to content

Move make_allocate_code utility function #4349

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

Conversation

antlechner
Copy link
Contributor

No functional change, just some small refactoring.

  • 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/
  • n/a 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).
  • n/a 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.

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: f80e3b1).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/103584559
Status will be re-evaluated on next push.
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 compatibility was already broken by an earlier merge.

@@ -271,3 +271,15 @@ void allocate_objectst::mark_created_symbols_as_input(code_blockt &init_code)
init_code.add(std::move(input_code));
}
}

/// Create code allocating object of size `size` and assigning it to `lhs`
Copy link
Collaborator

Choose a reason for hiding this comment

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

"an object"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in a new "Tidy up documentation" commit. 🐚

{
side_effect_exprt alloc(ID_allocate, lhs.type(), lhs.source_location());
alloc.add_to_operands(size);
alloc.add_to_operands(false_exprt());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nowadays you can actually do
side_effect_exprt alloc{ID_allocate, {size, false_exprt()}, lhs.type(), lhs.source_location()};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, didn't know about this constructor, I changed it to your suggestion.

side_effect_exprt alloc(ID_allocate, lhs.type(), lhs.source_location());
alloc.add_to_operands(size);
alloc.add_to_operands(false_exprt());
return code_assignt(lhs, alloc);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd do return code_assignt{lhs, std::move(alloc)};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? Wouldn't return-value optimisation take care of this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAIK not, because it's a named object. (But also it won't make any difference until #3502 is merged, and even then it will not make a measurable difference.)

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 see, so the pass-by-value constructor for code_assignt doesn't exist yet but hopefully will in the future, when your PR is merged. In that case I'll leave it as it is for now as it'll be less confusing to make this kind of change in several places at once after your PR got merged.

@@ -95,6 +95,10 @@ class allocate_objectst
const irep_idt &basename_prefix);
};

/// Create code allocating object of size `size` and assigning it to `lhs`
/// \param lhs : pointer which will be allocated
/// \param size : size of the object
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit pick: no need for a space before colon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🐚

This utility function is only related to allocating an object and not to
nondet-initialization.
This also saves an include.
This allows us to call this function and assign the result to a
code_assignt.
No functional change; the utility function can be used to directly
replace the previous steps of creating the code_assignt.
Following the new coding standard.
This allows us to construct the expression in one line rather than
three.
@antlechner antlechner force-pushed the antonia/move_make_allocate_code branch from f80e3b1 to b2e9778 Compare March 8, 2019 10:44
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: b2e9778).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/103670013
Status will be re-evaluated on next push.
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 compatibility was already broken by an earlier merge.

@antlechner antlechner merged commit 804efea into diffblue:develop Mar 8, 2019
@antlechner antlechner deleted the antonia/move_make_allocate_code branch March 8, 2019 16:35
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.

4 participants