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 21424 - Variable is incremented twice #11997

Merged
merged 1 commit into from
Dec 5, 2020

Conversation

BorisCarvajal
Copy link
Member

Test case:

    ubyte[10] buf;
    size_t pos = 0;
    size_t num = 5;
    buf[pos++] += num;

Here DMD internally generates something like:
cast(ulong)cast(int) (tmp = pos++ + &buf, *tmp) += num

That expression had to be converted to:
(tmp = pos++ + &buf, cast(ulong)cast(int) *tmp) += num
but the implementation worked only for one cast (fixed now). And because of that the compiler ended up creating an assign operation duplicating the comma exp in both sides:
(tmp = pos++ + &buf, *tmp) = cast(...)(tmp = pos++ + &buf, *tmp) + num

@dlang-bot
Copy link
Contributor

dlang-bot commented Nov 25, 2020

Thanks for your pull request and interest in making D better, @BorisCarvajal! 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
21424 normal Variable is incremented twice

Testing this PR locally

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

dub run digger -- build "master + dmd#11997"

@BorisCarvajal BorisCarvajal changed the base branch from stable to master November 29, 2020 07:29
@BorisCarvajal BorisCarvajal force-pushed the fix21424 branch 2 times, most recently from be32787 to 97ce08d Compare November 29, 2020 08:59
elem *econv = e.EV.E1;
while (OTconv(econv.Eoper))
{
if (econv.EV.E1.Eoper == OPcomma)
Copy link
Contributor

@thewilsonator thewilsonator Dec 5, 2020

Choose a reason for hiding this comment

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

if (econv.EV.E1.Eoper != OPcomma)
{
    econv = econv.EV.E1;
    continue;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

Otherwise looks good

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.

3 participants