Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,15 @@ fn build_basic_type_di_node<'ll, 'tcx>(
};

let typedef_di_node = unsafe {
llvm::LLVMRustDIBuilderCreateTypedef(
llvm::LLVMDIBuilderCreateTypedef(
DIB(cx),
ty_di_node,
typedef_name.as_c_char_ptr(),
typedef_name.as_ptr(),
typedef_name.len(),
unknown_file_metadata(cx),
0,
None,
0, // (no line number)
None, // (no scope)
0u32, // (no alignment specified)
)
};

Expand Down Expand Up @@ -1034,10 +1035,10 @@ fn create_member_type<'ll, 'tcx>(
type_di_node: &'ll DIType,
) -> &'ll DIType {
unsafe {
llvm::LLVMRustDIBuilderCreateMemberType(
llvm::LLVMDIBuilderCreateMemberType(
DIB(cx),
owner,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
file_metadata,
line_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, AdtDef, CoroutineArgs, CoroutineArgsExt, Ty};
use smallvec::smallvec;

use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::dwarf_const::DW_TAG_const_type;
use crate::debuginfo::metadata::enums::DiscrResult;
use crate::debuginfo::metadata::type_map::{self, Stub, UniqueTypeId};
Expand Down Expand Up @@ -378,20 +378,17 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
variant_struct_type_wrapper_di_node,
None,
),
unsafe {
llvm::LLVMRustDIBuilderCreateStaticMemberType(
DIB(cx),
enum_type_di_node,
TAG_FIELD_NAME.as_c_char_ptr(),
TAG_FIELD_NAME.len(),
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
variant_names_type_di_node,
visibility_flags,
Some(cx.const_u64(SINGLE_VARIANT_VIRTUAL_DISR)),
tag_base_type_align.bits() as u32,
)
}
create_static_member_type(
cx,
enum_type_di_node,
TAG_FIELD_NAME,
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
variant_names_type_di_node,
visibility_flags,
Some(cx.const_u64(SINGLE_VARIANT_VIRTUAL_DISR)),
tag_base_type_align,
),
]
}

Expand Down Expand Up @@ -570,27 +567,28 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
let build_assoc_const = |name: &str,
type_di_node_: &'ll DIType,
value: u64,
align: Align| unsafe {
align: Align|
-> &'ll llvm::Metadata {
// FIXME: Currently we force all DISCR_* values to be u64's as LLDB seems to have
// problems inspecting other value types. Since DISCR_* is typically only going to be
// directly inspected via the debugger visualizer - which compares it to the `tag` value
// (whose type is not modified at all) it shouldn't cause any real problems.
let (t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
(type_di_node_, align.bits() as u32)
(type_di_node_, align)
} else {
let ty_u64 = Ty::new_uint(cx.tcx, ty::UintTy::U64);
(type_di_node(cx, ty_u64), Align::EIGHT.bits() as u32)
(type_di_node(cx, ty_u64), Align::EIGHT)
};

// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
let field_type =
llvm::LLVMRustDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di);
let field_type = unsafe {
llvm::LLVMDIBuilderCreateQualifiedType(DIB(cx), DW_TAG_const_type, t_di)
};

llvm::LLVMRustDIBuilderCreateStaticMemberType(
DIB(cx),
create_static_member_type(
cx,
wrapper_struct_type_di_node,
name.as_c_char_ptr(),
name.len(),
name,
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
field_type,
Expand Down Expand Up @@ -975,3 +973,30 @@ fn variant_struct_wrapper_type_name(variant_index: VariantIdx) -> Cow<'static, s
.map(|&s| Cow::from(s))
.unwrap_or_else(|| format!("Variant{}", variant_index.as_usize()).into())
}

fn create_static_member_type<'ll>(
cx: &CodegenCx<'ll, '_>,
scope: &'ll llvm::Metadata,
name: &str,
file: &'ll llvm::Metadata,
line_number: c_uint,
ty: &'ll llvm::Metadata,
flags: DIFlags,
value: Option<&'ll llvm::Value>,
align: Align,
) -> &'ll llvm::Metadata {
unsafe {
llvm::LLVMDIBuilderCreateStaticMemberType(
DIB(cx),
scope,
name.as_ptr(),
name.len(),
file,
line_number,
ty,
flags,
value,
align.bits() as c_uint,
)
}
}
91 changes: 47 additions & 44 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_target::spec::SymbolVisibility;

