Skip to content

Commit 43f9d09

Browse files
committed
Use LLVMDIBuilderCreateUnionType
1 parent 23e4b3a commit 43f9d09

File tree

4 files changed

+61
-46
lines changed

4 files changed

+61
-46
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs

+33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Safe wrappers for [`DIBuilder`] FFI functions.
22
33
use libc::c_uint;
4+
use rustc_abi::{Align, Size};
45

56
use crate::llvm::debuginfo::{DIBuilder, DIFlags};
67
use crate::llvm::{self, Metadata};
@@ -21,4 +22,36 @@ impl<'ll> DIBuilder<'ll> {
2122
)
2223
}
2324
}
25+
26+
pub(crate) fn create_union_type(
27+
&self,
28+
scope: Option<&'ll Metadata>,
29+
name: &str,
30+
file_metadata: &'ll Metadata,
31+
line_number: c_uint,
32+
size: Size,
33+
align: Align,
34+
flags: DIFlags,
35+
elements: &[&'ll Metadata],
36+
unique_id: &str,
37+
) -> &'ll Metadata {
38+
unsafe {
39+
llvm::LLVMDIBuilderCreateUnionType(
40+
self,
41+
scope,
42+
name.as_ptr(),
43+
name.len(),
44+
file_metadata,
45+
line_number,
46+
size.bits(),
47+
align.bits() as u32,
48+
flags,
49+
elements.as_ptr(),
50+
elements.len() as c_uint,
51+
0, // ("Objective-C runtime version"; default is 0)
52+
unique_id.as_ptr(),
53+
unique_id.len(),
54+
)
55+
}
56+
}
2457
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,17 @@ pub(super) fn stub<'ll, 'tcx>(
226226
)
227227
}
228228
}
229-
Stub::Union => unsafe {
230-
llvm::LLVMRustDIBuilderCreateUnionType(
231-
DIB(cx),
232-
containing_scope,
233-
name.as_c_char_ptr(),
234-
name.len(),
235-
file_metadata,
236-
line_number,
237-
size.bits(),
238-
align.bits() as u32,
239-
flags,
240-
Some(empty_array),
241-
0,
242-
unique_type_id_str.as_c_char_ptr(),
243-
unique_type_id_str.len(),
244-
)
245-
},
229+
Stub::Union => DIB(cx).create_union_type(
230+
containing_scope,
231+
name,
232+
file_metadata,
233+
line_number,
234+
size,
235+
align,
236+
flags,
237+
&[],
238+
&unique_type_id_str,
239+
),
246240
};
247241
StubInfo { metadata, unique_type_id }
248242
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,23 @@ unsafe extern "C" {
17751775
NumParameterTypes: c_uint,
17761776
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
17771777
) -> &'ll Metadata;
1778+
1779+
pub(crate) fn LLVMDIBuilderCreateUnionType<'ll>(
1780+
Builder: &DIBuilder<'ll>,
1781+
Scope: Option<&'ll Metadata>,
1782+
Name: *const c_uchar,
1783+
NameLen: size_t,
1784+
File: &'ll Metadata,
1785+
LineNumber: c_uint,
1786+
SizeInBits: u64,
1787+
AlignInBits: u32,
1788+
Flags: DIFlags,
1789+
Elements: *const &'ll Metadata,
1790+
NumElements: c_uint,
1791+
RunTimeLang: c_uint, // ("Objective-C runtime version"; default is 0)
1792+
UniqueId: *const c_uchar,
1793+
UniqueIdLen: size_t,
1794+
) -> &'ll Metadata;
17781795
}
17791796

17801797
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2285,22 +2302,6 @@ unsafe extern "C" {
22852302
IsScoped: bool,
22862303
) -> &'a DIType;
22872304

2288-
pub fn LLVMRustDIBuilderCreateUnionType<'a>(
2289-
Builder: &DIBuilder<'a>,
2290-
Scope: Option<&'a DIScope>,
2291-
Name: *const c_char,
2292-
NameLen: size_t,
2293-
File: &'a DIFile,
2294-
LineNumber: c_uint,
2295-
SizeInBits: u64,
2296-
AlignInBits: u32,
2297-
Flags: DIFlags,
2298-
Elements: Option<&'a DIArray>,
2299-
RunTimeLang: c_uint,
2300-
UniqueId: *const c_char,
2301-
UniqueIdLen: size_t,
2302-
) -> &'a DIType;
2303-
23042305
pub fn LLVMRustDIBuilderCreateVariantPart<'a>(
23052306
Builder: &DIBuilder<'a>,
23062307
Scope: &'a DIScope,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -1278,19 +1278,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
12781278
/* RunTimeLang */ 0, "", IsScoped));
12791279
}
12801280

1281-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType(
1282-
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1283-
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1284-
uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1285-
LLVMMetadataRef Elements, unsigned RunTimeLang, const char *UniqueId,
1286-
size_t UniqueIdLen) {
1287-
return wrap(unwrap(Builder)->createUnionType(
1288-
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
1289-
unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits,
1290-
fromRust(Flags), DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang,
1291-
StringRef(UniqueId, UniqueIdLen)));
1292-
}
1293-
12941281
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
12951282
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
12961283
size_t NameLen, LLVMMetadataRef Ty) {

0 commit comments

Comments
 (0)