Skip to content

Commit

Permalink
Support 128-bit discriminants in debuginfo
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Jun 16, 2019
1 parent c28084a commit 6269bc7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
13 changes: 4 additions & 9 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ struct MemberDescription<'ll> {
size: Size,
align: Align,
flags: DIFlags,
discriminant: Option<u64>,
discriminant: Option<u128>,
}

impl<'ll> MemberDescription<'ll> {
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/codegen/enum-debug-niche-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
24 changes: 24 additions & 0 deletions src/test/codegen/repr-u128.rs
Original file line number Diff line number Diff line change
@@ -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<Foo> {
None
}

fn main() {
let roa = foo();
}
2 changes: 1 addition & 1 deletion src/test/debuginfo/issue-22656.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// lldbg-check:[...]$0 = vec![1, 2, 3]
// lldbr-check:(alloc::vec::Vec<i32>) 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

Expand Down
37 changes: 37 additions & 0 deletions src/test/debuginfo/repr-u128.rs
Original file line number Diff line number Diff line change
@@ -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<repr_u128::Foo>, core::option::Option<repr_u128::Foo>)

// === LLDB TESTS ==================================================================================

// lldb-command:run

// lldb-command:print vals
// lldbg-check:[...]$0 = (Option<repr_u128::Foo> { }, Option<repr_u128::Foo> { })
// lldbr-check:((core::option::Option<repr_u128::Foo>, core::option::Option<repr_u128::Foo>)) $0 = (Option<repr_u128::Foo> { }, Option<repr_u128::Foo> { })

#![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::<Foo>);

zzz(); // #break
}

fn zzz() {()}

0 comments on commit 6269bc7

Please sign in to comment.