Skip to content

Commit c0bc001

Browse files
committed
review
1 parent f41e711 commit c0bc001

File tree

4 files changed

+16
-31
lines changed

4 files changed

+16
-31
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::type_::Type;
77
use crate::type_of::LayoutLlvmExt;
88
use crate::value::Value;
99
use cstr::cstr;
10-
use libc::c_uint;
1110
use rustc_codegen_ssa::traits::*;
1211
use rustc_hir::def_id::DefId;
1312
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
@@ -486,10 +485,10 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
486485
// go into custom sections of the wasm executable.
487486
if self.tcx.sess.target.is_like_wasm {
488487
if let Some(section) = attrs.link_section {
489-
let section = llvm::LLVMMDStringInContext(
488+
let section = llvm::LLVMMDStringInContext2(
490489
self.llcx,
491490
section.as_str().as_ptr().cast(),
492-
section.as_str().len() as c_uint,
491+
section.as_str().len(),
493492
);
494493
assert!(alloc.provenance().ptrs().is_empty());
495494

@@ -498,17 +497,15 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
498497
// as part of the interpreter execution).
499498
let bytes =
500499
alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len());
501-
let alloc = llvm::LLVMMDStringInContext(
502-
self.llcx,
503-
bytes.as_ptr().cast(),
504-
bytes.len() as c_uint,
505-
);
500+
let alloc =
501+
llvm::LLVMMDStringInContext2(self.llcx, bytes.as_ptr().cast(), bytes.len());
506502
let data = [section, alloc];
507-
let meta = llvm::LLVMMDNodeInContext(self.llcx, data.as_ptr(), 2);
503+
let meta = llvm::LLVMMDNodeInContext2(self.llcx, data.as_ptr(), data.len());
504+
let val = llvm::LLVMMetadataAsValue(self.llcx, meta);
508505
llvm::LLVMAddNamedMetadataOperand(
509506
self.llmod,
510507
"wasm.custom_sections\0".as_ptr().cast(),
511-
meta,
508+
val,
512509
);
513510
}
514511
} else {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -881,29 +881,24 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
881881
);
882882

883883
if tcx.sess.opts.unstable_opts.profile {
884-
let cu_desc_metadata =
885-
llvm::LLVMMetadataAsValue(debug_context.llcontext, unit_metadata);
886884
let default_gcda_path = &output_filenames.with_extension("gcda");
887885
let gcda_path =
888886
tcx.sess.opts.unstable_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);
889887

890888
let gcov_cu_info = [
891889
path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")),
892890
path_to_mdstring(debug_context.llcontext, gcda_path),
893-
cu_desc_metadata,
891+
unit_metadata,
894892
];
895-
let gcov_metadata = llvm::LLVMMDNodeInContext(
893+
let gcov_metadata = llvm::LLVMMDNodeInContext2(
896894
debug_context.llcontext,
897895
gcov_cu_info.as_ptr(),
898-
gcov_cu_info.len() as c_uint,
896+
gcov_cu_info.len(),
899897
);
898+
let val = llvm::LLVMMetadataAsValue(debug_context.llcontext, gcov_metadata);
900899

901900
let llvm_gcov_ident = cstr!("llvm.gcov");
902-
llvm::LLVMAddNamedMetadataOperand(
903-
debug_context.llmod,
904-
llvm_gcov_ident.as_ptr(),
905-
gcov_metadata,
906-
);
901+
llvm::LLVMAddNamedMetadataOperand(debug_context.llmod, llvm_gcov_ident.as_ptr(), val);
907902
}
908903

909904
// Insert `llvm.ident` metadata on the wasm targets since that will
@@ -924,15 +919,9 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
924919
return unit_metadata;
925920
};
926921

927-
fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll Value {
922+
fn path_to_mdstring<'ll>(llcx: &'ll llvm::Context, path: &Path) -> &'ll llvm::Metadata {
928923
let path_str = path_to_c_string(path);
929-
unsafe {
930-
llvm::LLVMMDStringInContext(
931-
llcx,
932-
path_str.as_ptr(),
933-
path_str.as_bytes().len() as c_uint,
934-
)
935-
}
924+
unsafe { llvm::LLVMMDStringInContext2(llcx, path_str.as_ptr(), path_str.as_bytes().len()) }
936925
}
937926
}
938927

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,6 @@ extern "C" {
10751075
// FIXME: deprecated, replace with LLVMMDStringInContext2
10761076
pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
10771077

1078-
// LLVMMDStringInContext but don't own string
10791078
pub fn LLVMMDStringInContext2(C: &Context, Str: *const c_char, SLen: size_t) -> &Metadata;
10801079

10811080
// FIXME: deprecated, replace with LLVMMDNodeInContext2
@@ -1117,7 +1116,7 @@ extern "C" {
11171116
Packed: Bool,
11181117
) -> &'a Value;
11191118

1120-
// FIXME: replace with LLVMConstArray2
1119+
// FIXME: replace with LLVMConstArray2 when bumped minimal version to llvm-17
11211120
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
11221121
pub fn LLVMConstArray<'a>(
11231122
ElementTy: &'a Type,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ extern "C" void LLVMRustWriteValueToString(LLVMValueRef V,
11371137
}
11381138

11391139
// LLVMArrayType function does not support 64-bit ElementCount
1140-
// FIXME: replace with LLVMArrayType2
1140+
// FIXME: replace with LLVMArrayType2 when bumped minimal version to llvm-17
11411141
// https://github.com/llvm/llvm-project/commit/35276f16e5a2cae0dfb49c0fbf874d4d2f177acc
11421142
extern "C" LLVMTypeRef LLVMRustArrayType(LLVMTypeRef ElementTy,
11431143
uint64_t ElementCount) {

0 commit comments

Comments
 (0)