about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-04 14:37:30 +0000
committerbors <bors@rust-lang.org>2025-07-04 14:37:30 +0000
commit0c4fa2690de945f062668acfc36b3f8cfbd013e2 (patch)
tree2e57f7883dc3c6de58c406d64b53638140e19a16 /compiler/rustc_codegen_gcc
parent556d20a834126d2d0ac20743b9792b8474d6d03c (diff)
parent3a5da6c4d82a9d7d191ff8d2bfbd8350487ad855 (diff)
downloadrust-0c4fa2690de945f062668acfc36b3f8cfbd013e2.tar.gz
rust-0c4fa2690de945f062668acfc36b3f8cfbd013e2.zip
Auto merge of #143434 - matthiaskrgr:rollup-eyr4rcb, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#140643 (Refactor StableMIR)
 - rust-lang/rust#143286 (Make -Ztrack-diagnostics emit like a note)
 - rust-lang/rust#143308 (Remove `PointerLike` trait)
 - rust-lang/rust#143387 (Make __rust_alloc_error_handler_should_panic a function)
 - rust-lang/rust#143400 (Port `#[rustc_pass_by_value]` to the new attribute system)
 - rust-lang/rust#143417 (bump termize dep)
 - rust-lang/rust#143420 (rustc-dev-guide subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_gcc')
-rw-r--r--compiler/rustc_codegen_gcc/src/allocator.rs44
1 files changed, 33 insertions, 11 deletions
diff --git a/compiler/rustc_codegen_gcc/src/allocator.rs b/compiler/rustc_codegen_gcc/src/allocator.rs
index cf8aa500c77..0d8dc93274f 100644
--- a/compiler/rustc_codegen_gcc/src/allocator.rs
+++ b/compiler/rustc_codegen_gcc/src/allocator.rs
@@ -1,6 +1,6 @@
-use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
 #[cfg(feature = "master")]
-use gccjit::{FnAttribute, VarAttribute};
+use gccjit::FnAttribute;
+use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
 use rustc_ast::expand::allocator::{
     ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
     alloc_error_handler_name, default_fn_name, global_fn_name,
@@ -71,15 +71,13 @@ pub(crate) unsafe fn codegen(
         None,
     );
 
-    let name = mangle_internal_symbol(tcx, OomStrategy::SYMBOL);
-    let global = context.new_global(None, GlobalKind::Exported, i8, name);
-    #[cfg(feature = "master")]
-    global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
-        tcx.sess.default_visibility(),
-    )));
-    let value = tcx.sess.opts.unstable_opts.oom.should_panic();
-    let value = context.new_rvalue_from_int(i8, value as i32);
-    global.global_set_initializer_rvalue(value);
+    create_const_value_function(
+        tcx,
+        context,
+        &mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
+        i8,
+        context.new_rvalue_from_int(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as i32),
+    );
 
     create_wrapper_function(
         tcx,
@@ -91,6 +89,30 @@ pub(crate) unsafe fn codegen(
     );
 }
 
+fn create_const_value_function(
+    tcx: TyCtxt<'_>,
+    context: &Context<'_>,
+    name: &str,
+    output: Type<'_>,
+    value: RValue<'_>,
+) {
+    let func = context.new_function(None, FunctionType::Exported, output, &[], name, false);
+
+    #[cfg(feature = "master")]
+    func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
+        tcx.sess.default_visibility(),
+    )));
+
+    func.add_attribute(FnAttribute::AlwaysInline);
+
+    if tcx.sess.must_emit_unwind_tables() {
+        // TODO(antoyo): emit unwind tables.
+    }
+
+    let block = func.new_block("entry");
+    block.end_with_return(None, value);
+}
+
 fn create_wrapper_function(
     tcx: TyCtxt<'_>,
     context: &Context<'_>,