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

Filling drop blocks LLVM from optimizing away allocations. #31133

Closed
eddyb opened this issue Jan 22, 2016 · 2 comments
Closed

Filling drop blocks LLVM from optimizing away allocations. #31133

eddyb opened this issue Jan 22, 2016 · 2 comments
Labels
A-codegen Area: Code generation

Comments

@eddyb
Copy link
Member

eddyb commented Jan 22, 2016

Testcase by @tsion (run on playpen):

#![crate_type = "lib"]
#![feature(filling_drop)]

extern "C" {
    fn __rust_allocate(_: usize, _: usize) -> &'static mut i8;
    fn __rust_deallocate(_: *mut i8, _: usize, _: usize);
}

pub fn foo(x: i32) -> i32 {
    unsafe {
        let b = __rust_allocate(4, 4) as *mut _ as *mut i32;
        *b = x;
        let r = *b;

        // Comment this check and watch the IR shrink.
        if b != std::mem::POST_DROP_USIZE as *mut i32 {
            __rust_deallocate(b as *mut i8, 4, 4);
        }

        r
    }
}

A complete implementation of #5016 should fix this, although I'm surprised there is a check at all here (run on playpen):

#![crate_type = "lib"]

pub fn foo(x: i32) -> i32 {
    let b = Box::new(x);
    *b
}

cc @alexcrichton @pnkfelix

@eddyb eddyb added the A-codegen Area: Code generation label Jan 22, 2016
@jonas-schievink
Copy link
Contributor

Filling drop is no more

@eddyb
Copy link
Member Author

eddyb commented Sep 1, 2016

My second example is now:

define i32 @_ZN8rust_out3foo17hcacd841310a2f504E(i32) unnamed_addr #0 personality i32 (i32, i32, i64, %"8.unwind::libunwind::_Unwind_Exception"*, %"8.unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
entry-block:
  ret i32 %0
}

@eddyb eddyb closed this as completed Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

No branches or pull requests

2 participants