Synthesize calls to box_free language item

This gets rid of Drop(Free, _) MIR construct by synthesizing a call to language item which
takes care of dropping instead.
This commit is contained in:
Simonas Kazlauskas 2016-01-28 23:59:00 +02:00
parent 7b9d6d3bc8
commit 432460a6fc
20 changed files with 127 additions and 69 deletions

View file

@ -39,11 +39,17 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
p
}
#[lang = "exchange_free"]
unsafe fn deallocate(ptr: *mut u8, _size: usize, _align: usize) {
libc::free(ptr as *mut libc::c_void)
}
#[lang = "box_free"]
unsafe fn box_free<T>(ptr: *mut T) {
deallocate(ptr as *mut u8, ::core::mem::size_of::<T>(), ::core::mem::align_of::<T>());
}
#[start]
fn main(argc: isize, argv: *const *const u8) -> isize {
let x = box 1;