Skip to content

Add support for noalias function parameters #312

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 3 commits into from
Aug 29, 2023

Conversation

GuillaumeGomez
Copy link
Member

No description provided.

@GuillaumeGomez GuillaumeGomez force-pushed the fn-param-noalias branch 2 times, most recently from 7348627 to f4f204d Compare August 16, 2023 11:53
@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();
}

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