Skip to content

Commit 3eb8c2a

Browse files
Rollup merge of #112474 - ldm0:ldm_enum_debuginfo_128_support, r=compiler-errors
Support 128-bit enum variant in debuginfo codegen fixes #111600
2 parents 4d5e7cd + ea19243 commit 3eb8c2a

File tree

7 files changed

+41
-11
lines changed

7 files changed

+41
-11
lines changed

compiler/rustc_codegen_gcc/src/common.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
108108
self.const_uint(self.type_u64(), i)
109109
}
110110

111+
fn const_u128(&self, i: u128) -> RValue<'gcc> {
112+
self.const_uint_big(self.type_u128(), i)
113+
}
114+
111115
fn const_usize(&self, i: u64) -> RValue<'gcc> {
112116
let bit_size = self.data_layout().pointer_size.bits();
113117
if bit_size < 64 {
@@ -254,7 +258,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
254258
// SIMD builtins require a constant value.
255259
self.bitcast_if_needed(value, typ)
256260
}
257-
261+
258262
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
259263
self.context.new_array_access(None, base_addr, self.const_usize(offset.bytes())).get_address(None)
260264
}

compiler/rustc_codegen_llvm/src/common.rs

+4
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
168168
self.const_uint(self.type_i64(), i)
169169
}
170170

171+
fn const_u128(&self, i: u128) -> &'ll Value {
172+
self.const_uint_big(self.type_i128(), i)
173+
}
174+
171175
fn const_usize(&self, i: u64) -> &'ll Value {
172176
let bit_size = self.data_layout().pointer_size.bits();
173177
if bit_size < 64 {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
429429
return existing_di_node;
430430
}
431431

432-
debug!("type_di_node: {:?}", t);
432+
debug!("type_di_node: {:?} kind: {:?}", t, t.kind());
433433

434434
let DINodeCreationResult { di_node, already_stored_in_typemap } = match *t.kind() {
435435
ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,7 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
412412
enum_type_and_layout.size.bits(),
413413
enum_type_and_layout.align.abi.bits() as u32,
414414
Size::ZERO.bits(),
415-
discr_value.opt_single_val().map(|value| {
416-
// NOTE(eddyb) do *NOT* remove this assert, until
417-
// we pass the full 128-bit value to LLVM, otherwise
418-
// truncation will be silent and remain undetected.
419-
assert_eq!(value as u64 as u128, value);
420-
cx.const_u64(value as u64)
421-
}),
415+
discr_value.opt_single_val().map(|value| cx.const_u128(value)),
422416
DIFlags::FlagZero,
423417
variant_member_info.variant_struct_type_di_node,
424418
)

compiler/rustc_codegen_ssa/src/traits/consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub trait ConstMethods<'tcx>: BackendTypes {
1515
fn const_i32(&self, i: i32) -> Self::Value;
1616
fn const_u32(&self, i: u32) -> Self::Value;
1717
fn const_u64(&self, i: u64) -> Self::Value;
18+
fn const_u128(&self, i: u128) -> Self::Value;
1819
fn const_usize(&self, i: u64) -> Self::Value;
1920
fn const_u8(&self, i: u8) -> Self::Value;
2021
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;

tests/codegen/enum-debug-niche-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// compile-flags: -g -C no-prepopulate-passes
88

99
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
10-
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i64 4294967295{{[,)].*}}
11-
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i64 0{{[,)].*}}
10+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}}
11+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}}
1212

1313
#![feature(never_type)]
1414

tests/codegen/enum-u128.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This tests that debug info for "c-like" 128bit enums is properly emitted.
2+
// This is ignored for the fallback mode on MSVC due to problems with PDB.
3+
4+
//
5+
// ignore-msvc
6+
7+
// compile-flags: -g -C no-prepopulate-passes
8+
9+
// CHECK-LABEL: @main
10+
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_enumeration_type,{{.*}}name: "Foo",{{.*}}flags: DIFlagEnumClass,{{.*}}
11+
// CHECK: {{.*}}DIEnumerator{{.*}}name: "Lo",{{.*}}value: 0,{{.*}}
12+
// CHECK: {{.*}}DIEnumerator{{.*}}name: "Hi",{{.*}}value: 18446744073709551616,{{.*}}
13+
// CHECK: {{.*}}DIEnumerator{{.*}}name: "Bar",{{.*}}value: 18446745000000000123,{{.*}}
14+
15+
#![allow(incomplete_features)]
16+
#![feature(repr128)]
17+
18+
#[repr(u128)]
19+
pub enum Foo {
20+
Lo,
21+
Hi = 1 << 64,
22+
Bar = 18_446_745_000_000_000_123,
23+
}
24+
25+
pub fn main() {
26+
let foo = Foo::Bar;
27+
}

0 commit comments

Comments
 (0)