From dd172d08d48beaba0ddd4f26657387d00e6633c6 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 19 Apr 2023 10:57:17 +0000 Subject: [PATCH 1/4] Split `{Idx, IndexVec, IndexSlice}` into their own modules --- src/analyze.rs | 2 +- src/base.rs | 2 +- src/common.rs | 2 +- src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/analyze.rs b/src/analyze.rs index 54d5c1c2ae9..359d581c153 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -2,7 +2,7 @@ use crate::prelude::*; -use rustc_index::vec::IndexVec; +use rustc_index::IndexVec; use rustc_middle::mir::StatementKind::*; use rustc_middle::ty::Ty; diff --git a/src/base.rs b/src/base.rs index f481290583e..98ba23c6f57 100644 --- a/src/base.rs +++ b/src/base.rs @@ -1,7 +1,7 @@ //! Codegen of a single function use rustc_ast::InlineAsmOptions; -use rustc_index::vec::IndexVec; +use rustc_index::IndexVec; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::print::with_no_trimmed_paths; diff --git a/src/common.rs b/src/common.rs index d39bf700035..528b35283d7 100644 --- a/src/common.rs +++ b/src/common.rs @@ -2,7 +2,7 @@ use cranelift_codegen::isa::TargetFrontendConfig; use gimli::write::FileId; use rustc_data_structures::sync::Lrc; -use rustc_index::vec::IndexVec; +use rustc_index::IndexVec; use rustc_middle::ty::layout::{ FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, }; diff --git a/src/lib.rs b/src/lib.rs index 8cc7f6c34b0..74d9b72b90c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,7 +90,7 @@ mod prelude { pub(crate) use rustc_data_structures::fx::FxHashMap; - pub(crate) use rustc_index::vec::Idx; + pub(crate) use rustc_index::Idx; pub(crate) use cranelift_codegen::ir::condcodes::{FloatCC, IntCC}; pub(crate) use cranelift_codegen::ir::function::Function; From 106db3ef59a20abd4403587895140114236ea4f5 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 19 Apr 2023 14:46:39 +0000 Subject: [PATCH 2/4] Fix `rustc_index` imports outside the compiler --- src/abi/returning.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abi/returning.rs b/src/abi/returning.rs index 6d3e8eda276..bd055216e36 100644 --- a/src/abi/returning.rs +++ b/src/abi/returning.rs @@ -9,7 +9,7 @@ use smallvec::{smallvec, SmallVec}; /// this adds an extra parameter pointing to where the return value needs to be stored. pub(super) fn codegen_return_param<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - ssa_analyzed: &rustc_index::vec::IndexVec, + ssa_analyzed: &rustc_index::IndexSlice, block_params_iter: &mut impl Iterator, ) -> CPlace<'tcx> { let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode { From b908472a93f218f12d8f980ddf6b008ecee83c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 25 Apr 2023 00:08:35 +0200 Subject: [PATCH 3/4] Revert "Remove #[alloc_error_handler] from the compiler and library" This reverts commit abc0660118cc95f47445fd33502a11dd448f5968. --- example/alloc_example.rs | 7 ++++++- src/allocator.rs | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/example/alloc_example.rs b/example/alloc_example.rs index e39c3272958..4ede2fe4efe 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/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); From 065d81ac6f8ab8dbc8bd39fc672bf821282d556e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Tue, 25 Apr 2023 12:10:55 -0700 Subject: [PATCH 4/4] Lower `intrinsics::offset` to `mir::BinOp::Offset` They're semantically the same, so this means the backends don't need to handle the intrinsic and means fewer MIR basic blocks in pointer arithmetic code. --- src/intrinsics/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 03f2a65fcca..90b36c61114 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -534,7 +534,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);