-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #54004 - tromey:enum-debuginfo, r=tromey
Fix DWARF generation for enums The DWARF generated for Rust enums was always somewhat unusual. Rather than using DWARF constructs directly, it would emit magic field names like "RUST$ENCODED$ENUM$0$Name" and "RUST$ENUM$DISR". Since PR #45225, though, even this has not worked -- the ad hoc scheme was not updated to handle the wider variety of niche-filling layout optimizations now available. This patch changes the generated DWARF to use the standard tags meant for this purpose; namely, DW_TAG_variant and DW_TAG_variant_part. The patch to implement this went in to LLVM 7. In order to work with older versions of LLVM, and because LLVM doesn't do anything here for PDB, the existing code is kept as a fallback mode. Support for this DWARF is in the Rust lldb and in gdb 8.2. Closes #32920 Closes #32924 Closes #52762 Closes #53153
- Loading branch information
Showing
26 changed files
with
1,636 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule llvm
updated
2 files
+1 −1 | lib/Bitcode/Reader/MetadataLoader.cpp | |
+14 −0 | test/Assembler/debug-variant-discriminator.ll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// This test depends on a patch that was committed to upstream LLVM | ||
// before 7.0, then backported to the Rust LLVM fork. It tests that | ||
// debug info for "c-like" enums is properly emitted. | ||
|
||
// ignore-tidy-linelength | ||
// ignore-windows | ||
// min-system-llvm-version 7.0 | ||
|
||
// compile-flags: -g -C no-prepopulate-passes | ||
|
||
// CHECK-LABEL: @main | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_enumeration_type,{{.*}}name: "E",{{.*}}flags: DIFlagFixedEnum,{{.*}} | ||
// CHECK: {{.*}}DIEnumerator{{.*}}name: "A",{{.*}}value: {{[0-9].*}} | ||
// CHECK: {{.*}}DIEnumerator{{.*}}name: "B",{{.*}}value: {{[0-9].*}} | ||
// CHECK: {{.*}}DIEnumerator{{.*}}name: "C",{{.*}}value: {{[0-9].*}} | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
#![allow(unused_assignments)] | ||
|
||
enum E { A, B, C } | ||
|
||
pub fn main() { | ||
let e = E::C; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// This test depends on a patch that was committed to upstream LLVM | ||
// before 7.0, then backported to the Rust LLVM fork. It tests that | ||
// optimized enum debug info accurately reflects the enum layout. | ||
|
||
// ignore-tidy-linelength | ||
// ignore-windows | ||
// min-system-llvm-version 7.0 | ||
|
||
// compile-flags: -g -C no-prepopulate-passes | ||
|
||
// CHECK-LABEL: @main | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}discriminator:{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "A",{{.*}}extraData:{{.*}} | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_structure_type,{{.*}}name: "A",{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "B",{{.*}}extraData:{{.*}} | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_structure_type,{{.*}}name: "B",{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "C",{{.*}}extraData:{{.*}} | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_structure_type,{{.*}}name: "C",{{.*}} | ||
// CHECK-NOT: {{.*}}DIDerivedType{{.*}}name: "D",{{.*}}extraData:{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "D",{{.*}} | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_structure_type,{{.*}}name: "D",{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}flags: DIFlagArtificial{{.*}} | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
#![allow(unused_assignments)] | ||
|
||
enum E { A, B, C, D(bool) } | ||
|
||
pub fn main() { | ||
let e = E::D(true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// This test depends on a patch that was committed to upstream LLVM | ||
// before 7.0, then backported to the Rust LLVM fork. It tests that | ||
// debug info for tagged (ordinary) enums is properly emitted. | ||
|
||
// ignore-tidy-linelength | ||
// ignore-windows | ||
// min-system-llvm-version 7.0 | ||
|
||
// compile-flags: -g -C no-prepopulate-passes | ||
|
||
// CHECK-LABEL: @main | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_structure_type,{{.*}}name: "E",{{.*}} | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}discriminator:{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "A",{{.*}}extraData:{{.*}} | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_structure_type,{{.*}}name: "A",{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "__0",{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "B",{{.*}}extraData:{{.*}} | ||
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_structure_type,{{.*}}name: "B",{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "__0",{{.*}} | ||
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}flags: DIFlagArtificial{{.*}} | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
#![allow(unused_assignments)] | ||
|
||
enum E { A(u32), B(u32) } | ||
|
||
pub fn main() { | ||
let e = E::A(23); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// ignore-tidy-linelength | ||
// min-lldb-version: 310 | ||
|
||
// As long as LLVM 5 and LLVM 6 are supported, we want to test the | ||
// enum debuginfo fallback mode. Once those are desupported, this | ||
// test can be removed, as there is another (non-"legacy") test that | ||
// tests the new mode. | ||
// ignore-llvm-version: 7.0 - 9.9.9 | ||
// ignore-gdb-version: 7.11.90 - 7.12.9 | ||
// ignore-gdb-version: 8.2 - 9.9 | ||
|
||
// compile-flags:-g | ||
|
||
// === GDB TESTS =================================================================================== | ||
|
||
// gdb-command:run | ||
|
||
// gdb-command:print *the_a_ref | ||
// gdbg-check:$1 = {{RUST$ENUM$DISR = TheA, x = 0, y = 8970181431921507452}, {RUST$ENUM$DISR = TheA, [...]}} | ||
// gdbr-check:$1 = borrowed_enum_legacy::ABC::TheA{x: 0, y: 8970181431921507452} | ||
|
||
// gdb-command:print *the_b_ref | ||
// gdbg-check:$2 = {{RUST$ENUM$DISR = TheB, [...]}, {RUST$ENUM$DISR = TheB, __0 = 0, __1 = 286331153, __2 = 286331153}} | ||
// gdbr-check:$2 = borrowed_enum_legacy::ABC::TheB(0, 286331153, 286331153) | ||
|
||
// gdb-command:print *univariant_ref | ||
// gdbg-check:$3 = {{__0 = 4820353753753434}} | ||
// gdbr-check:$3 = borrowed_enum_legacy::Univariant::TheOnlyCase(4820353753753434) | ||
|
||
|
||
// === LLDB TESTS ================================================================================== | ||
|
||
// lldb-command:run | ||
|
||
// lldb-command:print *the_a_ref | ||
// lldb-check:[...]$0 = TheA { x: 0, y: 8970181431921507452 } | ||
// lldb-command:print *the_b_ref | ||
// lldb-check:[...]$1 = TheB(0, 286331153, 286331153) | ||
// lldb-command:print *univariant_ref | ||
// lldb-check:[...]$2 = TheOnlyCase(4820353753753434) | ||
|
||
#![allow(unused_variables)] | ||
#![feature(omit_gdb_pretty_printer_section)] | ||
#![omit_gdb_pretty_printer_section] | ||
|
||
// The first element is to ensure proper alignment, irrespective of the machines word size. Since | ||
// the size of the discriminant value is machine dependent, this has be taken into account when | ||
// datatype layout should be predictable as in this case. | ||
enum ABC { | ||
TheA { x: i64, y: i64 }, | ||
TheB (i64, i32, i32), | ||
} | ||
|
||
// This is a special case since it does not have the implicit discriminant field. | ||
enum Univariant { | ||
TheOnlyCase(i64) | ||
} | ||
|
||
fn main() { | ||
|
||
// 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452 | ||
// 0b01111100011111000111110001111100 = 2088533116 | ||
// 0b0111110001111100 = 31868 | ||
// 0b01111100 = 124 | ||
let the_a = ABC::TheA { x: 0, y: 8970181431921507452 }; | ||
let the_a_ref: &ABC = &the_a; | ||
|
||
// 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441 | ||
// 0b00010001000100010001000100010001 = 286331153 | ||
// 0b0001000100010001 = 4369 | ||
// 0b00010001 = 17 | ||
let the_b = ABC::TheB (0, 286331153, 286331153); | ||
let the_b_ref: &ABC = &the_b; | ||
|
||
let univariant = Univariant::TheOnlyCase(4820353753753434); | ||
let univariant_ref: &Univariant = &univariant; | ||
|
||
zzz(); // #break | ||
} | ||
|
||
fn zzz() {()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.