mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Sync from rust a2b1646c59
This commit is contained in:
commit
35acd910bb
@ -432,11 +432,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
|||||||
let is_cold = if fn_sig.abi() == Abi::RustCold {
|
let is_cold = if fn_sig.abi() == Abi::RustCold {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
instance
|
instance.is_some_and(|inst| {
|
||||||
.map(|inst| {
|
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
|
||||||
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
|
})
|
||||||
})
|
|
||||||
.unwrap_or(false)
|
|
||||||
};
|
};
|
||||||
if is_cold {
|
if is_cold {
|
||||||
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
|
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
|
||||||
@ -470,7 +468,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Pass the caller location for `#[track_caller]`.
|
// Pass the caller location for `#[track_caller]`.
|
||||||
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
|
if instance.is_some_and(|inst| inst.def.requires_caller_location(fx.tcx)) {
|
||||||
let caller_location = fx.get_caller_location(source_info);
|
let caller_location = fx.get_caller_location(source_info);
|
||||||
args.push(CallArgument { value: caller_location, is_owned: false });
|
args.push(CallArgument { value: caller_location, is_owned: false });
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
|
use rustc_ast::expand::allocator::{
|
||||||
|
alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy,
|
||||||
|
ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE,
|
||||||
|
};
|
||||||
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
|
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
|
||||||
use rustc_session::config::OomStrategy;
|
use rustc_session::config::OomStrategy;
|
||||||
use rustc_span::symbol::sym;
|
|
||||||
|
|
||||||
/// Returns whether an allocator shim was created
|
/// Returns whether an allocator shim was created
|
||||||
pub(crate) fn codegen(
|
pub(crate) fn codegen(
|
||||||
@ -34,41 +36,43 @@ fn codegen_inner(
|
|||||||
) {
|
) {
|
||||||
let usize_ty = module.target_config().pointer_type();
|
let usize_ty = module.target_config().pointer_type();
|
||||||
|
|
||||||
for method in ALLOCATOR_METHODS {
|
if kind == AllocatorKind::Default {
|
||||||
let mut arg_tys = Vec::with_capacity(method.inputs.len());
|
for method in ALLOCATOR_METHODS {
|
||||||
for ty in method.inputs.iter() {
|
let mut arg_tys = Vec::with_capacity(method.inputs.len());
|
||||||
match *ty {
|
for ty in method.inputs.iter() {
|
||||||
AllocatorTy::Layout => {
|
match *ty {
|
||||||
arg_tys.push(usize_ty); // size
|
AllocatorTy::Layout => {
|
||||||
arg_tys.push(usize_ty); // align
|
arg_tys.push(usize_ty); // size
|
||||||
|
arg_tys.push(usize_ty); // align
|
||||||
|
}
|
||||||
|
AllocatorTy::Ptr => arg_tys.push(usize_ty),
|
||||||
|
AllocatorTy::Usize => arg_tys.push(usize_ty),
|
||||||
|
|
||||||
|
AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
|
||||||
}
|
}
|
||||||
AllocatorTy::Ptr => arg_tys.push(usize_ty),
|
|
||||||
AllocatorTy::Usize => arg_tys.push(usize_ty),
|
|
||||||
|
|
||||||
AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
|
|
||||||
}
|
}
|
||||||
|
let output = match method.output {
|
||||||
|
AllocatorTy::ResultPtr => Some(usize_ty),
|
||||||
|
AllocatorTy::Unit => None,
|
||||||
|
|
||||||
|
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
|
||||||
|
panic!("invalid allocator output")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let sig = Signature {
|
||||||
|
call_conv: module.target_config().default_call_conv,
|
||||||
|
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
|
||||||
|
returns: output.into_iter().map(AbiParam::new).collect(),
|
||||||
|
};
|
||||||
|
crate::common::create_wrapper_function(
|
||||||
|
module,
|
||||||
|
unwind_context,
|
||||||
|
sig,
|
||||||
|
&global_fn_name(method.name),
|
||||||
|
&default_fn_name(method.name),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let output = match method.output {
|
|
||||||
AllocatorTy::ResultPtr => Some(usize_ty),
|
|
||||||
AllocatorTy::Unit => None,
|
|
||||||
|
|
||||||
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
|
|
||||||
panic!("invalid allocator output")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let sig = Signature {
|
|
||||||
call_conv: module.target_config().default_call_conv,
|
|
||||||
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
|
|
||||||
returns: output.into_iter().map(AbiParam::new).collect(),
|
|
||||||
};
|
|
||||||
crate::common::create_wrapper_function(
|
|
||||||
module,
|
|
||||||
unwind_context,
|
|
||||||
sig,
|
|
||||||
&format!("__rust_{}", method.name),
|
|
||||||
&kind.fn_name(method.name),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let sig = Signature {
|
let sig = Signature {
|
||||||
@ -81,7 +85,7 @@ fn codegen_inner(
|
|||||||
unwind_context,
|
unwind_context,
|
||||||
sig,
|
sig,
|
||||||
"__rust_alloc_error_handler",
|
"__rust_alloc_error_handler",
|
||||||
&alloc_error_handler_kind.fn_name(sym::oom),
|
&alloc_error_handler_name(alloc_error_handler_kind),
|
||||||
);
|
);
|
||||||
|
|
||||||
let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
|
let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
|
||||||
@ -90,4 +94,11 @@ fn codegen_inner(
|
|||||||
let val = oom_strategy.should_panic();
|
let val = oom_strategy.should_panic();
|
||||||
data.define(Box::new([val]));
|
data.define(Box::new([val]));
|
||||||
module.define_data(data_id, &data).unwrap();
|
module.define_data(data_id, &data).unwrap();
|
||||||
|
|
||||||
|
let data_id =
|
||||||
|
module.declare_data(NO_ALLOC_SHIM_IS_UNSTABLE, Linkage::Export, false, false).unwrap();
|
||||||
|
let mut data = DataDescription::new();
|
||||||
|
data.set_align(1);
|
||||||
|
data.define(Box::new([0]));
|
||||||
|
module.define_data(data_id, &data).unwrap();
|
||||||
}
|
}
|
||||||
|
14
src/base.rs
14
src/base.rs
@ -631,11 +631,11 @@ fn codegen_stmt<'tcx>(
|
|||||||
let to_ty = fx.monomorphize(to_ty);
|
let to_ty = fx.monomorphize(to_ty);
|
||||||
|
|
||||||
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
|
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
|
||||||
ty.builtin_deref(true)
|
ty.builtin_deref(true).is_some_and(
|
||||||
.map(|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
|
|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
|
||||||
has_ptr_meta(fx.tcx, pointee_ty)
|
has_ptr_meta(fx.tcx, pointee_ty)
|
||||||
})
|
},
|
||||||
.unwrap_or(false)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_fat_ptr(fx, from_ty) {
|
if is_fat_ptr(fx, from_ty) {
|
||||||
@ -967,11 +967,7 @@ fn codegen_panic_inner<'tcx>(
|
|||||||
args: &[Value],
|
args: &[Value],
|
||||||
span: Span,
|
span: Span,
|
||||||
) {
|
) {
|
||||||
let def_id = fx
|
let def_id = fx.tcx.require_lang_item(lang_item, Some(span));
|
||||||
.tcx
|
|
||||||
.lang_items()
|
|
||||||
.require(lang_item)
|
|
||||||
.unwrap_or_else(|e| fx.tcx.sess.span_fatal(span, e.to_string()));
|
|
||||||
|
|
||||||
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
|
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
|
||||||
let symbol_name = fx.tcx.symbol_name(instance).name;
|
let symbol_name = fx.tcx.symbol_name(instance).name;
|
||||||
|
@ -227,7 +227,7 @@ pub(crate) fn write_ir_file(
|
|||||||
// Using early_warn as no Session is available here
|
// Using early_warn as no Session is available here
|
||||||
rustc_session::early_warn(
|
rustc_session::early_warn(
|
||||||
rustc_session::config::ErrorOutputType::default(),
|
rustc_session::config::ErrorOutputType::default(),
|
||||||
&format!("error writing ir file: {}", err),
|
format!("error writing ir file: {}", err),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user