Skip to content
Open
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
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
43 changes: 30 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 @@ -740,7 +739,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 @@ -1782,6 +1780,15 @@ unsafe extern "C" {
Flags: DIFlags, // (default is `DIFlags::DIFlagZero`)
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateEnumeratorOfArbitraryPrecision<'ll>(
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 @@ -2196,6 +2203,9 @@ unsafe extern "C" {
ValueLen: size_t,
);

/// We can't use LLVM-C's `LLVMDIBuilderCreateCompileUnit` because it hardcodes
/// `DICompileUnit::DebugNameTableKind::Default`, but we want to be able to
/// pass other values.
pub(crate) fn LLVMRustDIBuilderCreateCompileUnit<'a>(
Builder: &DIBuilder<'a>,
Lang: c_uint,
Expand All @@ -2213,6 +2223,8 @@ unsafe extern "C" {
DebugNameTableKind: DebugNameTableKind,
) -> &'a DIDescriptor;

/// We can't use LLVM-C's `LLVMDIBuilderCreateFileWithChecksum` because it
/// _requires_ a checksum, but we sometimes don't provide one.
pub(crate) fn LLVMRustDIBuilderCreateFile<'a>(
Builder: &DIBuilder<'a>,
Filename: *const c_char,
Expand All @@ -2226,6 +2238,8 @@ unsafe extern "C" {
SourceLen: size_t,
) -> &'a DIFile;

/// We can't use LLVM-C's `LLVMDIBuilderCreateFunction` because it only
/// supports a subset of `DISubprogram::DISPFlags`.
pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Expand All @@ -2244,6 +2258,7 @@ unsafe extern "C" {
Decl: Option<&'a DIDescriptor>,
) -> &'a DISubprogram;

/// As of LLVM 22 there is no corresponding LLVM-C function.
pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Expand All @@ -2259,6 +2274,7 @@ unsafe extern "C" {
TParam: &'a DIArray,
) -> &'a DISubprogram;

/// As of LLVM 22 there is no corresponding LLVM-C function.
pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Expand All @@ -2274,15 +2290,7 @@ 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;

/// As of LLVM 22 there is no corresponding LLVM-C function.
pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Expand All @@ -2297,6 +2305,7 @@ unsafe extern "C" {
IsScoped: bool,
) -> &'a DIType;

/// As of LLVM 22 there is no corresponding LLVM-C function.
pub(crate) fn LLVMRustDIBuilderCreateVariantPart<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIScope,
Expand All @@ -2313,6 +2322,7 @@ unsafe extern "C" {
UniqueIdLen: size_t,
) -> &'a DIDerivedType;

/// As of LLVM 22 there is no corresponding LLVM-C function.
pub(crate) fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
Builder: &DIBuilder<'a>,
Scope: Option<&'a DIScope>,
Expand All @@ -2321,13 +2331,17 @@ unsafe extern "C" {
Ty: &'a DIType,
) -> &'a DITemplateTypeParameter;

/// We can't use LLVM-C's `LLVMReplaceArrays` because it doesn't take a
/// `Params` argument.
pub(crate) fn LLVMRustDICompositeTypeReplaceArrays<'a>(
Builder: &DIBuilder<'a>,
CompositeType: &'a DIType,
Elements: Option<&'a DIArray>,
Params: Option<&'a DIArray>,
);

/// We can't use LLVM-C's `LLVMDIBuilderGetOrCreateSubrange` because it doesn't
/// call the overload that takes a `Metadata` upper bound.
pub(crate) fn LLVMRustDIGetOrCreateSubrange<'a>(
Builder: &DIBuilder<'a>,
CountNode: Option<&'a Metadata>,
Expand All @@ -2336,6 +2350,8 @@ unsafe extern "C" {
Stride: Option<&'a Metadata>,
) -> &'a Metadata;

/// We can't use LLVM-C's `LLVMDIBuilderCreateVectorType` because it doesn't
/// take a `BitStride` argument.
pub(crate) fn LLVMRustDICreateVectorType<'a>(
Builder: &DIBuilder<'a>,
Size: u64,
Expand All @@ -2345,6 +2361,7 @@ unsafe extern "C" {
BitStride: Option<&'a Metadata>,
) -> &'a Metadata;

/// As of LLVM 22 there is no corresponding LLVM-C function.
pub(crate) fn LLVMRustDILocationCloneWithBaseDiscriminator<'a>(
Location: &'a DILocation,
BD: c_uint,
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
Loading