use super::RustString;
use super::debuginfo::{
DIArray, DIBasicType, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram, DISubrange,
DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind,
};
Expand Down Expand Up @@ -1943,6 +1943,52 @@ unsafe extern "C" {
UniqueId: *const c_uchar, // See "PTR_LEN_STR".
UniqueIdLen: size_t,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateMemberType<'ll>(
Builder: &DIBuilder<'ll>,
Scope: &'ll Metadata,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'ll Metadata,
LineNo: c_uint,
SizeInBits: u64,
AlignInBits: u32,
OffsetInBits: u64,
Flags: DIFlags,
Ty: &'ll Metadata,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateStaticMemberType<'ll>(
Builder: &DIBuilder<'ll>,
Scope: &'ll Metadata,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'ll Metadata,
LineNumber: c_uint,
Type: &'ll Metadata,
Flags: DIFlags,
ConstantVal: Option<&'ll Value>,
AlignInBits: u32,
) -> &'ll Metadata;

/// Creates a "qualified type" in the C/C++ sense, by adding modifiers
/// like `const` or `volatile`.
pub(crate) fn LLVMDIBuilderCreateQualifiedType<'ll>(
Builder: &DIBuilder<'ll>,
Tag: c_uint, // (DWARF tag, e.g. `DW_TAG_const_type`)
Type: &'ll Metadata,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateTypedef<'ll>(
Builder: &DIBuilder<'ll>,
Type: &'ll Metadata,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'ll Metadata,
LineNo: c_uint,
Scope: Option<&'ll Metadata>,
AlignInBits: u32, // (optional; default is 0)
) -> &'ll Metadata;
}

#[link(name = "llvm-wrapper", kind = "static")]
Expand Down Expand Up @@ -2278,30 +2324,6 @@ unsafe extern "C" {
TParam: &'a DIArray,
) -> &'a DISubprogram;

pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>(
Builder: &DIBuilder<'a>,
Type: &'a DIBasicType,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Scope: Option<&'a DIScope>,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
SizeInBits: u64,
AlignInBits: u32,
OffsetInBits: u64,
Flags: DIFlags,
Ty: &'a DIType,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Expand All @@ -2317,25 +2339,6 @@ unsafe extern "C" {
Ty: &'a DIType,
) -> &'a DIType;

pub(crate) fn LLVMRustDIBuilderCreateStaticMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
LineNo: c_uint,
Ty: &'a DIType,
Flags: DIFlags,
val: Option<&'a Value>,
AlignInBits: u32,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>(
Builder: &DIBuilder<'a>,
Tag: c_uint,
Type: &'a DIType,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>(
Builder: &DIBuilder<'a>,
Context: Option<&'a DIScope>,
Expand Down
38 changes: 0 additions & 38 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,16 +1064,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMethod(
return wrap(Sub);
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
const char *Name, size_t NameLen,
LLVMMetadataRef File, unsigned LineNo,
LLVMMetadataRef Scope) {
return wrap(unwrap(Builder)->createTypedef(
unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File),
LineNo, unwrapDIPtr<DIScope>(Scope)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
Expand All @@ -1088,17 +1078,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart(
StringRef(UniqueId, UniqueIdLen)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMemberType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
LLVMMetadataRef Ty) {
return wrap(unwrap(Builder)->createMemberType(
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits, OffsetInBits,
fromRust(Flags), unwrapDI<DIType>(Ty)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
Expand All @@ -1114,23 +1093,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
fromRust(Flags), unwrapDI<DIType>(Ty)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
LLVMDIFlags Flags, LLVMValueRef val, uint32_t AlignInBits) {
return wrap(unwrap(Builder)->createStaticMemberType(
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), fromRust(Flags),
unwrap<llvm::ConstantInt>(val), llvm::dwarf::DW_TAG_member, AlignInBits));
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
LLVMMetadataRef Type) {
return wrap(
unwrap(Builder)->createQualifiedType(Tag, unwrapDI<DIType>(Type)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable(
LLVMDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name,
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
Expand Down
Loading