From 58eda6ec6775da8f47d119d73bc1d88a4b8f1cd1 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Fri, 2 Oct 2026 16:36:37 +1000 Subject: [PATCH] Use `LLVMGlobalAddMetadata` This function was added in LLVM 22. --- compiler/rustc_codegen_llvm/src/context.rs | 4 ++-- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 11 +++++------ compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | 5 ----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index d64c8de6ed7aa..1059de3c0aec0 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -1234,7 +1234,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// Helper method for the sequence of calls: /// - `LLVMMDNodeInContext2` (to create an `llvm::MDNode` from a list of metadata) - /// - `LLVMRustGlobalAddMetadata` (to set that node as metadata of `kind_id` for `global`) + /// - `LLVMGlobalAddMetadata` (to set that node as metadata of `kind_id` for `global`) pub(crate) fn global_add_metadata_node( &self, global: &'ll Value, @@ -1242,7 +1242,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { md_list: &[&'ll Metadata], ) { let md = self.md_node_in_context(md_list); - unsafe { llvm::LLVMRustGlobalAddMetadata(global, kind_id, md) }; + unsafe { llvm::LLVMGlobalAddMetadata(global, kind_id, md) }; } /// Helper method for the sequence of calls: diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 4c7d60a0cbf67..f576f29a17cca 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -993,6 +993,11 @@ unsafe extern "C" { KindID: MetadataKindId, Metadata: &'a Metadata, ); + pub(crate) fn LLVMGlobalAddMetadata<'ll>( + Global: &'ll Value, + Kind: MetadataKindId, + MD: &'ll Metadata, + ); pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata; // Operations on constants of any type @@ -1968,12 +1973,6 @@ unsafe extern "C" { pub(crate) fn LLVMRustDisableSystemDialogsOnCrash(); // Operations on all values - /// FIXME: After dropping LLVM 21, migrate to LLVM-C's `LLVMGlobalAddMetadata`. - pub(crate) fn LLVMRustGlobalAddMetadata<'a>( - Val: &'a Value, - KindID: MetadataKindId, - Metadata: &'a Metadata, - ); pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool; pub(crate) fn LLVMRustStripPointerCasts<'a>(Val: &'a Value) -> &'a Value; diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 4b14392db2c94..62aa8c5c57aae 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -1002,11 +1002,6 @@ extern "C" void LLVMRustRemoveFnAttribute(LLVMValueRef Fn, const char *Name, } } -extern "C" void LLVMRustGlobalAddMetadata(LLVMValueRef Global, unsigned Kind, - LLVMMetadataRef MD) { - unwrap(Global)->addMetadata(Kind, *unwrap(MD)); -} - extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit( LLVMDIBuilderRef Builder, unsigned Lang, LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, bool isOptimized,