aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-04-12 08:05:16 -0600
committerTom Tromey <tom@tromey.com>2018-04-17 13:37:44 -0600
commitbedda9aced2b3a8ab05e0fbf1372e394e32afbde (patch)
tree8a9451b501969cac27636c36c1ce60b3c7cce4f6 /gdb
parenta037790ec570ae9f9bf535cbce25f238f90e8b4a (diff)
downloadbinutils-bedda9aced2b3a8ab05e0fbf1372e394e32afbde.zip
binutils-bedda9aced2b3a8ab05e0fbf1372e394e32afbde.tar.gz
binutils-bedda9aced2b3a8ab05e0fbf1372e394e32afbde.tar.bz2
Conditionally drop the discriminant field in quirk_rust_enum
While debugging the crash that Jan reported, I noticed that in some situations we could end up with a situation where one branch of a Rust enum type ended up with a field count of -1. The fix is simple: only conditionally drop the discriminant field when rewriting the enum variants. I couldn't find a way to test this; I only noticed it while debugging the DWARF reader. 2018-04-17 Tom Tromey <tom@tromey.com> * dwarf2read.c (quirk_rust_enum): Conditionally drop the discriminant field.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/dwarf2read.c9
2 files changed, 11 insertions, 3 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 35072e8..55bdd14 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2018-04-17 Tom Tromey <tom@tromey.com>
+ * dwarf2read.c (quirk_rust_enum): Conditionally drop the
+ discriminant field.
+
+2018-04-17 Tom Tromey <tom@tromey.com>
+
* dwarf2read.c (quirk_rust_enum): Handle unions correctly.
2018-04-17 Andreas Arnez <arnez@linux.vnet.ibm.com>
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0d3af00..4207e4c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -10079,10 +10079,13 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
if (iter != discriminant_map.end ())
disc->discriminants[i] = iter->second;
- /* Remove the discriminant field. */
+ /* Remove the discriminant field, if it exists. */
struct type *sub_type = TYPE_FIELD_TYPE (union_type, i);
- --TYPE_NFIELDS (sub_type);
- ++TYPE_FIELDS (sub_type);
+ if (TYPE_NFIELDS (sub_type) > 0)
+ {
+ --TYPE_NFIELDS (sub_type);
+ ++TYPE_FIELDS (sub_type);
+ }
TYPE_FIELD_NAME (union_type, i) = variant_name;
TYPE_NAME (sub_type)
= rust_fully_qualify (&objfile->objfile_obstack,