Skip to content

Commit 23e4b3a

Browse files
committed
Use LLVMDIBuilderCreateSubroutineType
1 parent 5958825 commit 23e4b3a

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//! Safe wrappers for [`DIBuilder`] FFI functions.
2+
3+
use libc::c_uint;
4+
5+
use crate::llvm::debuginfo::{DIBuilder, DIFlags};
6+
use crate::llvm::{self, Metadata};
7+
8+
impl<'ll> DIBuilder<'ll> {
9+
pub(crate) fn create_subroutine_type(
10+
&self,
11+
parameter_types: &[Option<&'ll Metadata>],
12+
flags: DIFlags,
13+
) -> &'ll Metadata {
14+
unsafe {
15+
llvm::LLVMDIBuilderCreateSubroutineType(
16+
self,
17+
None, // ("File"; unused)
18+
parameter_types.as_ptr(),
19+
parameter_types.len() as c_uint,
20+
flags,
21+
)
22+
}
23+
}
24+
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
309309

310310
debug_context(cx).type_map.unique_id_to_di_node.borrow_mut().remove(&unique_type_id);
311311

312-
let fn_di_node = unsafe {
313-
llvm::LLVMRustDIBuilderCreateSubroutineType(
314-
DIB(cx),
315-
create_DIArray(DIB(cx), &signature_di_nodes[..]),
316-
)
317-
};
312+
let fn_di_node = DIB(cx).create_subroutine_type(&signature_di_nodes, DIFlags::FlagZero);
318313

319314
// This is actually a function pointer, so wrap it in pointer DI.
320315
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use crate::llvm::debuginfo::{
4040
use crate::value::Value;
4141

4242
mod create_scope_map;
43+
mod di_builder;
4344
mod dwarf_const;
4445
mod gdb;
4546
pub(crate) mod metadata;
@@ -321,9 +322,9 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
321322
let loc = self.lookup_debug_loc(span.lo());
322323
let file_metadata = file_metadata(self, &loc.file);
323324

324-
let function_type_metadata = unsafe {
325+
let function_type_metadata = {
325326
let fn_signature = get_function_signature(self, fn_abi);
326-
llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), fn_signature)
327+
DIB(self).create_subroutine_type(&fn_signature, DIFlags::FlagZero)
327328
};
328329

329330
let mut name = String::with_capacity(64);
@@ -416,9 +417,9 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
416417
fn get_function_signature<'ll, 'tcx>(
417418
cx: &CodegenCx<'ll, 'tcx>,
418419
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
419-
) -> &'ll DIArray {
420+
) -> Vec<Option<&'ll llvm::Metadata>> {
420421
if cx.sess().opts.debuginfo != DebugInfo::Full {
421-
return create_DIArray(DIB(cx), &[]);
422+
return vec![];
422423
}
423424

424425
let mut signature = Vec::with_capacity(fn_abi.args.len() + 1);
@@ -459,7 +460,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
459460
.extend(fn_abi.args.iter().map(|arg| Some(type_di_node(cx, arg.layout.ty))));
460461
}
461462

462-
create_DIArray(DIB(cx), &signature[..])
463+
signature
463464
}
464465

465466
fn get_template_parameters<'ll, 'tcx>(

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,14 @@ unsafe extern "C" {
17671767
Scope: &'ll Metadata,
17681768
InlinedAt: Option<&'ll Metadata>,
17691769
) -> &'ll Metadata;
1770+
1771+
pub(crate) fn LLVMDIBuilderCreateSubroutineType<'ll>(
1772+
Builder: &DIBuilder<'ll>,
1773+
File: Option<&'ll Metadata>, // (unused)
1774+
ParameterTypes: *const Option<&'ll Metadata>,
1775+
NumParameterTypes: c_uint,
1776+
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
1777+
) -> &'ll Metadata;
17701778
}
17711779

17721780
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2066,11 +2074,6 @@ unsafe extern "C" {
20662074
SourceLen: size_t,
20672075
) -> &'a DIFile;
20682076

2069-
pub fn LLVMRustDIBuilderCreateSubroutineType<'a>(
2070-
Builder: &DIBuilder<'a>,
2071-
ParameterTypes: &'a DIArray,
2072-
) -> &'a DICompositeType;
2073-
20742077
pub fn LLVMRustDIBuilderCreateFunction<'a>(
20752078
Builder: &DIBuilder<'a>,
20762079
Scope: &'a DIDescriptor,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -1036,13 +1036,6 @@ LLVMRustDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
10361036
CSInfo, oSource));
10371037
}
10381038

1039-
extern "C" LLVMMetadataRef
1040-
LLVMRustDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder,
1041-
LLVMMetadataRef ParameterTypes) {
1042-
return wrap(unwrap(Builder)->createSubroutineType(
1043-
DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
1044-
}
1045-
10461039
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
10471040
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
10481041
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,

0 commit comments

Comments
 (0)