Skip to content

Unrevert #69450 - Add a mark_dependence while emitting SIL for uninitialized array allocation #70242

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
Dec 6, 2023

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Dec 5, 2023

Currently allocation for uninitialized array looks like this:

 %3 = function_ref @_allocateUninitializedArray : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)	  %3 = function_ref @_allocateUninitializedArray : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer)
 %4 = apply %3<() -> Int>(%2) : $@convention(thin) <τ_0_0> (Builtin.Word) -> (@owned Array<τ_0_0>, Builtin.RawPointer

There is no lifetime dependence between the interior pointer and the array value returned by such functions. This can cause illegal lifetime shortening.

Add a mark_dependence and teach the new array initialization pattern to the optimizer.

Fixes rdar://114546034

#69450 was reverted because it exposed an unrelated optimizer problem - rdar://117927523

@meg-gupta meg-gupta requested a review from eeckstein as a code owner December 5, 2023 20:35
@meg-gupta
Copy link
Contributor Author

#69450 was reverted because it exposed an unrelated optimizer problem - rdar://117927523

Cherry picking the fix here to get a toolchain build started - #70233

@meg-gupta
Copy link
Contributor Author

@swift-ci Please Build Toolchain

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta requested a review from atrick December 5, 2023 21:49
@meg-gupta
Copy link
Contributor Author

I'll merge this once #70233 is merged.

@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test

@meg-gupta meg-gupta merged commit d005743 into swiftlang:main Dec 6, 2023
meg-gupta added a commit to meg-gupta/swift that referenced this pull request Feb 27, 2024
With swiftlang#70242 mark_dependence was added while emitting uninitialized array allocation
between the unsafe pointer and the array value returned.
Without it, we can end up with use after free of the unsafe pointer if the array's lifetime
is shortened. Along with this change, pattern matching of all array optimizations was updated to include
mark_dependence.

This change adds mark_dependence for uninitialized array allocation in OSLogOptimization which was left out previously.
With this, potential use-after-free of the unsafe pointer is prevented and all updated array optimizations apply
to the array created by OSLogOptimization.

Fixes rdar://122922902
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.

1 participant