1
Fork 0

Merge commit '1bbee3e217' into sync-cg_gcc-2023-06-19

This commit is contained in:
Antoni Boucher 2023-06-19 18:51:02 -04:00
commit 4d96893d85
23 changed files with 244 additions and 264 deletions

View file

@ -451,6 +451,9 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
drop_in_place(to_drop);
}
#[lang = "unpin"]
pub auto trait Unpin {}
#[lang = "deref"]
pub trait Deref {
type Target: ?Sized;
@ -488,10 +491,23 @@ pub struct Box<T: ?Sized, A: Allocator = Global>(Unique<T>, A);
impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}
impl<T> Box<T> {
pub fn new(val: T) -> Box<T> {
unsafe {
let size = intrinsics::size_of::<T>();
let ptr = libc::malloc(size);
intrinsics::copy(&val as *const T as *const u8, ptr, size);
Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, Global)
}
}
}
impl<T: ?Sized, A: Allocator> Drop for Box<T, A> {
fn drop(&mut self) {
// inner value is dropped by compiler
libc::free(self.pointer.0 as *mut u8);
// inner value is dropped by compiler.
unsafe {
libc::free(self.0.pointer.0 as *mut u8);
}
}
}

View file

@ -168,6 +168,9 @@ fn main() {
world as Box<dyn SomeTrait>;
assert_eq!(intrinsics::bitreverse(0b10101000u8), 0b00010101u8);
assert_eq!(intrinsics::bitreverse(0xddccu16), 0x33bbu16);
assert_eq!(intrinsics::bitreverse(0xffee_ddccu32), 0x33bb77ffu32);
assert_eq!(intrinsics::bitreverse(0x1234_5678_ffee_ddccu64), 0x33bb77ff1e6a2c48u64);
assert_eq!(intrinsics::bswap(0xabu8), 0xabu8);
assert_eq!(intrinsics::bswap(0xddccu16), 0xccddu16);

View file

@ -58,6 +58,7 @@ fn main() {
assert_eq!(0b0000000000000000000000000010000010000000000000000000000000000000_0000000000100000000000000000000000001000000000000100000000000000u128.leading_zeros(), 26);
assert_eq!(0b0000000000000000000000000010000000000000000000000000000000000000_0000000000000000000000000000000000001000000000000000000010000000u128.trailing_zeros(), 7);
assert_eq!(0x1234_5678_ffee_ddcc_1234_5678_ffee_ddccu128.reverse_bits(), 0x33bb77ff1e6a2c4833bb77ff1e6a2c48u128);
let _d = 0i128.checked_div(2i128);
let _d = 0u128.checked_div(2u128);