Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_codegen_llvm: support 128-bit discriminants in debuginfo. #59520

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
JohnTitor marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, here is where we need someone who knows debuginfo (@michaelwoerister?).
Or you could peek at a different debuginfo test, to see how it makes the debugger print variables automatically and checks the output.


// gdb-command:print vals
// gdb-check:$1 = (core::option::Option<repr_u128::Foo>, core::option::Option<repr_u128::Foo>)

// === LLDB TESTS ==================================================================================
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is GDB missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyb Sorry for being late. I fixed test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing Some or None in the tested output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we cannot catch these now. This is a part of repr-u128.out.

print vals
((core::option::Option<repr_u128::Foo>, core::option::Option<repr_u128::Foo>)) $0 = (Option<repr_u128::Foo> { }, Option<repr_u128::Foo> { }) 
quit
None

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't understand what's happening :/


// 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() {()}