From 540e41f8b3822661d2f9d0768bbfe1dd3bb65e4d Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Wed, 25 Sep 2024 10:23:30 +0200 Subject: [PATCH] Add missing module flags for function-return=thunk-extern --- compiler/rustc_codegen_llvm/src/context.rs | 14 +++++++++++++- tests/codegen/function-return.rs | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 2b8912d1db2..81b82840472 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -19,7 +19,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_session::Session; use rustc_session::config::{ - BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, PAuthKey, PacRet, + BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, FunctionReturn, PAuthKey, PacRet, }; use rustc_span::source_map::Spanned; use rustc_span::{DUMMY_SP, Span}; @@ -378,6 +378,18 @@ pub(crate) unsafe fn create_module<'ll>( } } + match sess.opts.unstable_opts.function_return { + FunctionReturn::Keep => {} + FunctionReturn::ThunkExtern => unsafe { + llvm::LLVMRustAddModuleFlagU32( + llmod, + llvm::LLVMModFlagBehavior::Override, + c"function_return_thunk_extern".as_ptr(), + 1, + ) + }, + } + match (sess.opts.unstable_opts.small_data_threshold, sess.target.small_data_threshold_support()) { // Set up the small-data optimization limit for architectures that use diff --git a/tests/codegen/function-return.rs b/tests/codegen/function-return.rs index 0ca1a41ee86..2b9de4e1478 100644 --- a/tests/codegen/function-return.rs +++ b/tests/codegen/function-return.rs @@ -26,3 +26,9 @@ pub fn foo() { // keep-thunk-extern: attributes #0 = { {{.*}}fn_ret_thunk_extern{{.*}} } // thunk-extern-keep-NOT: fn_ret_thunk_extern } + +// unset-NOT: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1} +// keep-NOT: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1} +// thunk-extern: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1} +// keep-thunk-extern: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1} +// thunk-extern-keep-NOT: !{{[0-9]+}} = !{i32 4, !"function_return_thunk_extern", i32 1}