Skip to content

Commit a0ea60b

Browse files
committed
Sync from rust debd22da66cfa97c74040ebf68e420672ac8560e
2 parents ba8c695 + db4dbc8 commit a0ea60b

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed

src/abi/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ pub(crate) fn codegen_drop<'tcx>(
593593
fx: &mut FunctionCx<'_, '_, 'tcx>,
594594
source_info: mir::SourceInfo,
595595
drop_place: CPlace<'tcx>,
596+
target: BasicBlock,
596597
) {
597598
let ty = drop_place.layout().ty;
598599
let drop_instance = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);
@@ -620,6 +621,12 @@ pub(crate) fn codegen_drop<'tcx>(
620621
let ptr = ptr.get_addr(fx);
621622
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
622623

624+
let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
625+
let target_block = fx.get_block(target);
626+
let continued = fx.bcx.create_block();
627+
fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
628+
fx.bcx.switch_to_block(continued);
629+
623630
// FIXME(eddyb) perhaps move some of this logic into
624631
// `Instance::resolve_drop_in_place`?
625632
let virtual_drop = Instance {
@@ -659,6 +666,12 @@ pub(crate) fn codegen_drop<'tcx>(
659666
let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx);
660667
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable);
661668

669+
let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0);
670+
let target_block = fx.get_block(target);
671+
let continued = fx.bcx.create_block();
672+
fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]);
673+
fx.bcx.switch_to_block(continued);
674+
662675
let virtual_drop = Instance {
663676
def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
664677
args: drop_instance.args,
@@ -697,4 +710,7 @@ pub(crate) fn codegen_drop<'tcx>(
697710
}
698711
}
699712
}
713+
714+
let target_block = fx.get_block(target);
715+
fx.bcx.ins().jump(target_block, &[]);
700716
}

src/base.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
548548
}
549549
TerminatorKind::Drop { place, target, unwind: _, replace: _ } => {
550550
let drop_place = codegen_place(fx, *place);
551-
crate::abi::codegen_drop(fx, source_info, drop_place);
552-
553-
let target_block = fx.get_block(*target);
554-
fx.bcx.ins().jump(target_block, &[]);
551+
crate::abi::codegen_drop(fx, source_info, drop_place, *target);
555552
}
556553
};
557554
}
@@ -619,22 +616,34 @@ fn codegen_stmt<'tcx>(
619616
Rvalue::UnaryOp(un_op, ref operand) => {
620617
let operand = codegen_operand(fx, operand);
621618
let layout = operand.layout();
622-
let val = operand.load_scalar(fx);
623619
let res = match un_op {
624-
UnOp::Not => match layout.ty.kind() {
625-
ty::Bool => {
626-
let res = fx.bcx.ins().icmp_imm(IntCC::Equal, val, 0);
627-
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),
628631
}
629-
ty::Uint(_) | ty::Int(_) => {
630-
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),
631639
}
632-
_ => unreachable!("un op Not for {:?}", layout.ty),
633-
},
634-
UnOp::Neg => match layout.ty.kind() {
635-
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
636-
ty::Float(_) => CValue::by_val(fx.bcx.ins().fneg(val), layout),
637-
_ => 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:?}"),
638647
},
639648
};
640649
lval.write_cvalue(fx, res);

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 {

src/driver/aot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn produce_final_output_artifacts(
200200
// to get rid of it.
201201
for output_type in crate_output.outputs.keys() {
202202
match *output_type {
203-
OutputType::Bitcode => {
203+
OutputType::Bitcode | OutputType::ThinLinkBitcode => {
204204
// Cranelift doesn't have bitcode
205205
// user_wants_bitcode = true;
206206
// // Copy to .bc, but always keep the .0.bc. There is a later

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
}

0 commit comments

Comments
 (0)