Skip to content

Commit a9332af

Browse files
committed
Use LLVMDIBuilderCreateUnionType
1 parent 778704f commit a9332af

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

17831800
#[link(name = "llvm-wrapper", kind = "static")]
@@ -2302,22 +2319,6 @@ unsafe extern "C" {
23022319
IsScoped: bool,
23032320
) -> &'a DIType;
23042321

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