diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2024-04-22 16:37:40 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2024-04-22 16:37:40 +0000 |
| commit | 8bc15fb2dad7597e3d2b5a8fce09ae2a96be23e9 (patch) | |
| tree | 0f785123fea28dbacde8432bfcfdbd1eb6eedc52 | |
| parent | a74d6c2125761f96e156a4e924298fcecb8333eb (diff) | |
| parent | e654877b2fe85e168513add63552149fdddc2ff7 (diff) | |
| download | rust-8bc15fb2dad7597e3d2b5a8fce09ae2a96be23e9.tar.gz rust-8bc15fb2dad7597e3d2b5a8fce09ae2a96be23e9.zip | |
Sync from rust fb898629a26e4acec59c928ce3ec00a62675d1cc
| -rw-r--r-- | example/mini_core_hello_world.rs | 15 | ||||
| -rw-r--r-- | src/base.rs | 13 | ||||
| -rw-r--r-- | src/value_and_place.rs | 17 |
3 files changed, 41 insertions, 4 deletions
diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 8b0b9123ac7..efa4be7e15a 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -1,4 +1,13 @@ -#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)] +#![feature( + no_core, + lang_items, + never_type, + linkage, + extern_types, + thread_local, + repr_simd, + raw_ref_op +)] #![no_core] #![allow(dead_code, non_camel_case_types, internal_features)] @@ -112,9 +121,7 @@ fn start<T: Termination + 'static>( static mut NUM: u8 = 6 * 7; -// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint -#[allow(static_mut_refs)] -static NUM_REF: &'static u8 = unsafe { &NUM }; +static NUM_REF: &'static u8 = unsafe { &*&raw const NUM }; unsafe fn zeroed<T>() -> T { let mut uninit = MaybeUninit { uninit: () }; diff --git a/src/base.rs b/src/base.rs index 46301278382..4892d46a572 100644 --- a/src/base.rs +++ b/src/base.rs @@ -815,6 +815,19 @@ fn codegen_stmt<'tcx>( ); lval.write_cvalue(fx, val); } + Rvalue::Aggregate(ref kind, ref operands) + if matches!(**kind, AggregateKind::RawPtr(..)) => + { + let ty = to_place_and_rval.1.ty(&fx.mir.local_decls, fx.tcx); + let layout = fx.layout_of(fx.monomorphize(ty)); + let [data, meta] = &*operands.raw else { + bug!("RawPtr fields: {operands:?}"); + }; + let data = codegen_operand(fx, data); + let meta = codegen_operand(fx, meta); + let ptr_val = CValue::pointer_from_data_and_meta(data, meta, layout); + lval.write_cvalue(fx, ptr_val); + } Rvalue::Aggregate(ref kind, ref operands) => { let (variant_index, variant_dest, active_field_index) = match **kind { mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => { diff --git a/src/value_and_place.rs b/src/value_and_place.rs index dded6df7771..38fedb6036c 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -95,6 +95,23 @@ impl<'tcx> CValue<'tcx> { CValue(CValueInner::ByValPair(value, extra), layout) } + /// For `AggregateKind::RawPtr`, create a pointer from its parts. + /// + /// Panics if the `layout` is not a raw pointer. + pub(crate) fn pointer_from_data_and_meta( + data: CValue<'tcx>, + meta: CValue<'tcx>, + layout: TyAndLayout<'tcx>, + ) -> CValue<'tcx> { + assert!(layout.ty.is_unsafe_ptr()); + let inner = match (data.0, meta.0) { + (CValueInner::ByVal(p), CValueInner::ByVal(m)) => CValueInner::ByValPair(p, m), + (p @ CValueInner::ByVal(_), CValueInner::ByRef(..)) if meta.1.is_zst() => p, + _ => bug!("RawPtr operands {data:?} {meta:?}"), + }; + CValue(inner, layout) + } + pub(crate) fn layout(&self) -> TyAndLayout<'tcx> { self.1 } |
