about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2021-10-06 15:52:54 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2022-03-03 12:58:38 +0000
commit6fcfc3d8773ee0f318a3311bb02655e0ccafbc14 (patch)
tree16be78b31b72dc2021d580efe049b908423f237c
parente855e2d15c8fcb4d6b9ffddb5f408acf008cc96f (diff)
downloadrust-6fcfc3d8773ee0f318a3311bb02655e0ccafbc14.tar.gz
rust-6fcfc3d8773ee0f318a3311bb02655e0ccafbc14.zip
Add -Z oom={panic,abort} command-line option
-rw-r--r--src/allocator.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/allocator.rs b/src/allocator.rs
index 6378a31202c..c761e5aabd1 100644
--- a/src/allocator.rs
+++ b/src/allocator.rs
@@ -1,7 +1,8 @@
-use gccjit::{FunctionType, ToRValue};
+use gccjit::{FunctionType, GlobalKind, ToRValue};
 use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS};
 use rustc_middle::bug;
 use rustc_middle::ty::TyCtxt;
+use rustc_session::config::OomStrategy;
 use rustc_span::symbol::sym;
 
 use crate::GccContext;
@@ -113,4 +114,10 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
     let _ret = context.new_call(None, callee, &args);
     //llvm::LLVMSetTailCall(ret, True);
     block.end_with_void_return(None);
+
+    let name = OomStrategy::SYMBOL.to_string();
+    let global = context.new_global(None, GlobalKind::Exported, i8, name);
+    let value = tcx.sess.opts.debugging_opts.oom.should_panic();
+    let value = context.new_rvalue_from_int(i8, value as i32);
+    global.global_set_initializer_rvalue(value);
 }