Skip to content

Wrap return value in std::move (Clang 7 build fix) #3301

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 1 commit into from
Nov 9, 2018

Conversation

karkhaz
Copy link
Collaborator

@karkhaz karkhaz commented Nov 9, 2018

This fixes #3238 (again).

@karkhaz karkhaz changed the title Wrap return value in std::move Wrap return value in std::move (Clang 7 build fix) Nov 9, 2018
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.

If it is required to compile, then it is required, but it makes me sad and I don't really understand why.

@@ -1251,14 +1251,14 @@ exprt java_string_library_preprocesst::get_primitive_value_of_object(
typecast_exprt(object, pointer_type), pointer_type.subtype());
member_exprt deref_value(deref, value_comp.get_name(), value_comp.type());
code.add(code_assignt(value, deref_value), loc);
return value;
return std::move(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

What a bore. I thought RVO meant you didn't need to move locals on return...

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I am also bugged by this. The rule isn't hard ('the type must match'), but it's still super annoying.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair - so in this case could be fixed by changing return to symbol_exprt? This seems like the better fix since the docs explicitly says returns a symbol

Copy link
Collaborator

Choose a reason for hiding this comment

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

Except ... it doesn't - there is a branch that returns a nil_exprt.

Copy link
Contributor

Choose a reason for hiding this comment

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

And presumably if you did return optionalt<symbol_exprt>(...) then that would need to be std::move'd as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't actually think so, it would likely be the best approach. Well, even if the std::move were required, it would still be cleaner.

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'll try to use optionalt since I have a compiler to test with, I'll let you know how it goes in a few moments...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, please have a look at the updated patch. Indeed, std::move is not required. get_primitive_value_of_object now returns an optionalt<symbol_exprt>, and I've updated its only caller accordingly...please let me know if the call site looks wrong, I'm not sure that I did the right thing.

@karkhaz
Copy link
Collaborator Author

karkhaz commented Nov 9, 2018

@thk123 it's not "required to compile," it's actually a warning that can be disabled with -Wno-return-std-move---sorry that I didn't actually elaborate on this. If it's annoying then I suppose that we can change CMake to pass that flag to Clang? But I would vote against that, personally, it generally seems like a useful warning to have around.

@karkhaz karkhaz force-pushed the kk-clang7-build-fix branch 2 times, most recently from 2f504f5 to 678b730 Compare November 9, 2018 12:55
if(value.has_value())
code_not_null.add(code_assignt(field_expr, *value), loc);
else
code_not_null.add(code_assignt(field_expr, nil_exprt()), loc);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Puh, I'm pretty sure this is broken and has actually been all along? @romainbrenguier maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

The else case should never happen, it would be better to put an invariant here.
The nil_exprt case happen for name == ID_void, which is excluded by the if condition.

@karkhaz karkhaz force-pushed the kk-clang7-build-fix branch from 678b730 to d6e1984 Compare November 9, 2018 12:59
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: 645dce0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/90853799
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.

@karkhaz
Copy link
Collaborator Author

karkhaz commented Nov 9, 2018

Do I need to rebase, or will the compatibility checks pick up my latest push automatically @allredj?

I resolved all of @tautschnig's suggestions except one.

@thk123
Copy link
Contributor

thk123 commented Nov 9, 2018

Heh yeah I consider warnings as not compiling since we compile with warnings as errors!

@thk123
Copy link
Contributor

thk123 commented Nov 9, 2018

@karkhaz I think you should leave it - Joels bot refers to an old commit id so I imagine the new one is still running.

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: 678b730).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/90863299
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

@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: d6e1984).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/90866577

@tautschnig tautschnig merged commit 65b0939 into diffblue:develop Nov 9, 2018
@karkhaz karkhaz deleted the kk-clang7-build-fix branch November 9, 2018 15:24
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.

Build fails with Clang 7.0 due to local variable copies
7 participants