Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 04bf9f0

Browse files
committed
Auto merge of rust-lang#125689 - jieyouxu:rollup-e2waal9, r=jieyouxu
Rollup of 8 pull requests Successful merges: - rust-lang#124251 (Add an intrinsic for `ptr::metadata`) - rust-lang#124320 (Add `--print=check-cfg` to get the expected configs) - rust-lang#125226 (Make more of the test suite run on Mac Catalyst) - rust-lang#125381 (Silence some resolve errors when there have been glob import errors) - rust-lang#125633 (miri: avoid making a full copy of all new allocations) - rust-lang#125638 (Rewrite `lto-smoke`, `simple-rlib` and `mixing-deps` `run-make` tests in `rmake.rs` format) - rust-lang#125639 (Support `./x doc run-make-support --open`) - rust-lang#125664 (Tweak relations to no longer rely on `TypeTrace`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents da159eb + 093791c commit 04bf9f0

File tree

140 files changed

+1278
-465
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+1278
-465
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -616,22 +616,34 @@ fn codegen_stmt<'tcx>(
616616
Rvalue::UnaryOp(un_op, ref operand) => {
617617
let operand = codegen_operand(fx, operand);
618618
let layout = operand.layout();
619-
let val = operand.load_scalar(fx);
620619
let res = match un_op {
621-
UnOp::Not => match layout.ty.kind() {
622-
ty::Bool => {
623-
let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
624-
CValue::by_val(res, layout)
620+
UnOp::Not => {
621+
let val = operand.load_scalar(fx);
622+
match layout.ty.kind() {
623+
ty::Bool => {
624+
let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
625+
CValue::by_val(res, layout)
626+
}
627+
ty::Uint(_) | ty::Int(_) => {
628+
CValue::by_val(fx.bcx.ins().bnot(val), layout)
629+
}
630+
_ => unreachable!("un op Not for {:?}", layout.ty),
625631
}
626-
ty::Uint(_) | ty::Int(_) => {
627-
CValue::by_val(fx.bcx.ins().bnot(val), layout)
632+
}
633+
UnOp::Neg => {
634+
let val = operand.load_scalar(fx);
635+
match layout.ty.kind() {
636+
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
637+
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
638+
_ => unreachable!("un op Neg for {:?}", layout.ty),
628639
}
629-
_ => unreachable!("un op Not for {:?}", layout.ty),
630-
},
631-
UnOp::Neg => match layout.ty.kind() {
632-
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
633-
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
634-
_ => unreachable!("un op Neg for {:?}", layout.ty),
640+
}
641+
UnOp::PtrMetadata => match layout.abi {
642+
Abi::Scalar(_) => CValue::zst(dest_layout),
643+
Abi::ScalarPair(_, _) => {
644+
CValue::by_val(operand.load_scalar_pair(fx).1, dest_layout)
645+
}
646+
_ => bug!("Unexpected `PtrToMetadata` operand: {operand:?}"),
635647
},
636648
};
637649
lval.write_cvalue(fx, res);

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub(crate) fn codegen_const_value<'tcx>(
100100
assert!(layout.is_sized(), "unsized const value");
101101

102102
if layout.is_zst() {
103-
return CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout);
103+
return CValue::zst(layout);
104104
}
105105

106106
match const_val {

compiler/rustc_codegen_cranelift/src/value_and_place.rs

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

98+
/// Create an instance of a ZST
99+
///
100+
/// The is represented by a dangling pointer of suitable alignment.
101+
pub(crate) fn zst(layout: TyAndLayout<'tcx>) -> CValue<'tcx> {
102+
assert!(layout.is_zst());
103+
CValue::by_ref(crate::Pointer::dangling(layout.align.pref), layout)
104+
}
105+
98106
pub(crate) fn layout(&self) -> TyAndLayout<'tcx> {
99107
self.1
100108
}

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
565565
for elem in place_ref.projection.iter() {
566566
match elem {
567567
mir::ProjectionElem::Field(ref f, _) => {
568+
debug_assert!(
569+
!o.layout.ty.is_any_ptr(),
570+
"Bad PlaceRef: destructing pointers should use cast/PtrMetadata, \
571+
but tried to access field {f:?} of pointer {o:?}",
572+
);
568573
o = o.extract_field(bx, f.index());
569574
}
570575
mir::ProjectionElem::Index(_)

compiler/rustc_codegen_ssa/src/mir/place.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
480480
cg_base = match *elem {
481481
mir::ProjectionElem::Deref => bx.load_operand(cg_base).deref(bx.cx()),
482482
mir::ProjectionElem::Field(ref field, _) => {
483+
debug_assert!(
484+
!cg_base.layout.ty.is_any_ptr(),
485+
"Bad PlaceRef: destructing pointers should use cast/PtrMetadata, \
486+
but tried to access field {field:?} of pointer {cg_base:?}",
487+
);
483488
cg_base.project_field(bx, field.index())
484489
}
485490
mir::ProjectionElem::OpaqueCast(ty) => {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -623,19 +623,36 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
623623

624624
mir::Rvalue::UnaryOp(op, ref operand) => {
625625
let operand = self.codegen_operand(bx, operand);
626-
let lloperand = operand.immediate();
627626
let is_float = operand.layout.ty.is_floating_point();
628-
let llval = match op {
629-
mir::UnOp::Not => bx.not(lloperand),
627+
let (val, layout) = match op {
628+
mir::UnOp::Not => {
629+
let llval = bx.not(operand.immediate());
630+
(OperandValue::Immediate(llval), operand.layout)
631+
}
630632
mir::UnOp::Neg => {
631-
if is_float {
632-
bx.fneg(lloperand)
633+
let llval = if is_float {
634+
bx.fneg(operand.immediate())
635+
} else {
636+
bx.neg(operand.immediate())
637+
};
638+
(OperandValue::Immediate(llval), operand.layout)
639+
}
640+
mir::UnOp::PtrMetadata => {
641+
debug_assert!(operand.layout.ty.is_unsafe_ptr());
642+
let (_, meta) = operand.val.pointer_parts();
643+
assert_eq!(operand.layout.fields.count() > 1, meta.is_some());
644+
if let Some(meta) = meta {
645+
(OperandValue::Immediate(meta), operand.layout.field(self.cx, 1))
633646
} else {
634-
bx.neg(lloperand)
647+
(OperandValue::ZeroSized, bx.cx().layout_of(bx.tcx().types.unit))
635648
}
636649
}
637650
};
638-
OperandRef { val: OperandValue::Immediate(llval), layout: operand.layout }
651+
debug_assert!(
652+
val.is_expected_variant_for_type(self.cx, layout),
653+
"Made wrong variant {val:?} for type {layout:?}",
654+
);
655+
OperandRef { val, layout }
639656
}
640657

641658
mir::Rvalue::Discriminant(ref place) => {
@@ -718,8 +735,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
718735
let values = op.val.immediates_or_place().left_or_else(|p| {
719736
bug!("Field {field_idx:?} is {p:?} making {layout:?}");
720737
});
721-
inputs.extend(values);
722738
let scalars = self.value_kind(op.layout).scalars().unwrap();
739+
debug_assert_eq!(values.len(), scalars.len());
740+
inputs.extend(values);
723741
input_scalars.extend(scalars);
724742
}
725743

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
174174
unimplemented!()
175175
}
176176

177-
fn init_frame_extra(
177+
fn init_frame(
178178
_ecx: &mut InterpCx<'tcx, Self>,
179179
_frame: interpret::Frame<'tcx, Self::Provenance>,
180180
) -> interpret::InterpResult<'tcx, interpret::Frame<'tcx, Self::Provenance, Self::FrameExtra>>

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeInterpreter<'tcx> {
643643
}
644644

645645
#[inline(always)]
646-
fn init_frame_extra(
646+
fn init_frame(
647647
ecx: &mut InterpCx<'tcx, Self>,
648648
frame: Frame<'tcx>,
649649
) -> InterpResult<'tcx, Frame<'tcx>> {

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
207207
assert!(cast_to.ty.is_unsafe_ptr());
208208
// Handle casting any ptr to raw ptr (might be a fat ptr).
209209
if cast_to.size == src.layout.size {
210-
// Thin or fat pointer that just hast the ptr kind of target type changed.
210+
// Thin or fat pointer that just has the ptr kind of target type changed.
211211
return Ok(ImmTy::from_immediate(**src, cast_to));
212212
} else {
213213
// Casting the metadata away from a fat ptr.

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
819819
tracing_span: SpanGuard::new(),
820820
extra: (),
821821
};
822-
let frame = M::init_frame_extra(self, pre_frame)?;
822+
let frame = M::init_frame(self, pre_frame)?;
823823
self.stack_mut().push(frame);
824824

825825
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).

0 commit comments

Comments
 (0)