mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Pass 128-bit C-style enum enumerator values to LLVM
This commit is contained in:
parent
24ac6a26bc
commit
25c1c635e5
@ -462,7 +462,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>(
|
|||||||
cx,
|
cx,
|
||||||
"VariantNames",
|
"VariantNames",
|
||||||
variant_names_enum_base_type(cx),
|
variant_names_enum_base_type(cx),
|
||||||
variants.map(|(variant_index, variant_name)| (variant_name, variant_index.as_u32() as u64)),
|
variants.map(|(variant_index, variant_name)| (variant_name, variant_index.as_u32().into())),
|
||||||
containing_scope,
|
containing_scope,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,7 @@ fn build_c_style_enum_di_node<'ll, 'tcx>(
|
|||||||
tag_base_type(cx, enum_type_and_layout),
|
tag_base_type(cx, enum_type_and_layout),
|
||||||
enum_adt_def.discriminants(cx.tcx).map(|(variant_index, discr)| {
|
enum_adt_def.discriminants(cx.tcx).map(|(variant_index, discr)| {
|
||||||
let name = Cow::from(enum_adt_def.variant(variant_index).name.as_str());
|
let name = Cow::from(enum_adt_def.variant(variant_index).name.as_str());
|
||||||
// Is there anything we can do to support 128-bit C-Style enums?
|
(name, discr.val)
|
||||||
let value = discr.val as u64;
|
|
||||||
(name, value)
|
|
||||||
}),
|
}),
|
||||||
containing_scope,
|
containing_scope,
|
||||||
),
|
),
|
||||||
@ -147,14 +145,11 @@ fn tag_base_type<'ll, 'tcx>(
|
|||||||
/// This is a helper function and does not register anything in the type map by itself.
|
/// This is a helper function and does not register anything in the type map by itself.
|
||||||
///
|
///
|
||||||
/// `variants` is an iterator of (discr-value, variant-name).
|
/// `variants` is an iterator of (discr-value, variant-name).
|
||||||
///
|
|
||||||
// NOTE: Handling of discriminant values is somewhat inconsistent. They can appear as u128,
|
|
||||||
// u64, and i64. Here everything gets mapped to i64 because that's what LLVM's API expects.
|
|
||||||
fn build_enumeration_type_di_node<'ll, 'tcx>(
|
fn build_enumeration_type_di_node<'ll, 'tcx>(
|
||||||
cx: &CodegenCx<'ll, 'tcx>,
|
cx: &CodegenCx<'ll, 'tcx>,
|
||||||
type_name: &str,
|
type_name: &str,
|
||||||
base_type: Ty<'tcx>,
|
base_type: Ty<'tcx>,
|
||||||
enumerators: impl Iterator<Item = (Cow<'tcx, str>, u64)>,
|
enumerators: impl Iterator<Item = (Cow<'tcx, str>, u128)>,
|
||||||
containing_scope: &'ll DIType,
|
containing_scope: &'ll DIType,
|
||||||
) -> &'ll DIType {
|
) -> &'ll DIType {
|
||||||
let is_unsigned = match base_type.kind() {
|
let is_unsigned = match base_type.kind() {
|
||||||
@ -162,21 +157,22 @@ fn build_enumeration_type_di_node<'ll, 'tcx>(
|
|||||||
ty::Uint(_) => true,
|
ty::Uint(_) => true,
|
||||||
_ => bug!("build_enumeration_type_di_node() called with non-integer tag type."),
|
_ => bug!("build_enumeration_type_di_node() called with non-integer tag type."),
|
||||||
};
|
};
|
||||||
|
let (size, align) = cx.size_and_align_of(base_type);
|
||||||
|
|
||||||
let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = enumerators
|
let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = enumerators
|
||||||
.map(|(name, value)| unsafe {
|
.map(|(name, value)| unsafe {
|
||||||
|
let value = [value as u64, (value >> 64) as u64];
|
||||||
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
|
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
|
||||||
DIB(cx),
|
DIB(cx),
|
||||||
name.as_ptr().cast(),
|
name.as_ptr().cast(),
|
||||||
name.len(),
|
name.len(),
|
||||||
value as i64,
|
value.as_ptr(),
|
||||||
|
size.bits() as libc::c_uint,
|
||||||
is_unsigned,
|
is_unsigned,
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let (size, align) = cx.size_and_align_of(base_type);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMRustDIBuilderCreateEnumerationType(
|
llvm::LLVMRustDIBuilderCreateEnumerationType(
|
||||||
DIB(cx),
|
DIB(cx),
|
||||||
|
@ -2118,7 +2118,8 @@ extern "C" {
|
|||||||
Builder: &DIBuilder<'a>,
|
Builder: &DIBuilder<'a>,
|
||||||
Name: *const c_char,
|
Name: *const c_char,
|
||||||
NameLen: size_t,
|
NameLen: size_t,
|
||||||
Value: i64,
|
Value: *const u64,
|
||||||
|
SizeInBits: c_uint,
|
||||||
IsUnsigned: bool,
|
IsUnsigned: bool,
|
||||||
) -> &'a DIEnumerator;
|
) -> &'a DIEnumerator;
|
||||||
|
|
||||||
|
@ -998,8 +998,9 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
|
|||||||
|
|
||||||
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(
|
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(
|
||||||
LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen,
|
LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen,
|
||||||
int64_t Value, bool IsUnsigned) {
|
const uint64_t Value[2], unsigned SizeInBits, bool IsUnsigned) {
|
||||||
return wrap(Builder->createEnumerator(StringRef(Name, NameLen), Value, IsUnsigned));
|
return wrap(Builder->createEnumerator(StringRef(Name, NameLen),
|
||||||
|
APSInt(APInt(SizeInBits, makeArrayRef(Value, 2)), IsUnsigned)));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
|
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
|
||||||
|
Loading…
Reference in New Issue
Block a user