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

Forbid memcpyopt if the source pointer escapes #6655

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

ironcev
Copy link
Member

@ironcev ironcev commented Oct 17, 2024

Description

This PR fixes the issue of the source pointer not being checked for escapes in the memcpyopt::local_copy_prop_prememcpy. E.g., in this example:

script {
    entry fn main() -> u64 {
        local u64 x
        local u64 y

        entry():
        v0 = get_local ptr u64, x
        v1 = get_local ptr u64, y
	
        v2 = load v0
        v3 = call escape(v0) // `v0` escapes here.
        store v2 to v1
        v4 = load v1

        ret u64 v4
    }

    fn escape(a: ptr u64) -> u64 {
        entry(a: ptr u64):
        z = const u64 0
        store z to a
        ret u64 z
    }
}

after the memcpyopt the store v2 to v1 got optimized away and the final return was from v0. It means the returned value was the one changed in escape and not the one taken before the call to escape.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev ironcev self-assigned this Oct 17, 2024
@ironcev ironcev added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes labels Oct 17, 2024
@ironcev ironcev marked this pull request as ready for review October 17, 2024 12:48
@ironcev ironcev requested a review from a team as a code owner October 17, 2024 12:48
@ironcev ironcev requested a review from a team October 17, 2024 12:48
@ironcev ironcev requested a review from a team October 17, 2024 15:10
@IGI-111 IGI-111 merged commit 1d2f63f into master Oct 17, 2024
38 checks passed
@IGI-111 IGI-111 deleted the ironcev/memcpyopt-escaping-source-pointer branch October 17, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: ir IRgen and sway-ir including optimization passes compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants