Skip to content

Commit

Permalink
Remove LLVMMDStringInContext.
Browse files Browse the repository at this point in the history
Because it's deprecated in LLVM. Use `LLVMMDStringInContext2` instead.
  • Loading branch information
nnethercote committed Sep 18, 2024
1 parent 04a3187 commit 5da0745
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
13 changes: 5 additions & 8 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::cell::{Cell, RefCell};
use std::ffi::CStr;
use std::str;

use libc::c_uint;
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
use rustc_codegen_ssa::errors as ssa_errors;
use rustc_codegen_ssa::traits::*;
Expand Down Expand Up @@ -413,18 +412,16 @@ pub(crate) unsafe fn create_module<'ll>(
let rustc_producer =
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
let name_metadata = unsafe {
llvm::LLVMMDStringInContext(
llvm::LLVMMDStringInContext2(
llcx,
rustc_producer.as_ptr().cast(),
rustc_producer.as_bytes().len() as c_uint,
rustc_producer.as_bytes().len(),
)
};
unsafe {
llvm::LLVMAddNamedMetadataOperand(
llmod,
c"llvm.ident".as_ptr(),
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
);
let meta = llvm::LLVMMDNodeInContext2(llcx, &name_metadata, 1);
let val = llvm::LLVMMetadataAsValue(llcx, meta);
llvm::LLVMAddNamedMetadataOperand(llmod, c"llvm.ident".as_ptr(), val);
}

// Emit RISC-V specific target-abi metadata
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,20 +1545,16 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
let trait_ref_typeid = typeid_for_trait_ref(cx.tcx, trait_ref);

unsafe {
let typeid = llvm::LLVMMDStringInContext(
let typeid = llvm::LLVMMDStringInContext2(
cx.llcx,
trait_ref_typeid.as_ptr() as *const c_char,
trait_ref_typeid.as_bytes().len() as c_uint,
trait_ref_typeid.as_bytes().len(),
);
let v = [cx.const_usize(0), typeid];
let meta = [llvm::LLVMValueAsMetadata(cx.const_usize(0)), typeid];
llvm::LLVMRustGlobalAddMetadata(
vtable,
llvm::MD_type as c_uint,
llvm::LLVMValueAsMetadata(llvm::LLVMMDNodeInContext(
cx.llcx,
v.as_ptr(),
v.len() as c_uint,
)),
llvm::LLVMMDNodeInContext2(cx.llcx, meta.as_ptr(), meta.len()),
);
let vcall_visibility = llvm::LLVMValueAsMetadata(cx.const_u64(vcall_visibility as u64));
let vcall_visibility_metadata = llvm::LLVMMDNodeInContext2(cx.llcx, &vcall_visibility, 1);
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,6 @@ unsafe extern "C" {
pub fn LLVMGetPoison(Ty: &Type) -> &Value;

// Operations on metadata
// FIXME: deprecated, replace with LLVMMDStringInContext2
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;

pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;

// FIXME: deprecated, replace with LLVMMDNodeInContext2
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_llvm/src/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ impl<'ll, 'tcx> TypeMembershipMethods<'tcx> for CodegenCx<'ll, 'tcx> {

fn typeid_metadata(&self, typeid: String) -> Option<&'ll Value> {
Some(unsafe {
llvm::LLVMMDStringInContext(
let meta = llvm::LLVMMDStringInContext2(
self.llcx,
typeid.as_ptr() as *const c_char,
typeid.len() as c_uint,
)
typeid.len(),
);
llvm::LLVMMetadataAsValue(self.llcx, meta)
})
}

Expand Down

0 comments on commit 5da0745

Please sign in to comment.