Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 18 additions & 11 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::debuginfo::metadata::{
file_metadata_from_def_id, type_di_node, unknown_file_metadata,
};
use crate::debuginfo::utils::{DIB, create_DIArray, get_namespace_for_item};
use crate::llvm;
use crate::llvm::debuginfo::{DIFlags, DIType};
use crate::llvm::{self, ToLlvmBool};

mod cpp_like;
mod native;
Expand Down Expand Up @@ -111,16 +111,23 @@ fn build_enumeration_type_di_node<'ll, 'tcx>(
let (size, align) = cx.size_and_align_of(base_type);

let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = enumerators
.map(|(name, value)| unsafe {
let value = [value as u64, (value >> 64) as u64];
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
DIB(cx),
name.as_c_char_ptr(),
name.len(),
value.as_ptr(),
size.bits() as libc::c_uint,
is_unsigned,
))
.map(|(name, value)| {
let value_words = [value as u64, (value >> 64) as u64];
let size_in_bits = size.bits();
// LLVM computes `NumWords = (SizeInBits + 63) / 64`.
assert!((size_in_bits + 63) / 64 <= value_words.len() as u64);

let enumerator = unsafe {
llvm::LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
DIB(cx),
name.as_ptr(),
name.len(),
size_in_bits,
value_words.as_ptr(),
is_unsigned.to_llvm_bool(),
)
};
Some(enumerator)
})
.collect();

Expand Down
24 changes: 11 additions & 13 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t};

use super::RustString;
use super::debuginfo::{
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DILocation,
DISPFlags, DIScope, DISubprogram, DITemplateTypeParameter, DIType, DebugEmissionKind,
DebugNameTableKind,
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIFile, DIFlags, DILocation, DISPFlags,
DIScope, DISubprogram, DITemplateTypeParameter, DIType, DebugEmissionKind, DebugNameTableKind,
};
use crate::llvm::MetadataKindId;
use crate::{TryFromU32, llvm};
Expand Down Expand Up @@ -752,7 +751,6 @@ pub(crate) mod debuginfo {
pub(crate) type DICompositeType = DIDerivedType;
pub(crate) type DIVariable = DIDescriptor;
pub(crate) type DIArray = DIDescriptor;
pub(crate) type DIEnumerator = DIDescriptor;
pub(crate) type DITemplateTypeParameter = DIDescriptor;

bitflags! {
Expand Down Expand Up @@ -1794,6 +1792,15 @@ unsafe extern "C" {
Flags: DIFlags, // (default is `DIFlags::DIFlagZero`)
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision<'ll>(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark:

21.x:

https://github.com/llvm/llvm-project/blob/2078da43e25a4623cab2d0d60decddf709aaea28/llvm/include/llvm-c/DebugInfo.h#L621-L632

LLVM_C_ABI LLVMMetadataRef LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
    LLVMDIBuilderRef Builder, const char *Name, size_t NameLen,
    uint64_t SizeInBits, const uint64_t Words[], LLVMBool IsUnsigned);

main:

https://github.com/llvm/llvm-project/blob/1235c442a3c08e9cb4a9d2a6c082f392ec0885f1/llvm/include/llvm-c/DebugInfo.h#L654-L656

LLVM_C_ABI LLVMMetadataRef LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision(
    LLVMDIBuilderRef Builder, const char *Name, size_t NameLen,
    uint64_t SizeInBits, const uint64_t Words[], LLVMBool IsUnsigned);

Builder: &DIBuilder<'ll>,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
SizeInBits: u64,
Words: *const u64, // LLVM computes `NumWords = (SizeInBits + 63) / 64`.
IsUnsigned: llvm::Bool,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateUnionType<'ll>(
Builder: &DIBuilder<'ll>,
Scope: Option<&'ll Metadata>,
Expand Down Expand Up @@ -2286,15 +2293,6 @@ unsafe extern "C" {
Ty: &'a DIType,
) -> &'a DIType;

pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>(
Builder: &DIBuilder<'a>,
Name: *const c_char,
NameLen: size_t,
Value: *const u64,
SizeInBits: c_uint,
IsUnsigned: bool,
) -> &'a DIEnumerator;

pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,15 +1198,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantMemberType(
fromRust(Flags), unwrapDI<DIType>(Ty)));
}

extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name,
size_t NameLen, const uint64_t Value[2],
unsigned SizeInBits, bool IsUnsigned) {
return wrap(unwrap(Builder)->createEnumerator(
StringRef(Name, NameLen),
APSInt(APInt(SizeInBits, ArrayRef<uint64_t>(Value, 2)), IsUnsigned)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
Expand Down