Skip to content

Commit e19e4e3

Browse files
committed
Create a safe wrapper around LLVMRustDIBuilderCreateSubroutineType
1 parent 6adc2c1 commit e19e4e3

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use crate::debuginfo::metadata::type_map::build_type_with_children;
3838
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
3939
use crate::llvm;
4040
use crate::llvm::debuginfo::{
41-
DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind,
42-
DebugNameTableKind,
41+
DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType,
42+
DebugEmissionKind, DebugNameTableKind,
4343
};
4444
use crate::value::Value;
4545

@@ -312,12 +312,7 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
312312

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

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

322317
// This is actually a function pointer, so wrap it in pointer DI.
323318
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
@@ -341,6 +336,13 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
341336
DINodeCreationResult::new(di_node, false)
342337
}
343338

339+
pub(super) fn create_subroutine_type<'ll>(
340+
cx: &CodegenCx<'ll, '_>,
341+
signature: &'ll DICompositeType,
342+
) -> &'ll DICompositeType {
343+
unsafe { llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(cx), signature) }
344+
}
345+
344346
/// Create debuginfo for `dyn SomeTrait` types. Currently these are empty structs
345347
/// we with the correct type name (e.g. "dyn SomeTrait<Foo, Item=u32> + Sync").
346348
fn build_dyn_type_di_node<'ll, 'tcx>(

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::ptr;
66
use std::sync::Arc;
77

88
use libc::c_uint;
9+
use metadata::create_subroutine_type;
910
use rustc_abi::Size;
1011
use rustc_codegen_ssa::debuginfo::type_names;
1112
use rustc_codegen_ssa::mir::debuginfo::VariableKind::*;
@@ -341,10 +342,8 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
341342
let loc = self.lookup_debug_loc(span.lo());
342343
let file_metadata = file_metadata(self, &loc.file);
343344

344-
let function_type_metadata = unsafe {
345-
let fn_signature = get_function_signature(self, fn_abi);
346-
llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(self), fn_signature)
347-
};
345+
let function_type_metadata =
346+
create_subroutine_type(self, get_function_signature(self, fn_abi));
348347

349348
let mut name = String::with_capacity(64);
350349
type_names::push_item_name(tcx, def_id, false, &mut name);

0 commit comments

Comments
 (0)