Skip to content

Commit 1db7d41

Browse files
committed
Extract DIBuilderExt::create_static_variable
1 parent 45e9ebe commit 1db7d41

File tree

2 files changed

+64
-36
lines changed

2 files changed

+64
-36
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use libc::c_uint;
2+
use rustc_abi::Align;
3+
4+
use crate::common::AsCCharPtr;
15
use crate::llvm;
26
use crate::llvm::debuginfo::DIBuilder;
37

@@ -10,6 +14,41 @@ pub(crate) trait DIBuilderExt<'ll> {
1014
let this = self.as_di_builder();
1115
unsafe { llvm::LLVMDIBuilderCreateExpression(this, addr_ops.as_ptr(), addr_ops.len()) }
1216
}
17+
18+
fn create_static_variable(
19+
&self,
20+
scope: Option<&'ll llvm::Metadata>,
21+
name: &str,
22+
linkage_name: &str,
23+
file: &'ll llvm::Metadata,
24+
line_number: c_uint,
25+
ty: &'ll llvm::Metadata,
26+
is_local_to_unit: bool,
27+
val: &'ll llvm::Value,
28+
decl: Option<&'ll llvm::Metadata>,
29+
align: Option<Align>,
30+
) -> &'ll llvm::Metadata {
31+
let this = self.as_di_builder();
32+
let align_in_bits = align.map_or(0, |align| align.bits() as u32);
33+
34+
unsafe {
35+
llvm::LLVMRustDIBuilderCreateStaticVariable(
36+
this,
37+
scope,
38+
name.as_c_char_ptr(),
39+
name.len(),
40+
linkage_name.as_c_char_ptr(),
41+
linkage_name.len(),
42+
file,
43+
line_number,
44+
ty,
45+
is_local_to_unit,
46+
val,
47+
decl,
48+
align_in_bits,
49+
)
50+
}
51+
}
1352
}
1453

1554
impl<'ll> DIBuilderExt<'ll> for &DIBuilder<'ll> {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ use super::namespace::mangled_name_of_instance;
3434
use super::type_names::{compute_debuginfo_type_name, compute_debuginfo_vtable_name};
3535
use super::utils::{DIB, debug_context, get_namespace_for_item, is_node_local_to_unit};
3636
use crate::common::{AsCCharPtr, CodegenCx};
37-
use crate::debuginfo::dwarf_const;
3837
use crate::debuginfo::metadata::type_map::build_type_with_children;
3938
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
39+
use crate::debuginfo::{DIBuilderExt, dwarf_const};
4040
use crate::llvm::debuginfo::{
4141
DIBasicType, DIBuilder, DICompositeType, DIDescriptor, DIFile, DIFlags, DILexicalBlock,
4242
DIScope, DIType, DebugEmissionKind, DebugNameTableKind,
@@ -1410,23 +1410,18 @@ pub(crate) fn build_global_var_di_node<'ll>(
14101410

14111411
let global_align = cx.align_of(variable_type);
14121412

1413-
unsafe {
1414-
llvm::LLVMRustDIBuilderCreateStaticVariable(
1415-
DIB(cx),
1416-
Some(var_scope),
1417-
var_name.as_c_char_ptr(),
1418-
var_name.len(),
1419-
linkage_name.as_c_char_ptr(),
1420-
linkage_name.len(),
1421-
file_metadata,
1422-
line_number,
1423-
type_di_node,
1424-
is_local_to_unit,
1425-
global,
1426-
None,
1427-
global_align.bits() as u32,
1428-
);
1429-
}
1413+
DIB(cx).create_static_variable(
1414+
Some(var_scope),
1415+
var_name,
1416+
linkage_name,
1417+
file_metadata,
1418+
line_number,
1419+
type_di_node,
1420+
is_local_to_unit,
1421+
global, // (value)
1422+
None, // (decl)
1423+
Some(global_align),
1424+
);
14301425
}
14311426

14321427
/// Generates LLVM debuginfo for a vtable.
@@ -1643,25 +1638,19 @@ pub(crate) fn create_vtable_di_node<'ll, 'tcx>(
16431638
let vtable_name =
16441639
compute_debuginfo_vtable_name(cx.tcx, ty, poly_trait_ref, VTableNameKind::GlobalVariable);
16451640
let vtable_type_di_node = build_vtable_type_di_node(cx, ty, poly_trait_ref);
1646-
let linkage_name = "";
16471641

1648-
unsafe {
1649-
llvm::LLVMRustDIBuilderCreateStaticVariable(
1650-
DIB(cx),
1651-
NO_SCOPE_METADATA,
1652-
vtable_name.as_c_char_ptr(),
1653-
vtable_name.len(),
1654-
linkage_name.as_c_char_ptr(),
1655-
linkage_name.len(),
1656-
unknown_file_metadata(cx),
1657-
UNKNOWN_LINE_NUMBER,
1658-
vtable_type_di_node,
1659-
true,
1660-
vtable,
1661-
None,
1662-
0,
1663-
);
1664-
}
1642+
DIB(cx).create_static_variable(
1643+
NO_SCOPE_METADATA,
1644+
&vtable_name,
1645+
"", // (linkage_name)
1646+
unknown_file_metadata(cx),
1647+
UNKNOWN_LINE_NUMBER,
1648+
vtable_type_di_node,
1649+
true, // (is_local_to_unit)
1650+
vtable, // (value)
1651+
None, // (decl)
1652+
None::<Align>,
1653+
);
16651654
}
16661655

16671656
/// Creates an "extension" of an existing `DIScope` into another file.

0 commit comments

Comments
 (0)