Skip to content

Commit eef70a9

Browse files
committed
Create a safe wrapper around LLVMRustDIBuilderCreateTemplateTypeParameter
1 parent f7b4354 commit eef70a9

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -1297,16 +1297,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
12971297
kind.as_type().map(|ty| {
12981298
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
12991299
let actual_type_di_node = type_di_node(cx, actual_type);
1300-
let name = name.as_str();
1301-
unsafe {
1302-
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
1303-
DIB(cx),
1304-
None,
1305-
name.as_c_char_ptr(),
1306-
name.len(),
1307-
actual_type_di_node,
1308-
)
1309-
}
1300+
cx.create_template_type_parameter(name.as_str(), actual_type_di_node)
13101301
})
13111302
})
13121303
.collect();

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use crate::builder::Builder;
3434
use crate::common::{AsCCharPtr, CodegenCx};
3535
use crate::llvm;
3636
use crate::llvm::debuginfo::{
37-
DIArray, DIBuilderBox, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope, DIType,
38-
DIVariable,
37+
DIArray, DIBuilderBox, DIFile, DIFlags, DILexicalBlock, DILocation, DISPFlags, DIScope,
38+
DITemplateTypeParameter, DIType, DIVariable,
3939
};
4040
use crate::value::Value;
4141

@@ -251,7 +251,7 @@ struct DebugLoc {
251251
col: u32,
252252
}
253253

254-
impl CodegenCx<'_, '_> {
254+
impl<'ll> CodegenCx<'ll, '_> {
255255
/// Looks up debug source information about a `BytePos`.
256256
// FIXME(eddyb) rename this to better indicate it's a duplicate of
257257
// `lookup_char_pos` rather than `dbg_loc`, perhaps by making
@@ -279,6 +279,22 @@ impl CodegenCx<'_, '_> {
279279
DebugLoc { file, line, col }
280280
}
281281
}
282+
283+
fn create_template_type_parameter(
284+
&self,
285+
name: &str,
286+
actual_type_metadata: &'ll DIType,
287+
) -> &'ll DITemplateTypeParameter {
288+
unsafe {
289+
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
290+
DIB(self),
291+
None,
292+
name.as_c_char_ptr(),
293+
name.len(),
294+
actual_type_metadata,
295+
)
296+
}
297+
}
282298
}
283299

284300
impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
@@ -483,16 +499,10 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
483499
kind.as_type().map(|ty| {
484500
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
485501
let actual_type_metadata = type_di_node(cx, actual_type);
486-
let name = name.as_str();
487-
unsafe {
488-
Some(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
489-
DIB(cx),
490-
None,
491-
name.as_c_char_ptr(),
492-
name.len(),
493-
actual_type_metadata,
494-
))
495-
}
502+
Some(cx.create_template_type_parameter(
503+
name.as_str(),
504+
actual_type_metadata,
505+
))
496506
})
497507
})
498508
.collect()

0 commit comments

Comments
 (0)