Skip to content

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