Skip to content

Commit 28d480b

Browse files
committed
Sync from rust 0824b30
2 parents 5932283 + a517adc commit 28d480b

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

src/abi/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use std::borrow::Cow;
88

99
use cranelift_codegen::ir::SigRef;
1010
use cranelift_module::ModuleError;
11+
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
1112
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1213
use rustc_middle::ty::layout::FnAbiOf;
14+
use rustc_middle::ty::print::with_no_trimmed_paths;
15+
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
1316
use rustc_session::Session;
1417
use rustc_span::source_map::Spanned;
1518
use rustc_target::abi::call::{Conv, FnAbi};
@@ -372,6 +375,17 @@ pub(crate) fn codegen_terminator_call<'tcx>(
372375
ty::Instance::expect_resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, fn_args)
373376
.polymorphize(fx.tcx);
374377

378+
if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
379+
if target.is_some() {
380+
let caller = with_no_trimmed_paths!(fx.tcx.def_path_str(fx.instance.def_id()));
381+
let callee = with_no_trimmed_paths!(fx.tcx.def_path_str(def_id));
382+
fx.tcx.dcx().emit_err(CompilerBuiltinsCannotCall { caller, callee });
383+
} else {
384+
fx.bcx.ins().trap(TrapCode::User(0));
385+
return;
386+
}
387+
}
388+
375389
if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
376390
crate::intrinsics::codegen_llvm_intrinsic_call(
377391
fx,
@@ -663,11 +677,7 @@ pub(crate) fn codegen_drop<'tcx>(
663677

664678
let arg_value = drop_place.place_ref(
665679
fx,
666-
fx.layout_of(Ty::new_ref(
667-
fx.tcx,
668-
fx.tcx.lifetimes.re_erased,
669-
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
670-
)),
680+
fx.layout_of(Ty::new_mut_ref(fx.tcx, fx.tcx.lifetimes.re_erased, ty)),
671681
);
672682
let arg_value = adjust_arg_for_abi(fx, arg_value, &fn_abi.args[0], true);
673683

src/base.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_index::IndexVec;
88
use rustc_middle::ty::adjustment::PointerCoercion;
99
use rustc_middle::ty::layout::FnAbiOf;
1010
use rustc_middle::ty::print::with_no_trimmed_paths;
11+
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
1112

1213
use crate::constant::ConstantCx;
1314
use crate::debuginfo::FunctionDebugContext;
@@ -779,7 +780,7 @@ fn codegen_stmt<'tcx>(
779780
NullOp::OffsetOf(fields) => {
780781
layout.offset_of_subfield(fx, fields.iter()).bytes()
781782
}
782-
NullOp::UbCheck(_) => {
783+
NullOp::UbChecks => {
783784
let val = fx.tcx.sess.opts.debug_assertions;
784785
let val = CValue::by_val(
785786
fx.bcx.ins().iconst(types::I8, i64::try_from(val).unwrap()),
@@ -999,6 +1000,12 @@ fn codegen_panic_inner<'tcx>(
9991000
let def_id = fx.tcx.require_lang_item(lang_item, span);
10001001

10011002
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
1003+
1004+
if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
1005+
fx.bcx.ins().trap(TrapCode::User(0));
1006+
return;
1007+
}
1008+
10021009
let symbol_name = fx.tcx.symbol_name(instance).name;
10031010

10041011
fx.lib_call(

src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
6969
FloatTy::F128 => unimplemented!("f16_f128"),
7070
},
7171
ty::FnPtr(_) => pointer_ty(tcx),
72-
ty::RawPtr(TypeAndMut { ty: pointee_ty, mutbl: _ }) | ty::Ref(_, pointee_ty, _) => {
72+
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
7373
if has_ptr_meta(tcx, *pointee_ty) {
7474
return None;
7575
} else {
@@ -89,7 +89,7 @@ fn clif_pair_type_from_ty<'tcx>(
8989
ty::Tuple(types) if types.len() == 2 => {
9090
(clif_type_from_ty(tcx, types[0])?, clif_type_from_ty(tcx, types[1])?)
9191
}
92-
ty::RawPtr(TypeAndMut { ty: pointee_ty, mutbl: _ }) | ty::Ref(_, pointee_ty, _) => {
92+
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
9393
if has_ptr_meta(tcx, *pointee_ty) {
9494
(pointer_ty(tcx), pointer_ty(tcx))
9595
} else {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern crate rustc_hir;
2121
extern crate rustc_incremental;
2222
extern crate rustc_index;
2323
extern crate rustc_metadata;
24+
extern crate rustc_monomorphize;
2425
extern crate rustc_session;
2526
extern crate rustc_span;
2627
extern crate rustc_target;

src/unsize.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ fn unsize_ptr<'tcx>(
7070
) -> (Value, Value) {
7171
match (&src_layout.ty.kind(), &dst_layout.ty.kind()) {
7272
(&ty::Ref(_, a, _), &ty::Ref(_, b, _))
73-
| (&ty::Ref(_, a, _), &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
74-
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
75-
(src, unsized_info(fx, *a, *b, old_info))
76-
}
73+
| (&ty::Ref(_, a, _), &ty::RawPtr(b, _))
74+
| (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => (src, unsized_info(fx, *a, *b, old_info)),
7775
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
7876
assert_eq!(def_a, def_b);
7977

src/value_and_place.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,10 @@ pub(crate) fn assert_assignable<'tcx>(
865865
return;
866866
}
867867
match (from_ty.kind(), to_ty.kind()) {
868-
(ty::Ref(_, a, _), ty::Ref(_, b, _))
869-
| (
870-
ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }),
871-
ty::RawPtr(TypeAndMut { ty: b, mutbl: _ }),
872-
) => {
868+
(ty::Ref(_, a, _), ty::Ref(_, b, _)) | (ty::RawPtr(a, _), ty::RawPtr(b, _)) => {
873869
assert_assignable(fx, *a, *b, limit - 1);
874870
}
875-
(ty::Ref(_, a, _), ty::RawPtr(TypeAndMut { ty: b, mutbl: _ }))
876-
| (ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }), ty::Ref(_, b, _)) => {
871+
(ty::Ref(_, a, _), ty::RawPtr(b, _)) | (ty::RawPtr(a, _), ty::Ref(_, b, _)) => {
877872
assert_assignable(fx, *a, *b, limit - 1);
878873
}
879874
(ty::FnPtr(_), ty::FnPtr(_)) => {

0 commit comments

Comments
 (0)