Skip to content

Commit 1add0bc

Browse files
committed
Use LLVMDIBuilderCreateSubroutineType
1 parent f8a913b commit 1add0bc

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
@@ -311,12 +311,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
311311

312312
debug_context(cx).type_map.unique_id_to_di_node.borrow_mut().remove(&unique_type_id);
313313

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

321316
// This is actually a function pointer, so wrap it in pointer DI.
322317
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;
@@ -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

+8-5
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,14 @@ unsafe extern "C" {
17721772
Scope: &'ll Metadata,
17731773
InlinedAt: Option<&'ll Metadata>,
17741774
) -> &'ll Metadata;
1775+
1776+
pub(crate) fn LLVMDIBuilderCreateSubroutineType<'ll>(
1777+
Builder: &DIBuilder<'ll>,
1778+
File: Option<&'ll Metadata>, // (unused)
1779+
ParameterTypes: *const Option<&'ll Metadata>,
1780+
NumParameterTypes: c_uint,
1781+
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
1782+
) -> &'ll Metadata;
17751783
}
17761784

17771785
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2085,11 +2093,6 @@ unsafe extern "C" {
20852093
SourceLen: size_t,
20862094
) -> &'a DIFile;
20872095

2088-
pub(crate) fn LLVMRustDIBuilderCreateSubroutineType<'a>(
2089-
Builder: &DIBuilder<'a>,
2090-
ParameterTypes: &'a DIArray,
2091-
) -> &'a DICompositeType;
2092-
20932096
pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>(
20942097
Builder: &DIBuilder<'a>,
20952098
Scope: &'a DIDescriptor,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-7
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)