diff options
author | Tom Tromey <tom@tromey.com> | 2018-03-29 11:49:59 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-04-17 13:37:44 -0600 |
commit | a037790ec570ae9f9bf535cbce25f238f90e8b4a (patch) | |
tree | 2c5232fd4fc9b0e6ce9f39a7696f9b46a42ab6c9 /gdb/dwarf2read.c | |
parent | c7dcbf88c6557f35d9e75ae6223a3e61e1f70578 (diff) | |
download | binutils-gdb-a037790ec570ae9f9bf535cbce25f238f90e8b4a.tar.gz |
Fix crash in quirk_rust_enum
I noticed that quirk_rust_enum can crash when presented with a union
whose fields are all scalar types.
This patch adds a new test case and fixes the bug.
Regression tested on Fedora 26 x86-64.
2018-04-17 Tom Tromey <tom@tromey.com>
* dwarf2read.c (quirk_rust_enum): Handle unions correctly.
2018-04-17 Tom Tromey <tom@tromey.com>
* gdb.rust/simple.rs (Union): New type.
(main): New local "u".
* gdb.rust/simple.exp (test_one_slice): Add new test case.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r-- | gdb/dwarf2read.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 9c9dcee058c..0d3af00c463 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -9989,9 +9989,15 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) { disr_type = TYPE_FIELD_TYPE (type, i); - if (TYPE_NFIELDS (disr_type) == 0) + if (TYPE_CODE (disr_type) != TYPE_CODE_STRUCT) + { + /* All fields of a true enum will be structs. */ + return; + } + else if (TYPE_NFIELDS (disr_type) == 0) { /* Could be data-less variant, so keep going. */ + disr_type = nullptr; } else if (strcmp (TYPE_FIELD_NAME (disr_type, 0), "RUST$ENUM$DISR") != 0) |