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
Prev Previous commit
Use LLVMDIBuilderCreateStructType
  • Loading branch information
Zalathar committed Sep 17, 2025
commit af88d14cac15dd47452ce670e65c1ed56dae9586
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_middle::bug;
use rustc_middle::ty::{self, ExistentialTraitRef, Ty, TyCtxt};

use super::{DefinitionLocation, SmallVec, UNKNOWN_LINE_NUMBER, unknown_file_metadata};
use crate::common::{AsCCharPtr, CodegenCx};
use crate::common::CodegenCx;
use crate::debuginfo::utils::{DIB, create_DIArray, debug_context};
use crate::llvm::debuginfo::{DIFlags, DIScope, DIType};
use crate::llvm::{self};
Expand Down Expand Up @@ -193,7 +193,6 @@ pub(super) fn stub<'ll, 'tcx>(
flags: DIFlags,
) -> StubInfo<'ll, 'tcx> {
let no_elements: &[Option<&llvm::Metadata>] = &[];
let empty_array = create_DIArray(DIB(cx), &[]);
let unique_type_id_str = unique_type_id.generate_unique_id_string(cx.tcx);

let (file_metadata, line_number) = if let Some(def_location) = def_location {
Expand All @@ -209,21 +208,22 @@ pub(super) fn stub<'ll, 'tcx>(
_ => None,
};
unsafe {
llvm::LLVMRustDIBuilderCreateStructType(
llvm::LLVMDIBuilderCreateStructType(
DIB(cx),
containing_scope,
name.as_c_char_ptr(),
name.as_ptr(),
name.len(),
file_metadata,
line_number,
size.bits(),
align.bits() as u32,
flags,
None,
empty_array,
0,
no_elements.as_ptr(),
no_elements.len() as c_uint,
0u32, // (Objective-C runtime version; default is 0)
vtable_holder,
unique_type_id_str.as_c_char_ptr(),
unique_type_id_str.as_ptr(),
unique_type_id_str.len(),
)
}
Expand Down
43 changes: 22 additions & 21 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use rustc_target::spec::SymbolVisibility;

use super::RustString;
use super::debuginfo::{
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
DIFile, DIFlags, DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram,
DISubrange, DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind,
DIArray, DIBasicType, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram, DISubrange,
DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind,
};
use crate::llvm;

Expand Down Expand Up @@ -1923,6 +1923,25 @@ unsafe extern "C" {
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
) -> &'ll Metadata;

pub(crate) fn LLVMDIBuilderCreateStructType<'ll>(
Builder: &DIBuilder<'ll>,
Scope: Option<&'ll Metadata>,
Name: *const c_uchar, // See "PTR_LEN_STR".
NameLen: size_t,
File: &'ll Metadata,
LineNumber: c_uint,
SizeInBits: u64,
AlignInBits: u32,
Flags: DIFlags,
DerivedFrom: Option<&'ll Metadata>,
Elements: *const Option<&'ll Metadata>,
NumElements: c_uint,
RunTimeLang: c_uint, // (optional Objective-C runtime version; default is 0)
VTableHolder: Option<&'ll Metadata>,
UniqueId: *const c_uchar, // See "PTR_LEN_STR".
UniqueIdLen: size_t,
) -> &'ll Metadata;
}

#[link(name = "llvm-wrapper", kind = "static")]
Expand Down Expand Up @@ -2268,24 +2287,6 @@ unsafe extern "C" {
Scope: Option<&'a DIScope>,
) -> &'a DIDerivedType;

pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>(
Builder: &DIBuilder<'a>,
Scope: Option<&'a DIDescriptor>,
Name: *const c_char,
NameLen: size_t,
File: &'a DIFile,
LineNumber: c_uint,
SizeInBits: u64,
AlignInBits: u32,
Flags: DIFlags,
DerivedFrom: Option<&'a DIType>,
Elements: &'a DIArray,
RunTimeLang: c_uint,
VTableHolder: Option<&'a DIType>,
UniqueId: *const c_char,
UniqueIdLen: size_t,
) -> &'a DICompositeType;

pub(crate) fn LLVMRustDIBuilderCreateMemberType<'a>(
Builder: &DIBuilder<'a>,
Scope: &'a DIDescriptor,
Expand Down
14 changes: 0 additions & 14 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,20 +1074,6 @@ LLVMRustDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
LineNo, unwrapDIPtr<DIScope>(Scope)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStructType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
LLVMMetadataRef DerivedFrom, LLVMMetadataRef Elements, unsigned RunTimeLang,
LLVMMetadataRef VTableHolder, const char *UniqueId, size_t UniqueIdLen) {
return wrap(unwrap(Builder)->createStructType(
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits,
fromRust(Flags), unwrapDI<DIType>(DerivedFrom),
DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang,
unwrapDI<DIType>(VTableHolder), StringRef(UniqueId, UniqueIdLen)));
}

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