Skip to content

Commit

Permalink
Auto merge of #59520 - JohnTitor:add-assert, r=eddyb
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 1, 2019
2 parents 9b67bd4 + 6ed4b52 commit bed21ba
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ struct MemberDescription<'ll> {
size: Size,
align: Align,
flags: DIFlags,
discriminant: Option<u64>,
discriminant: Option<u128>,
}

// A factory for MemberDescriptions. It produces a list of member descriptions
Expand Down Expand Up @@ -1351,7 +1351,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
flags: DIFlags::FlagZero,
discriminant: Some(self.layout.ty.ty_adt_def().unwrap()
.discriminant_for_variant(cx.tcx, i)
.val as u64),
.val),
}
}).collect()
}
Expand Down Expand Up @@ -1450,12 +1450,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 Expand Up @@ -1928,7 +1923,8 @@ fn set_members_of_composite_type(cx: &CodegenCx<'ll, 'tcx>,
member_description.offset.bits(),
match member_description.discriminant {
None => None,
Some(value) => Some(cx.const_u64(value)),
Some(value) =>
Some(cx.const_uint_big(cx.type_i128(), value)),
},
member_description.flags,
member_description.type_metadata))
Expand Down
20 changes: 20 additions & 0 deletions src/test/codegen/repr-u128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ignore-windows
// ignore-tidy-linelength
//min-system-llvm-version 8.0

//compile-flags: -g -C no-prepopulate-passes
#![feature(repr128)]

#[repr(u128)]
pub enum Foo {
Lo,
Hi = 1 << 64,
Bar = 18_446_745_000_000_000_123,
}

// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "None",{{.*}}extraData:18446745000000000124
pub fn foo() -> Option<Foo> {
None
}

fn main() {}
34 changes: 34 additions & 0 deletions src/test/debuginfo/repr-u128.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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
// gdbg-check:$1 = (Some(Foo::Lo), None::<Foo>)
// gdbr-check:$1 = repr_u128::Foo::(std::option::Option<Foo>, std::option::Option<Foo>)

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

// lldb-command:run

// lldb-command:print vals
// lldbg-check:[...]$0 = (Some(Foo::Lo), None::<Foo>)
// lldbr-check:(repr_u128::Foo) vals = repr_u128::Foo::(std::option::Option<Foo>, std::option::Option<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>);
}

0 comments on commit bed21ba

Please sign in to comment.