Skip to content

Commit fadd1c5

Browse files
committed
Auto merge of rust-lang#88098 - Amanieu:oom_panic, r=nagisa
Implement -Z oom=panic This PR removes the `#[rustc_allocator_nounwind]` attribute on `alloc_error_handler` which allows it to unwind with a panic instead of always aborting. This is then used to implement `-Z oom=panic` as per RFC 2116 (tracking issue rust-lang#43596). Perf and binary size tests show negligible impact.
2 parents 1c38932 + 6fcfc3d commit fadd1c5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/allocator.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use gccjit::{FunctionType, ToRValue};
1+
use gccjit::{FunctionType, GlobalKind, ToRValue};
22
use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
33
use rustc_middle::bug;
44
use rustc_middle::ty::TyCtxt;
5+
use rustc_session::config::OomStrategy;
56
use rustc_span::symbol::sym;
67

78
use crate::GccContext;
@@ -113,4 +114,10 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
113114
let _ret = context.new_call(None, callee, &args);
114115
//llvm::LLVMSetTailCall(ret, True);
115116
block.end_with_void_return(None);
117+
118+
let name = OomStrategy::SYMBOL.to_string();
119+
let global = context.new_global(None, GlobalKind::Exported, i8, name);
120+
let value = tcx.sess.opts.debugging_opts.oom.should_panic();
121+
let value = context.new_rvalue_from_int(i8, value as i32);
122+
global.global_set_initializer_rvalue(value);
116123
}

0 commit comments

Comments
 (0)