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

Commit 35acd91

Browse files
committed
Sync from rust a2b1646
2 parents 134dc33 + e6d1a0e commit 35acd91

File tree

4 files changed

+55
-50
lines changed

4 files changed

+55
-50
lines changed

src/abi/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
432432
let is_cold = if fn_sig.abi() == Abi::RustCold {
433433
true
434434
} else {
435-
instance
436-
.map(|inst| {
437-
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
438-
})
439-
.unwrap_or(false)
435+
instance.is_some_and(|inst| {
436+
fx.tcx.codegen_fn_attrs(inst.def_id()).flags.contains(CodegenFnAttrFlags::COLD)
437+
})
440438
};
441439
if is_cold {
442440
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
@@ -470,7 +468,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
470468
};
471469

472470
// Pass the caller location for `#[track_caller]`.
473-
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
471+
if instance.is_some_and(|inst| inst.def.requires_caller_location(fx.tcx)) {
474472
let caller_location = fx.get_caller_location(source_info);
475473
args.push(CallArgument { value: caller_location, is_owned: false });
476474
}

src/allocator.rs

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33

44
use crate::prelude::*;
55

6-
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
6+
use rustc_ast::expand::allocator::{
7+
alloc_error_handler_name, default_fn_name, global_fn_name, AllocatorKind, AllocatorTy,
8+
ALLOCATOR_METHODS, NO_ALLOC_SHIM_IS_UNSTABLE,
9+
};
710
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
811
use rustc_session::config::OomStrategy;
9-
use rustc_span::symbol::sym;
1012

1113
/// Returns whether an allocator shim was created
1214
pub(crate) fn codegen(
@@ -34,41 +36,43 @@ fn codegen_inner(
3436
) {
3537
let usize_ty = module.target_config().pointer_type();
3638

37-
for method in ALLOCATOR_METHODS {
38-
let mut arg_tys = Vec::with_capacity(method.inputs.len());
39-
for ty in method.inputs.iter() {
40-
match *ty {
41-
AllocatorTy::Layout => {
42-
arg_tys.push(usize_ty); // size
43-
arg_tys.push(usize_ty); // align
44-
}
45-
AllocatorTy::Ptr => arg_tys.push(usize_ty),
46-
AllocatorTy::Usize => arg_tys.push(usize_ty),
39+
if kind == AllocatorKind::Default {
40+
for method in ALLOCATOR_METHODS {
41+
let mut arg_tys = Vec::with_capacity(method.inputs.len());
42+
for ty in method.inputs.iter() {
43+
match *ty {
44+
AllocatorTy::Layout => {
45+
arg_tys.push(usize_ty); // size
46+
arg_tys.push(usize_ty); // align
47+
}
48+
AllocatorTy::Ptr => arg_tys.push(usize_ty),
49+
AllocatorTy::Usize => arg_tys.push(usize_ty),
4750

48-
AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
51+
AllocatorTy::ResultPtr | AllocatorTy::Unit => panic!("invalid allocator arg"),
52+
}
4953
}
50-
}
51-
let output = match method.output {
52-
AllocatorTy::ResultPtr => Some(usize_ty),
53-
AllocatorTy::Unit => None,
54+
let output = match method.output {
55+
AllocatorTy::ResultPtr => Some(usize_ty),
56+
AllocatorTy::Unit => None,
5457

55-
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
56-
panic!("invalid allocator output")
57-
}
58-
};
58+
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
59+
panic!("invalid allocator output")
60+
}
61+
};
5962

60-
let sig = Signature {
61-
call_conv: module.target_config().default_call_conv,
62-
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
63-
returns: output.into_iter().map(AbiParam::new).collect(),
64-
};
65-
crate::common::create_wrapper_function(
66-
module,
67-
unwind_context,
68-
sig,
69-
&format!("__rust_{}", method.name),
70-
&kind.fn_name(method.name),
71-
);
63+
let sig = Signature {
64+
call_conv: module.target_config().default_call_conv,
65+
params: arg_tys.iter().cloned().map(AbiParam::new).collect(),
66+
returns: output.into_iter().map(AbiParam::new).collect(),
67+
};
68+
crate::common::create_wrapper_function(
69+
module,
70+
unwind_context,
71+
sig,
72+
&global_fn_name(method.name),
73+
&default_fn_name(method.name),
74+
);
75+
}
7276
}
7377

7478
let sig = Signature {
@@ -81,7 +85,7 @@ fn codegen_inner(
8185
unwind_context,
8286
sig,
8387
"__rust_alloc_error_handler",
84-
&alloc_error_handler_kind.fn_name(sym::oom),
88+
&alloc_error_handler_name(alloc_error_handler_kind),
8589
);
8690

8791
let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
@@ -90,4 +94,11 @@ fn codegen_inner(
9094
let val = oom_strategy.should_panic();
9195
data.define(Box::new([val]));
9296
module.define_data(data_id, &data).unwrap();
97+
98+
let data_id =
99+
module.declare_data(NO_ALLOC_SHIM_IS_UNSTABLE, Linkage::Export, false, false).unwrap();
100+
let mut data = DataDescription::new();
101+
data.set_align(1);
102+
data.define(Box::new([0]));
103+
module.define_data(data_id, &data).unwrap();
93104
}

src/base.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,11 @@ fn codegen_stmt<'tcx>(
631631
let to_ty = fx.monomorphize(to_ty);
632632

633633
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
634-
ty.builtin_deref(true)
635-
.map(|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
634+
ty.builtin_deref(true).is_some_and(
635+
|ty::TypeAndMut { ty: pointee_ty, mutbl: _ }| {
636636
has_ptr_meta(fx.tcx, pointee_ty)
637-
})
638-
.unwrap_or(false)
637+
},
638+
)
639639
}
640640

641641
if is_fat_ptr(fx, from_ty) {
@@ -967,11 +967,7 @@ fn codegen_panic_inner<'tcx>(
967967
args: &[Value],
968968
span: Span,
969969
) {
970-
let def_id = fx
971-
.tcx
972-
.lang_items()
973-
.require(lang_item)
974-
.unwrap_or_else(|e| fx.tcx.sess.span_fatal(span, e.to_string()));
970+
let def_id = fx.tcx.require_lang_item(lang_item, Some(span));
975971

976972
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
977973
let symbol_name = fx.tcx.symbol_name(instance).name;

src/pretty_clif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub(crate) fn write_ir_file(
227227
// Using early_warn as no Session is available here
228228
rustc_session::early_warn(
229229
rustc_session::config::ErrorOutputType::default(),
230-
&format!("error writing ir file: {}", err),
230+
format!("error writing ir file: {}", err),
231231
);
232232
}
233233
}

0 commit comments

Comments
 (0)