Skip to content

Commit 8bc15fb

Browse files
committed
Sync from rust fb898629a26e4acec59c928ce3ec00a62675d1cc
2 parents a74d6c2 + e654877 commit 8bc15fb

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

example/mini_core_hello_world.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)]
1+
#![feature(
2+
no_core,
3+
lang_items,
4+
never_type,
5+
linkage,
6+
extern_types,
7+
thread_local,
8+
repr_simd,
9+
raw_ref_op
10+
)]
211
#![no_core]
312
#![allow(dead_code, non_camel_case_types, internal_features)]
413

@@ -112,9 +121,7 @@ fn start<T: Termination + 'static>(
112121

113122
static mut NUM: u8 = 6 * 7;
114123

115-
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
116-
#[allow(static_mut_refs)]
117-
static NUM_REF: &'static u8 = unsafe { &NUM };
124+
static NUM_REF: &'static u8 = unsafe { &*&raw const NUM };
118125

119126
unsafe fn zeroed<T>() -> T {
120127
let mut uninit = MaybeUninit { uninit: () };

src/base.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,19 @@ fn codegen_stmt<'tcx>(
815815
);
816816
lval.write_cvalue(fx, val);
817817
}
818+
Rvalue::Aggregate(ref kind, ref operands)
819+
if matches!(**kind, AggregateKind::RawPtr(..)) =>
820+
{
821+
let ty = to_place_and_rval.1.ty(&fx.mir.local_decls, fx.tcx);
822+
let layout = fx.layout_of(fx.monomorphize(ty));
823+
let [data, meta] = &*operands.raw else {
824+
bug!("RawPtr fields: {operands:?}");
825+
};
826+
let data = codegen_operand(fx, data);
827+
let meta = codegen_operand(fx, meta);
828+
let ptr_val = CValue::pointer_from_data_and_meta(data, meta, layout);
829+
lval.write_cvalue(fx, ptr_val);
830+
}
818831
Rvalue::Aggregate(ref kind, ref operands) => {
819832
let (variant_index, variant_dest, active_field_index) = match **kind {
820833
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {

src/value_and_place.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ impl<'tcx> CValue<'tcx> {
9595
CValue(CValueInner::ByValPair(value, extra), layout)
9696
}
9797

98+
/// For `AggregateKind::RawPtr`, create a pointer from its parts.
99+
///
100+
/// Panics if the `layout` is not a raw pointer.
101+
pub(crate) fn pointer_from_data_and_meta(
102+
data: CValue<'tcx>,
103+
meta: CValue<'tcx>,
104+
layout: TyAndLayout<'tcx>,
105+
) -> CValue<'tcx> {
106+
assert!(layout.ty.is_unsafe_ptr());
107+
let inner = match (data.0, meta.0) {
108+
(CValueInner::ByVal(p), CValueInner::ByVal(m)) => CValueInner::ByValPair(p, m),
109+
(p @ CValueInner::ByVal(_), CValueInner::ByRef(..)) if meta.1.is_zst() => p,
110+
_ => bug!("RawPtr operands {data:?} {meta:?}"),
111+
};
112+
CValue(inner, layout)
113+
}
114+
98115
pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
99116
self.1
100117
}

0 commit comments

Comments
 (0)