Skip to content

Commit bed21ba

Browse files
committed
Auto merge of #59520 - JohnTitor:add-assert, r=eddyb
rustc_codegen_llvm: support 128-bit discriminants in debuginfo. CC: #59509 > Alternatively, if LLVM and DWARF support it, we should encode the 128-bit discriminant If we should fix like this issue comment, I'll do. r? @eddyb
2 parents 9b67bd4 + 6ed4b52 commit bed21ba

File tree

3 files changed

+59
-9
lines changed

3 files changed

+59
-9
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ struct MemberDescription<'ll> {
993993
size: Size,
994994
align: Align,
995995
flags: DIFlags,
996-
discriminant: Option<u64>,
996+
discriminant: Option<u128>,
997997
}
998998

999999
// A factory for MemberDescriptions. It produces a list of member descriptions
@@ -1351,7 +1351,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13511351
flags: DIFlags::FlagZero,
13521352
discriminant: Some(self.layout.ty.ty_adt_def().unwrap()
13531353
.discriminant_for_variant(cx.tcx, i)
1354-
.val as u64),
1354+
.val),
13551355
}
13561356
}).collect()
13571357
}
@@ -1450,12 +1450,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
14501450
let value = (i.as_u32() as u128)
14511451
.wrapping_sub(niche_variants.start().as_u32() as u128)
14521452
.wrapping_add(niche_start);
1453-
let value = truncate(value, discr.value.size(cx));
1454-
// NOTE(eddyb) do *NOT* remove this assert, until
1455-
// we pass the full 128-bit value to LLVM, otherwise
1456-
// truncation will be silent and remain undetected.
1457-
assert_eq!(value as u64 as u128, value);
1458-
Some(value as u64)
1453+
Some(truncate(value, discr.value.size(cx)))
14591454
};
14601455

14611456
MemberDescription {
@@ -1928,7 +1923,8 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
19281923
member_description.offset.bits(),
19291924
match member_description.discriminant {
19301925
None => None,
1931-
Some(value) => Some(cx.const_u64(value)),
1926+
Some(value) =>
1927+
Some(cx.const_uint_big(cx.type_i128(), value)),
19321928
},
19331929
member_description.flags,
19341930
member_description.type_metadata))

src/test/codegen/repr-u128.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ignore-windows
2+
// ignore-tidy-linelength
3+
//min-system-llvm-version 8.0
4+
5+
//compile-flags: -g -C no-prepopulate-passes
6+
#![feature(repr128)]
7+
8+
#[repr(u128)]
9+
pub enum Foo {
10+
Lo,
11+
Hi = 1 << 64,
12+
Bar = 18_446_745_000_000_000_123,
13+
}
14+
15+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "None",{{.*}}extraData:18446745000000000124
16+
pub fn foo() -> Option<Foo> {
17+
None
18+
}
19+
20+
fn main() {}

src/test/debuginfo/repr-u128.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ignore-windows
2+
// ignore-tidy-linelength
3+
//min-system-llvm-version 8.0
4+
5+
//compile-flags: -g -C no-prepopulate-passes
6+
7+
// === GDB TESTS ===================================================================================
8+
9+
// gdb-command: run
10+
11+
// gdb-command:print vals
12+
// gdbg-check:$1 = (Some(Foo::Lo), None::<Foo>)
13+
// gdbr-check:$1 = repr_u128::Foo::(std::option::Option<Foo>, std::option::Option<Foo>)
14+
15+
// === LLDB TESTS ==================================================================================
16+
17+
// lldb-command:run
18+
19+
// lldb-command:print vals
20+
// lldbg-check:[...]$0 = (Some(Foo::Lo), None::<Foo>)
21+
// lldbr-check:(repr_u128::Foo) vals = repr_u128::Foo::(std::option::Option<Foo>, std::option::Option<Foo>)
22+
23+
#![feature(repr128)]
24+
25+
#[repr(u128)]
26+
pub enum Foo {
27+
Lo,
28+
Hi = 1 << 64,
29+
Bar = 18_446_745_000_000_000_123,
30+
}
31+
32+
fn main() {
33+
let vals = (Some(Foo::Lo), None::<Foo>);
34+
}

0 commit comments

Comments
 (0)