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 22228 - [CTFE] taking address of immutable in frame function causes ICE on Unix platform #13005

Closed
wants to merge 1 commit into from

Conversation

RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Aug 23, 2021

auto f()
{   immutable int i;
    auto p = (() => &i)();

    return 0;
}

enum ctfeInvocation = f;

&i is viewed as a SymOffExp before being rewritten to an AddrExp. If the delegate is not present, this code never calls visit(AddrExp) and therefore the bug does not manifest. In the delegate scenario, the FuncExp is interpreted and it peels of the delegate, returning &i, but then, a subsequent call to interpret is made which rewrites the expression to &0 that in turn fails the assert.

I don't really understand the subtleties of why certain calls to interpret are made, so this fix might not be the best. But to me it seems that it is wrong that visit(VarExp) with goal = LValue is allowed to return an rvalue. Fixing this, seems to pass the testsuite.

@dlang-bot
Copy link
Contributor

dlang-bot commented Aug 23, 2021

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 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
22228 regression [CTFE] taking address of immutable in frame function causes ICE on Unix platforms

⚠️⚠️⚠️ 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 run digger -- build "master + dmd#13005"

@RazvanN7 RazvanN7 added the Severity:Regression PRs that fix regressions label Aug 23, 2021
@RazvanN7 RazvanN7 changed the title Fix Issue 22228 - [CTFE] taking address of immutable in frame functio[CTFE] taking address of immutable in frame function causes ICE on Unix platform Fix Issue 22228 - [CTFE] taking address of immutable in frame function causes ICE on Unix platform Aug 23, 2021
@UplinkCoder
Copy link
Member

@RazvanN7 if you could add a comment in the code why the change works.
unfortunately It's not oblivious.

@RazvanN7
Copy link
Contributor Author

@UplinkCoder Yes, I had one comment but somehow screwed up the commits. Should be fine now.

@UplinkCoder
Copy link
Member

it still doesn't explain why just assigning the VarExp to result works.

@BorisCarvajal
Copy link
Member

BorisCarvajal commented Aug 23, 2021

This regression was caused by #11545, you are applying a workaround over another one.
The solution is first to revert #11545, and then use a proper fix for it.

I've tested these two working:

  1. to cache (push it on CTFE stack) the pointed variable of ref arguments in interpretFunction().
    or easier:
  2. add an special case for non-CTFE variables that are const/immutable inside the if (goal == CTFEGoal.LValue).

@BorisCarvajal
Copy link
Member

Alternative solution #13007 (Sorry for somewhat hijacking this, but I was working on it too)

@RazvanN7 RazvanN7 closed this Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants