Skip to content

Commit 72022bb

Browse files
committed
Sync from rust f495605
2 parents 0c79ce3 + 2f624db commit 72022bb

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

example/alloc_example.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(start, core_intrinsics)]
1+
#![feature(start, core_intrinsics, alloc_error_handler)]
22
#![no_std]
33

44
extern crate alloc;
@@ -22,6 +22,11 @@ fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
2222
core::intrinsics::abort();
2323
}
2424

25+
#[alloc_error_handler]
26+
fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
27+
core::intrinsics::abort();
28+
}
29+
2530
#[start]
2631
fn main(_argc: isize, _argv: *const *const u8) -> isize {
2732
let world: Box<&str> = Box::new("Hello World!\0");

src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn get_function_sig<'tcx>(
7070
default_call_conv: CallConv,
7171
inst: Instance<'tcx>,
7272
) -> Signature {
73-
assert!(!inst.substs.needs_infer());
73+
assert!(!inst.substs.has_infer());
7474
clif_sig_from_fn_abi(
7575
tcx,
7676
default_call_conv,

src/allocator.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::prelude::*;
66
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
77
use rustc_codegen_ssa::base::allocator_kind_for_codegen;
88
use rustc_session::config::OomStrategy;
9+
use rustc_span::symbol::sym;
910

1011
/// Returns whether an allocator shim was created
1112
pub(crate) fn codegen(
@@ -14,14 +15,21 @@ pub(crate) fn codegen(
1415
unwind_context: &mut UnwindContext,
1516
) -> bool {
1617
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
17-
codegen_inner(module, unwind_context, kind, tcx.sess.opts.unstable_opts.oom);
18+
codegen_inner(
19+
module,
20+
unwind_context,
21+
kind,
22+
tcx.alloc_error_handler_kind(()).unwrap(),
23+
tcx.sess.opts.unstable_opts.oom,
24+
);
1825
true
1926
}
2027

2128
fn codegen_inner(
2229
module: &mut impl Module,
2330
unwind_context: &mut UnwindContext,
2431
kind: AllocatorKind,
32+
alloc_error_handler_kind: AllocatorKind,
2533
oom_strategy: OomStrategy,
2634
) {
2735
let usize_ty = module.target_config().pointer_type();
@@ -63,6 +71,19 @@ fn codegen_inner(
6371
);
6472
}
6573

74+
let sig = Signature {
75+
call_conv: module.target_config().default_call_conv,
76+
params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)],
77+
returns: vec![],
78+
};
79+
crate::common::create_wrapper_function(
80+
module,
81+
unwind_context,
82+
sig,
83+
"__rust_alloc_error_handler",
84+
&alloc_error_handler_kind.fn_name(sym::oom),
85+
);
86+
6687
let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
6788
let mut data_ctx = DataContext::new();
6889
data_ctx.set_align(1);

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) fn codegen_fn<'tcx>(
2828
module: &mut dyn Module,
2929
instance: Instance<'tcx>,
3030
) -> CodegenedFunction {
31-
debug_assert!(!instance.substs.needs_infer());
31+
debug_assert!(!instance.substs.has_infer());
3232

3333
let symbol_name = tcx.symbol_name(instance).name.to_string();
3434
let _timer = tcx.prof.generic_activity_with_arg("codegen fn", &*symbol_name);

src/intrinsics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
530530

531531
// The only difference between offset and arith_offset is regarding UB. Because Cranelift
532532
// doesn't have UB both are codegen'ed the same way
533-
sym::offset | sym::arith_offset => {
533+
sym::arith_offset => {
534534
intrinsic_args!(fx, args => (base, offset); intrinsic);
535535
let offset = offset.load_scalar(fx);
536536

0 commit comments

Comments
 (0)