Skip to content

Commit 6a1e75a

Browse files
committed
Use LLVMDIBuilderCreateUnionType
1 parent 7df8a50 commit 6a1e75a

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
@@ -1780,6 +1780,23 @@ unsafe extern "C" {
17801780
NumParameterTypes: c_uint,
17811781
Flags: DIFlags, // (optional; default is `DIFlags::FlagZero`)
17821782
) -> &'ll Metadata;
1783+
1784+
pub(crate) fn LLVMDIBuilderCreateUnionType<'ll>(
1785+
Builder: &DIBuilder<'ll>,
1786+
Scope: Option<&'ll Metadata>,
1787+
Name: *const c_uchar,
1788+
NameLen: size_t,
1789+
File: &'ll Metadata,
1790+
LineNumber: c_uint,
1791+
SizeInBits: u64,
1792+
AlignInBits: u32,
1793+
Flags: DIFlags,
1794+
Elements: *const &'ll Metadata,
1795+
NumElements: c_uint,
1796+
RunTimeLang: c_uint, // ("Objective-C runtime version"; default is 0)
1797+
UniqueId: *const c_uchar,
1798+
UniqueIdLen: size_t,
1799+
) -> &'ll Metadata;
17831800
}
17841801

17851802
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2304,22 +2321,6 @@ unsafe extern "C" {
23042321
IsScoped: bool,
23052322
) -> &'a DIType;
23062323

2307-
pub(crate) fn LLVMRustDIBuilderCreateUnionType<'a>(
2308-
Builder: &DIBuilder<'a>,
2309-
Scope: Option<&'a DIScope>,
2310-
Name: *const c_char,
2311-
NameLen: size_t,
2312-
File: &'a DIFile,
2313-
LineNumber: c_uint,
2314-
SizeInBits: u64,
2315-
AlignInBits: u32,
2316-
Flags: DIFlags,
2317-
Elements: Option<&'a DIArray>,
2318-
RunTimeLang: c_uint,
2319-
UniqueId: *const c_char,
2320-
UniqueIdLen: size_t,
2321-
) -> &'a DIType;
2322-
23232324
pub(crate) fn LLVMRustDIBuilderCreateVariantPart<'a>(
23242325
Builder: &DIBuilder<'a>,
23252326
Scope: &'a DIScope,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -1251,19 +1251,6 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
12511251
/* RunTimeLang */ 0, "", IsScoped));
12521252
}
12531253

1254-
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType(
1255-
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
1256-
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
1257-
uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
1258-
LLVMMetadataRef Elements, unsigned RunTimeLang, const char *UniqueId,
1259-
size_t UniqueIdLen) {
1260-
return wrap(unwrap(Builder)->createUnionType(
1261-
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
1262-
unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits,
1263-
fromRust(Flags), DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang,
1264-
StringRef(UniqueId, UniqueIdLen)));
1265-
}
1266-
12671254
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
12681255
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
12691256
size_t NameLen, LLVMMetadataRef Ty) {

0 commit comments

Comments
 (0)