Skip to content

Comments

Fix issue 20401 - The glue shouldn't copy side effects by value where the lvalue is wanted#10577

Merged
dlang-bot merged 1 commit intodlang:masterfrom
SSoulaimane:irlvalue
Nov 23, 2019
Merged

Fix issue 20401 - The glue shouldn't copy side effects by value where the lvalue is wanted#10577
dlang-bot merged 1 commit intodlang:masterfrom
SSoulaimane:irlvalue

Conversation

@SSoulaimane
Copy link
Member

@SSoulaimane SSoulaimane commented Nov 17, 2019

Issue 20401.

@SSoulaimane SSoulaimane marked this pull request as ready for review November 17, 2019 05:15
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @SSoulaimane! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
20401 major ref variable copied before return

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#10577"

@thewilsonator
Copy link
Contributor

Please use a while loop instead of a for, otherwise looks good.

kinke added a commit to kinke/ldc that referenced this pull request Nov 17, 2019
See https://issues.dlang.org/show_bug.cgi?id=20401; a testcase will be
added with dlang/dmd#10577.

It's a pretty serious issue (the previously returned reference in the
testcase was a dangling reference to a local memcopy of the original
value in memory), hence this early fix.
@SSoulaimane
Copy link
Member Author

Done.
This should probably target stable. What do you think?

!(erx.ET && type_size(erx.ET) <= 16))
else if (elemIsLvalue(erx))
{
/* Expensive to copy, to take a pointer to it instead
Copy link
Member

Choose a reason for hiding this comment

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

Not retaining this behavior for expensive-to-copy things?

Copy link
Member Author

@SSoulaimane SSoulaimane Nov 17, 2019

Choose a reason for hiding this comment

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

It is retained actually, structs bigger than two registers match the given definition of lvalue, i.e they are always lvalues in the backend regardless of the frontend's judgement. As far as the backend is concerned what lives in registers is an rvalue and what lives in memory is an lvalue.

… the lvalue is wanted

By ref semantics should be preserved when extracting side effects.
@RazvanN7
Copy link
Contributor

This should probably target stable. What do you think?

I think we're fine with master for now.

@RazvanN7 RazvanN7 added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Nov 19, 2019
@thewilsonator thewilsonator added Merge:auto-merge and removed Merge:72h no objection -> merge The PR will be merged if there are no objections raised. labels Nov 23, 2019
@dlang-bot dlang-bot merged commit b0cdc91 into dlang:master Nov 23, 2019
kinke added a commit to ldc-developers/ldc that referenced this pull request Nov 23, 2019
See https://issues.dlang.org/show_bug.cgi?id=20401; a testcase will be
added with dlang/dmd#10577.

It's a pretty serious issue (the previously returned reference in the
testcase was a dangling reference to a local memcopy of the original
value in memory), hence this early fix.
@MoonlightSentinel
Copy link
Contributor

This introduced a regression: https://issues.dlang.org/show_bug.cgi?id=20809

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants