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

Add support for noalias function parameters #312

Merged
merged 3 commits into from
Aug 29, 2023

Conversation

GuillaumeGomez
Copy link
Member

No description provided.

src/abi.rs Outdated Show resolved Hide resolved
@GuillaumeGomez
Copy link
Member Author

We figured out where the bug was coming from: it's because of ByValue arguments. It can be reproduced with this code:

use std::mem;

#[repr(C)]
pub struct Buffer {
    data: *mut u8,
    len: usize,
    drop: extern "C" fn(Buffer),
}

impl Default for Buffer {
    #[inline]
    fn default() -> Self {
        Self::from(vec![])
    }
}

impl Buffer {
    #[inline]
    pub fn new() -> Self {
        Self::default()
    }

    #[inline]
    pub fn push(&mut self, v: u8) {
    }
}

impl From<Vec<u8>> for Buffer {
    fn from(mut v: Vec<u8>) -> Self {
        let (data, len) = (v.as_mut_ptr(), v.len());
        mem::forget(v);

        extern "C" fn drop(b: Buffer) {
        }

        Buffer { data, len, drop }
    }
}

fn main() {
    let mut buffer = Buffer::new();
}

@antoyo antoyo merged commit 2b956f5 into rust-lang:master Aug 29, 2023
21 of 32 checks passed
@GuillaumeGomez GuillaumeGomez deleted the fn-param-noalias branch August 30, 2023 08:44
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.

2 participants