about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--example/alloc_example.rs7
-rw-r--r--src/abi/mod.rs2
-rw-r--r--src/allocator.rs23
-rw-r--r--src/base.rs2
-rw-r--r--src/intrinsics/mod.rs2
5 files changed, 31 insertions, 5 deletions
diff --git a/example/alloc_example.rs b/example/alloc_example.rs
index 31a294ad7a8..d994e2fbc0a 100644
--- a/example/alloc_example.rs
+++ b/example/alloc_example.rs
@@ -1,4 +1,4 @@
-#![feature(start, core_intrinsics)]
+#![feature(start, core_intrinsics, alloc_error_handler)]
 #![no_std]
 
 extern crate alloc;
@@ -22,6 +22,11 @@ fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! {
     core::intrinsics::abort();
 }
 
+#[alloc_error_handler]
+fn alloc_error_handler(_: alloc::alloc::Layout) -> ! {
+    core::intrinsics::abort();
+}
+
 #[start]
 fn main(_argc: isize, _argv: *const *const u8) -> isize {
     let world: Box<&str> = Box::new("Hello World!\0");
diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index 70eb0d0fa97..e533afcfaa9 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -70,7 +70,7 @@ pub(crate) fn get_function_sig<'tcx>(
     default_call_conv: CallConv,
     inst: Instance<'tcx>,
 ) -> Signature {
-    assert!(!inst.substs.needs_infer());
+    assert!(!inst.substs.has_infer());
     clif_sig_from_fn_abi(
         tcx,
         default_call_conv,
diff --git a/src/allocator.rs b/src/allocator.rs
index 9fb8079a21f..2c246ceb37d 100644
--- a/src/allocator.rs
+++ b/src/allocator.rs
@@ -6,6 +6,7 @@ use crate::prelude::*;
 use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
 use rustc_codegen_ssa::base::allocator_kind_for_codegen;
 use rustc_session::config::OomStrategy;
+use rustc_span::symbol::sym;
 
 /// Returns whether an allocator shim was created
 pub(crate) fn codegen(
@@ -14,7 +15,13 @@ pub(crate) fn codegen(
     unwind_context: &mut UnwindContext,
 ) -> bool {
     let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
-    codegen_inner(module, unwind_context, kind, tcx.sess.opts.unstable_opts.oom);
+    codegen_inner(
+        module,
+        unwind_context,
+        kind,
+        tcx.alloc_error_handler_kind(()).unwrap(),
+        tcx.sess.opts.unstable_opts.oom,
+    );
     true
 }
 
@@ -22,6 +29,7 @@ fn codegen_inner(
     module: &mut impl Module,
     unwind_context: &mut UnwindContext,
     kind: AllocatorKind,
+    alloc_error_handler_kind: AllocatorKind,
     oom_strategy: OomStrategy,
 ) {
     let usize_ty = module.target_config().pointer_type();
@@ -63,6 +71,19 @@ fn codegen_inner(
         );
     }
 
+    let sig = Signature {
+        call_conv: module.target_config().default_call_conv,
+        params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)],
+        returns: vec![],
+    };
+    crate::common::create_wrapper_function(
+        module,
+        unwind_context,
+        sig,
+        "__rust_alloc_error_handler",
+        &alloc_error_handler_kind.fn_name(sym::oom),
+    );
+
     let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap();
     let mut data_ctx = DataContext::new();
     data_ctx.set_align(1);
diff --git a/src/base.rs b/src/base.rs
index 16398c19bb1..292f24263ac 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -28,7 +28,7 @@ pub(crate) fn codegen_fn<'tcx>(
     module: &mut dyn Module,
     instance: Instance<'tcx>,
 ) -> CodegenedFunction {
-    debug_assert!(!instance.substs.needs_infer());
+    debug_assert!(!instance.substs.has_infer());
 
     let symbol_name = tcx.symbol_name(instance).name.to_string();
     let _timer = tcx.prof.generic_activity_with_arg("codegen fn", &*symbol_name);
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs
index 571af04f22c..539f8c103db 100644
--- a/src/intrinsics/mod.rs
+++ b/src/intrinsics/mod.rs
@@ -530,7 +530,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
 
         // The only difference between offset and arith_offset is regarding UB. Because Cranelift
         // doesn't have UB both are codegen'ed the same way
-        sym::offset | sym::arith_offset => {
+        sym::arith_offset => {
             intrinsic_args!(fx, args => (base, offset); intrinsic);
             let offset = offset.load_scalar(fx);