Skip to content

Extra memcpy when compiling with rustc_codegen_gcc #56

Open
@jrmuizel

Description

@jrmuizel

When compiling the following there's an extra memcpy that LLVM is able to optimize away:

use std::mem;

struct SV {
    disc: usize,
    data: [usize; 40],
    capacity: usize,
}

impl SV {
    fn new() -> SV {
        SV { data: unsafe { mem::uninitialized() },
            disc: 0,
            capacity: 0 }
    }
}

pub struct L {
    a: SV,
    b: SV
}

pub struct Allocation<T> {
    f: *mut T,
}

impl<T> Allocation<T> {
    pub fn init(self, value: T) {
        use std::ptr;
        unsafe {
        ptr::write(self.f, value);
        }
    }
}

#[inline(never)]
pub fn foo(a: Allocation<L>) {
    a.init(L {
        a: SV::new(),
        b: SV::new()
    });
}

See: https://rust.godbolt.org/z/1d843PPnx

This test case is derived from rust-lang/rust#58082 which links to https://bugs.llvm.org/show_bug.cgi?id=40574 which suggests that GCC should be able to optimize something like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions