Skip to content

Commit 9d28309

Browse files
authored
Rollup merge of rust-lang#59520 - JohnTitor:add-assert, r=eddyb
rustc_codegen_llvm: support 128-bit discriminants in debuginfo. CC: rust-lang#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 3af1bdc + 2e85b31 commit 9d28309

File tree

4 files changed

+65
-11
lines changed

4 files changed

+65
-11
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ struct MemberDescription<'ll> {
997997
size: Size,
998998
align: Align,
999999
flags: DIFlags,
1000-
discriminant: Option<u64>,
1000+
discriminant: Option<u128>,
10011001
}
10021002

10031003
// A factory for MemberDescriptions. It produces a list of member descriptions
@@ -1355,7 +1355,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13551355
flags: DIFlags::FlagZero,
13561356
discriminant: Some(self.layout.ty.ty_adt_def().unwrap()
13571357
.discriminant_for_variant(cx.tcx, i)
1358-
.val as u64),
1358+
.val),
13591359
}
13601360
}).collect()
13611361
}
@@ -1454,12 +1454,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
14541454
let value = (i.as_u32() as u128)
14551455
.wrapping_sub(niche_variants.start().as_u32() as u128)
14561456
.wrapping_add(niche_start);
1457-
let value = truncate(value, discr.value.size(cx));
1458-
// NOTE(eddyb) do *NOT* remove this assert, until
1459-
// we pass the full 128-bit value to LLVM, otherwise
1460-
// truncation will be silent and remain undetected.
1461-
assert_eq!(value as u64 as u128, value);
1462-
Some(value as u64)
1457+
Some(truncate(value, discr.value.size(cx)))
14631458
};
14641459

14651460
MemberDescription {
@@ -1932,7 +1927,8 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
19321927
member_description.offset.bits(),
19331928
match member_description.discriminant {
19341929
None => None,
1935-
Some(value) => Some(cx.const_u64(value)),
1930+
Some(value) =>
1931+
Some(cx.const_uint_big(cx.type_i128(), value)),
19361932
},
19371933
member_description.flags,
19381934
member_description.type_metadata))

src/test/codegen/enum-debug-niche-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// compile-flags: -g -C no-prepopulate-passes
1010

1111
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
12-
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i64 4294967295{{[,)].*}}
13-
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i64 0{{[,)].*}}
12+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}}
13+
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}}
1414

1515
#![feature(never_type)]
1616
#![feature(nll)]

src/test/codegen/repr-u128.rs

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

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)