From 6269bc78a5bed4226dcfb0a1235b9217d91cce9f Mon Sep 17 00:00:00 2001 From: Yuki OKUSHI Date: Fri, 29 Mar 2019 16:36:14 +0900 Subject: [PATCH] Support 128-bit discriminants in debuginfo --- .../debuginfo/metadata.rs | 13 ++----- src/test/codegen/enum-debug-niche-2.rs | 4 +- src/test/codegen/repr-u128.rs | 24 ++++++++++++ src/test/debuginfo/issue-22656.rs | 2 +- src/test/debuginfo/repr-u128.rs | 37 +++++++++++++++++++ 5 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/test/codegen/repr-u128.rs create mode 100644 src/test/debuginfo/repr-u128.rs diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index b000628a3f706..f085422fc084c 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -1019,7 +1019,7 @@ struct MemberDescription<'ll> { size: Size, align: Align, flags: DIFlags, - discriminant: Option, + discriminant: Option, } impl<'ll> MemberDescription<'ll> { @@ -1039,7 +1039,7 @@ impl<'ll> MemberDescription<'ll> { self.offset.bits(), match self.discriminant { None => None, - Some(value) => Some(cx.const_u64(value)), + Some(value) => Some(cx.const_uint_big(cx.type_i128(), value)), }, self.flags, self.type_metadata) @@ -1418,7 +1418,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { align: self.layout.align.abi, flags: DIFlags::FlagZero, discriminant: Some( - self.layout.ty.discriminant_for_variant(cx.tcx, i).unwrap().val as u64 + self.layout.ty.discriminant_for_variant(cx.tcx, i).unwrap().val ), } }).collect() @@ -1521,12 +1521,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> { let value = (i.as_u32() as u128) .wrapping_sub(niche_variants.start().as_u32() as u128) .wrapping_add(niche_start); - let value = truncate(value, discr.value.size(cx)); - // NOTE(eddyb) do *NOT* remove this assert, until - // we pass the full 128-bit value to LLVM, otherwise - // truncation will be silent and remain undetected. - assert_eq!(value as u64 as u128, value); - Some(value as u64) + Some(truncate(value, discr.value.size(cx))) }; MemberDescription { diff --git a/src/test/codegen/enum-debug-niche-2.rs b/src/test/codegen/enum-debug-niche-2.rs index 0f17976ef4965..a5a4653118478 100644 --- a/src/test/codegen/enum-debug-niche-2.rs +++ b/src/test/codegen/enum-debug-niche-2.rs @@ -9,8 +9,8 @@ // compile-flags: -g -C no-prepopulate-passes // CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}} -// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i64 4294967295{{[,)].*}} -// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i64 0{{[,)].*}} +// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}} +// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}} #![feature(never_type)] diff --git a/src/test/codegen/repr-u128.rs b/src/test/codegen/repr-u128.rs new file mode 100644 index 0000000000000..607ed627f65a3 --- /dev/null +++ b/src/test/codegen/repr-u128.rs @@ -0,0 +1,24 @@ +// ignore-tidy-linelength +// ignore-windows +// min-system-llvm-version 8.0 + +// compile-flags: -g -C no-prepopulate-passes + +// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "None",{{.*}}extraData: i128 18446745000000000124{{[,)].*}} + +#![feature(repr128)] + +#[repr(u128)] +pub enum Foo { + Lo, + Hi = 1 << 64, + Bar = 18_446_745_000_000_000_123, +} + +pub fn foo() -> Option { + None +} + +fn main() { + let roa = foo(); +} diff --git a/src/test/debuginfo/issue-22656.rs b/src/test/debuginfo/issue-22656.rs index 86d31909a0b3b..e39820baedcf1 100644 --- a/src/test/debuginfo/issue-22656.rs +++ b/src/test/debuginfo/issue-22656.rs @@ -15,7 +15,7 @@ // lldbg-check:[...]$0 = vec![1, 2, 3] // lldbr-check:(alloc::vec::Vec) v = vec![1, 2, 3] // lldb-command:print zs -// lldbg-check:[...]$1 = StructWithZeroSizedField { x: ZeroSizedStruct, y: 123, z: ZeroSizedStruct, w: 456 } +// lldbg-check:[...]$1 = StructWithZeroSizedField { x: ZeroSizedStruct { }, y: 123, z: ZeroSizedStruct { }, w: 456 } // lldbr-check:(issue_22656::StructWithZeroSizedField) zs = StructWithZeroSizedField { x: ZeroSizedStruct { }, y: 123, z: ZeroSizedStruct { }, w: 456 } // lldbr-command:continue diff --git a/src/test/debuginfo/repr-u128.rs b/src/test/debuginfo/repr-u128.rs new file mode 100644 index 0000000000000..d211c3f75cfd1 --- /dev/null +++ b/src/test/debuginfo/repr-u128.rs @@ -0,0 +1,37 @@ +// ignore-windows +// ignore-tidy-linelength +// min-system-llvm-version 8.0 + +// compile-flags: -g -C no-prepopulate-passes + +// === GDB TESTS =================================================================================== + +// gdb-command: run + +// gdb-command:print vals +// gdb-check:$1 = (core::option::Option, core::option::Option) + +// === LLDB TESTS ================================================================================== + +// lldb-command:run + +// lldb-command:print vals +// lldbg-check:[...]$0 = (Option { }, Option { }) +// lldbr-check:((core::option::Option, core::option::Option)) $0 = (Option { }, Option { }) + +#![feature(repr128)] + +#[repr(u128)] +pub enum Foo { + Lo, + Hi = 1 << 64, + Bar = 18_446_745_000_000_000_123, +} + +fn main() { + let vals = (Some(Foo::Lo), None::); + + zzz(); // #break +} + +fn zzz() {()}