Skip to content

Commit 25c1c63

Browse files
committed
Pass 128-bit C-style enum enumerator values to LLVM
1 parent 24ac6a2 commit 25c1c63

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>(
462462
cx,
463463
"VariantNames",
464464
variant_names_enum_base_type(cx),
465-
variants.map(|(variant_index, variant_name)| (variant_name, variant_index.as_u32() as u64)),
465+
variants.map(|(variant_index, variant_name)| (variant_name, variant_index.as_u32().into())),
466466
containing_scope,
467467
)
468468
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ fn build_c_style_enum_di_node<'ll, 'tcx>(
9191
tag_base_type(cx, enum_type_and_layout),
9292
enum_adt_def.discriminants(cx.tcx).map(|(variant_index, discr)| {
9393
let name = Cow::from(enum_adt_def.variant(variant_index).name.as_str());
94-
// Is there anything we can do to support 128-bit C-Style enums?
95-
let value = discr.val as u64;
96-
(name, value)
94+
(name, discr.val)
9795
}),
9896
containing_scope,
9997
),
@@ -147,36 +145,34 @@ fn tag_base_type<'ll, 'tcx>(
147145
/// This is a helper function and does not register anything in the type map by itself.
148146
///
149147
/// `variants` is an iterator of (discr-value, variant-name).
150-
///
151-
// NOTE: Handling of discriminant values is somewhat inconsistent. They can appear as u128,
152-
// u64, and i64. Here everything gets mapped to i64 because that's what LLVM's API expects.
153148
fn build_enumeration_type_di_node<'ll, 'tcx>(
154149
cx: &CodegenCx<'ll, 'tcx>,
155150
type_name: &str,
156151
base_type: Ty<'tcx>,
157-
enumerators: impl Iterator<Item = (Cow<'tcx, str>, u64)>,
152+
enumerators: impl Iterator<Item = (Cow<'tcx, str>, u128)>,
158153
containing_scope: &'ll DIType,
159154
) -> &'ll DIType {
160155
let is_unsigned = match base_type.kind() {
161156
ty::Int(_) => false,
162157
ty::Uint(_) => true,
163158
_ => bug!("build_enumeration_type_di_node() called with non-integer tag type."),
164159
};
160+
let (size, align) = cx.size_and_align_of(base_type);
165161

166162
let enumerator_di_nodes: SmallVec<Option<&'ll DIType>> = enumerators
167163
.map(|(name, value)| unsafe {
164+
let value = [value as u64, (value >> 64) as u64];
168165
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
169166
DIB(cx),
170167
name.as_ptr().cast(),
171168
name.len(),
172-
value as i64,
169+
value.as_ptr(),
170+
size.bits() as libc::c_uint,
173171
is_unsigned,
174172
))
175173
})
176174
.collect();
177175

178-
let (size, align) = cx.size_and_align_of(base_type);
179-
180176
unsafe {
181177
llvm::LLVMRustDIBuilderCreateEnumerationType(
182178
DIB(cx),

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,8 @@ extern "C" {
21182118
Builder: &DIBuilder<'a>,
21192119
Name: *const c_char,
21202120
NameLen: size_t,
2121-
Value: i64,
2121+
Value: *const u64,
2122+
SizeInBits: c_uint,
21222123
IsUnsigned: bool,
21232124
) -> &'a DIEnumerator;
21242125

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,9 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
998998

999999
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(
10001000
LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen,
1001-
int64_t Value, bool IsUnsigned) {
1002-
return wrap(Builder->createEnumerator(StringRef(Name, NameLen), Value, IsUnsigned));
1001+
const uint64_t Value[2], unsigned SizeInBits, bool IsUnsigned) {
1002+
return wrap(Builder->createEnumerator(StringRef(Name, NameLen),
1003+
APSInt(APInt(SizeInBits, makeArrayRef(Value, 2)), IsUnsigned)));
10031004
}
10041005

10051006
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(

0 commit comments

Comments
 (0)