Skip to content

Payload captures no longer alias the original value #4454

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 2 commits into from
Feb 14, 2020

Conversation

LemonBoy
Copy link
Contributor

Ad discussed with Andrew in #4443 I've changed the behavior of for/if/while/switch so that a "simple" capture (|v|) always creates a copy of the payload in a scope-local variable. If you need to modify the underlying memory just use a "ref" capture (|*v|).

I've added a few tests to make sure this new behavior is respected and I've run the stage1/std test suite and I've not spotted any regression. That's possibly a sign of how nobody expected the capture to behave like it did :P or maybe everybody knew that and worked around it.

Closes #4361
Closes #2915

The payload doesn't alias anymore the same memory it comes from and is
instead a fresh copy of the original object.
@JesseRMeyer
Copy link

Curious -- Do you know if LLVM only emits a copy in Release build modes when the capture was modified?

@andrewrk andrewrk merged commit 9e1afdc into ziglang:master Feb 14, 2020
@andrewrk
Copy link
Member

Nice work.

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.

slice of allowzero pointer is rejected in for Unwrapped optional aliasing footgun
3 participants