Skip to content

Commit e39e5a0

Browse files
committed
Use LLVMDIBuilderCreate(Auto|Parameter)Variable
1 parent 9daa026 commit e39e5a0

File tree

3 files changed

+57
-62
lines changed

3 files changed

+57
-62
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ mod utils;
5252
use self::create_scope_map::compute_mir_scopes;
5353
pub(crate) use self::metadata::build_global_var_di_node;
5454

55-
// FIXME(Zalathar): These `DW_TAG_*` constants are fake values that were
56-
// removed from LLVM in 2015, and are only used by our own `RustWrapper.cpp`
57-
// to decide which C++ API to call. Instead, we should just have two separate
58-
// FFI functions and choose the correct one on the Rust side.
59-
#[allow(non_upper_case_globals)]
60-
const DW_TAG_auto_variable: c_uint = 0x100;
61-
#[allow(non_upper_case_globals)]
62-
const DW_TAG_arg_variable: c_uint = 0x101;
63-
6455
/// A context object for maintaining all state needed by the debuginfo module.
6556
pub(crate) struct CodegenUnitDebugContext<'ll, 'tcx> {
6657
llmod: &'ll llvm::Module,
@@ -633,28 +624,39 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
633624

634625
let type_metadata = spanned_type_di_node(self, variable_type, span);
635626

636-
let (argument_index, dwarf_tag) = match variable_kind {
637-
ArgumentVariable(index) => (index as c_uint, DW_TAG_arg_variable),
638-
LocalVariable => (0, DW_TAG_auto_variable),
639-
};
640627
let align = self.align_of(variable_type);
641628

642629
let name = variable_name.as_str();
643-
unsafe {
644-
llvm::LLVMRustDIBuilderCreateVariable(
645-
DIB(self),
646-
dwarf_tag,
647-
scope_metadata,
648-
name.as_c_char_ptr(),
649-
name.len(),
650-
file_metadata,
651-
loc.line,
652-
type_metadata,
653-
true,
654-
DIFlags::FlagZero,
655-
argument_index,
656-
align.bits() as u32,
657-
)
630+
631+
match variable_kind {
632+
ArgumentVariable(arg_index) => unsafe {
633+
llvm::LLVMDIBuilderCreateParameterVariable(
634+
DIB(self),
635+
scope_metadata,
636+
name.as_ptr(),
637+
name.len(),
638+
arg_index as c_uint,
639+
file_metadata,
640+
loc.line,
641+
type_metadata,
642+
llvm::Bool::TRUE, // (preserve descriptor during optimizations)
643+
DIFlags::FlagZero,
644+
)
645+
},
646+
LocalVariable => unsafe {
647+
llvm::LLVMDIBuilderCreateAutoVariable(
648+
DIB(self),
649+
scope_metadata,
650+
name.as_ptr(),
651+
name.len(),
652+
file_metadata,
653+
loc.line,
654+
type_metadata,
655+
llvm::Bool::TRUE, // (preserve descriptor during optimizations)
656+
DIFlags::FlagZero,
657+
align.bits() as u32,
658+
)
659+
},
658660
}
659661
}
660662
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use super::RustString;
2626
use super::debuginfo::{
2727
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
2828
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram,
29-
DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind,
29+
DITemplateTypeParameter, DIType, DebugEmissionKind, DebugNameTableKind,
3030
};
3131
use crate::llvm;
3232

@@ -2017,6 +2017,32 @@ unsafe extern "C" {
20172017
DebugLoc: &'ll Metadata,
20182018
Block: &'ll BasicBlock,
20192019
) -> &'ll DbgRecord;
2020+
2021+
pub(crate) fn LLVMDIBuilderCreateAutoVariable<'ll>(
2022+
Builder: &DIBuilder<'ll>,
2023+
Scope: &'ll Metadata,
2024+
Name: *const c_uchar, // See "PTR_LEN_STR".
2025+
NameLen: size_t,
2026+
File: &'ll Metadata,
2027+
LineNo: c_uint,
2028+
Ty: &'ll Metadata,
2029+
AlwaysPreserve: llvm::Bool, // "If true, this descriptor will survive optimizations."
2030+
Flags: DIFlags,
2031+
AlignInBits: u32,
2032+
) -> &'ll Metadata;
2033+
2034+
pub(crate) fn LLVMDIBuilderCreateParameterVariable<'ll>(
2035+
Builder: &DIBuilder<'ll>,
2036+
Scope: &'ll Metadata,
2037+
Name: *const c_uchar, // See "PTR_LEN_STR".
2038+
NameLen: size_t,
2039+
ArgNo: c_uint,
2040+
File: &'ll Metadata,
2041+
LineNo: c_uint,
2042+
Ty: &'ll Metadata,
2043+
AlwaysPreserve: llvm::Bool, // "If true, this descriptor will survive optimizations."
2044+
Flags: DIFlags,
2045+
) -> &'ll Metadata;
20202046
}
20212047

20222048
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2383,21 +2409,6 @@ unsafe extern "C" {
23832409
AlignInBits: u32,
23842410
) -> &'a DIGlobalVariableExpression;
23852411

2386-
pub(crate) fn LLVMRustDIBuilderCreateVariable<'a>(
2387-
Builder: &DIBuilder<'a>,
2388-
Tag: c_uint,
2389-
Scope: &'a DIDescriptor,
2390-
Name: *const c_char,
2391-
NameLen: size_t,
2392-
File: &'a DIFile,
2393-
LineNo: c_uint,
2394-
Ty: &'a DIType,
2395-
AlwaysPreserve: bool,
2396-
Flags: DIFlags,
2397-
ArgNo: c_uint,
2398-
AlignInBits: u32,
2399-
) -> &'a DIVariable;
2400-
24012412
pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>(
24022413
Builder: &DIBuilder<'a>,
24032414
Name: *const c_char,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,24 +1124,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
11241124
return wrap(VarExpr);
11251125
}
11261126

1127-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable(
1128-
LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Scope,
1129-
const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo,
1130-
LLVMMetadataRef Ty, bool AlwaysPreserve, LLVMDIFlags Flags, unsigned ArgNo,
1131-
uint32_t AlignInBits) {
1132-
if (Tag == 0x100) { // DW_TAG_auto_variable
1133-
return wrap(unwrap(Builder)->createAutoVariable(
1134-
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
1135-
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), AlwaysPreserve,
1136-
fromRust(Flags), AlignInBits));
1137-
} else {
1138-
return wrap(unwrap(Builder)->createParameterVariable(
1139-
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen), ArgNo,
1140-
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), AlwaysPreserve,
1141-
fromRust(Flags)));
1142-
}
1143-
}
1144-
11451127
extern "C" LLVMMetadataRef
11461128
LLVMRustDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name,
11471129
size_t NameLen, const uint64_t Value[2],

0 commit comments

Comments
 (0)