Skip to content

Commit 778704f

Browse files
committed
Use LLVMDIBuilderCreateSubroutineType
1 parent 905b1bf commit 778704f

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed
Lines changed: 24 additions & 0 deletions
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

Lines changed: 1 addition & 6 deletions
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

Lines changed: 6 additions & 5 deletions
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;
@@ -325,9 +326,9 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
325326
let loc = self.lookup_debug_loc(span.lo());
326327
let file_metadata = file_metadata(self, &loc.file);
327328

328-
let function_type_metadata = unsafe {
329+
let function_type_metadata = {
329330
let fn_signature = get_function_signature(self, fn_abi);
330-
llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), fn_signature)
331+
DIB(self).create_subroutine_type(&fn_signature, DIFlags::FlagZero)
331332
};
332333

333334
let mut name = String::with_capacity(64);
@@ -420,9 +421,9 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
420421
fn get_function_signature<'ll, 'tcx>(
421422
cx: &CodegenCx<'ll, 'tcx>,
422423
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
423-
) -> &'ll DIArray {
424+
) -> Vec<Option<&'ll llvm::Metadata>> {
424425
if cx.sess().opts.debuginfo != DebugInfo::Full {
425-
return create_DIArray(DIB(cx), &[]);
426+
return vec![];
426427
}
427428

428429
let mut signature = Vec::with_capacity(fn_abi.args.len() + 1);
@@ -463,7 +464,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
463464
.extend(fn_abi.args.iter().map(|arg| Some(type_di_node(cx, arg.layout.ty))));
464465
}
465466

466-
create_DIArray(DIB(cx), &signature[..])
467+
signature
467468
}
468469

469470
fn get_template_parameters<'ll, 'tcx>(

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,14 @@ unsafe extern "C" {
17701770
Scope: &'ll Metadata,
17711771
InlinedAt: Option<&'ll Metadata>,
17721772
) -> &'ll Metadata;
1773+
1774+
pub(crate) fn LLVMDIBuilderCreateSubroutineType<'ll>(
1775+
Builder: &DIBuilder<'ll>,
1776+
File: Option<&'ll Metadata>, // (unused)
1777+
ParameterTypes: *const Option<&'ll Metadata>,
1778+
NumParameterTypes: c_uint,
1779+
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
1780+
) -> &'ll Metadata;
17731781
}
17741782

17751783
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2083,11 +2091,6 @@ unsafe extern "C" {
20832091
SourceLen: size_t,
20842092
) -> &'a DIFile;
20852093

2086-
pub(crate) fn LLVMRustDIBuilderCreateSubroutineType<'a>(
2087-
Builder: &DIBuilder<'a>,
2088-
ParameterTypes: &'a DIArray,
2089-
) -> &'a DICompositeType;
2090-
20912094
pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>(
20922095
Builder: &DIBuilder<'a>,
20932096
Scope: &'a DIDescriptor,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,13 +1009,6 @@ LLVMRustDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
10091009
CSInfo, oSource));
10101010
}
10111011

1012-
extern "C" LLVMMetadataRef
1013-
LLVMRustDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder,
1014-
LLVMMetadataRef ParameterTypes) {
1015-
return wrap(unwrap(Builder)->createSubroutineType(
1016-
DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
1017-
}
1018-
10191012
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction(
10201013
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
10211014
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,

0 commit comments

Comments
 (0)