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

Fix Issue 19774 - wrong code caused by opIndex #9696

Merged
merged 1 commit into from
Apr 26, 2019

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Apr 25, 2019

C bar()
{
    return C(42);
}

C foo()
{
    return bar()[1];
}

struct C
{
    int x;

    ~this()
    {
        x = 0;
    }

    C opIndex(int a)
    {
        return this;
    }
}

void main()
{
    auto c = foo();
    assert(c.x == 42); /* fails; should pass */
}

return bar()[1] is rewritten to :

C __dop3 = bar();
return __dop3.opIndex(1)

Which looks correct, but the problem is that C __dop3 is generated with a lifetime that lasts until the end of the expression. As a consequence the destructor is called before the return statement. In order to fix this I rewrote the CompoundStatement that the compiler generated to a simple return statement that has a Comma expression : return (C __dop3 = bar(); __dop3.opIndex(1));

@dlang-bot
Copy link
Contributor

dlang-bot commented Apr 25, 2019

Thanks for your pull request and interest in making D better, @RazvanN7! 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 annotated coverage diff directly on GitHub with CodeCov's browser extension
  • 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
19774 regression wrong code caused by opIndex

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

To target stable perform these two steps:

  1. Rebase your branch to upstream/stable:
git rebase --onto upstream/stable upstream/master
  1. Change the base branch of your PR to stable

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#9696"

@RazvanN7 RazvanN7 changed the base branch from master to stable April 25, 2019 13:35
@RazvanN7 RazvanN7 changed the base branch from stable to master April 25, 2019 13:41
@thewilsonator
Copy link
Contributor

Stable.

@JinShil
Copy link
Contributor

JinShil commented Apr 25, 2019

Using the result of a comma expression has been deprecated. I don't know if that negatively affects this technique or not.

@Geod24
Copy link
Member

Geod24 commented Apr 26, 2019

Using the result of a comma expression has been deprecated. I don't know if that negatively affects this technique or not.

It does not. Internally, coma expressions are used all over the place.

@RazvanN7
Copy link
Contributor Author

Stable.

I wanted to make sure that the failures are not due to stable missing any patches. Once I fix the issue properly, I will rebase on top of stable

@thewilsonator
Copy link
Contributor

OK. Ping me when this is GTG.

@RazvanN7 RazvanN7 changed the base branch from master to stable April 26, 2019 09:49
@RazvanN7
Copy link
Contributor Author

@thewilsonator

E: Some index files failed to download. They have been ignored, or old ones used instead.

on stable

@jacob-carlborg
Copy link
Contributor

@RazvanN7 rebasing the branch might fix the CircleCI issue.

@RazvanN7
Copy link
Contributor Author

@jacob-carlborg I already rebased on top of stable.

@RazvanN7
Copy link
Contributor Author

@thewilsonator Good to go. CircleCi failure unrelated.

@jacob-carlborg
Copy link
Contributor

CircleCI is using Debian Jessie, which I think is not supported anymore.

@wilzbach
Copy link
Member

Yup -> https://circleci.com/gh/dlang/dmd/tree/stable
One just needs to update to upstream/stable.

@jacob-carlborg
Copy link
Contributor

One just needs to update to upstream/stable.

#9696 (comment)

@thewilsonator thewilsonator merged commit 49b2921 into dlang:stable Apr 26, 2019
@wilzbach
Copy link
Member

One just needs to update to upstream/stable.

#9696 (comment)

Maybe @RazvanN7 didn't update his local upstream branch in a while?
Anyhow, thanks for fixing!

@9il
Copy link
Member

9il commented Apr 29, 2019

@RazvanN7 Did it fix also the same bug for opDollar?

@WalterBright
Copy link
Member

@RazvanN7 Thank for the most clear explanation!

@RazvanN7
Copy link
Contributor Author

@9il No, but I submitted another PR for that [1]

[1] #9725

@RazvanN7
Copy link
Contributor Author

@WalterBright Thanks!

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.

9 participants