Skip to content

split_at_mut does sketchy things with aliasing #27357

Closed
@arielb1

Description

@arielb1

The problematic function:

    fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) {
        unsafe {
            let self2: &mut [T] = mem::transmute_copy(&self);

            (ops::IndexMut::index_mut(self, ops::RangeTo { end: mid } ),
             ops::IndexMut::index_mut(self2, ops::RangeFrom { start: mid } ))
        }
    }

the first field return value is very much alive when index_mut is called on self2. This doesn't strictly violate LLVM's aliasing rules (AFAICT), because the overlapping part isn't directly accessed, but is still very sketchy (I can think of optimizers screwing it up).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions