From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 1/2] Conditionally drop the discriminant field in quirk_rust_enum
Date: Thu, 12 Apr 2018 19:08:00 -0000 [thread overview]
Message-ID: <20180412190756.16052-2-tom@tromey.com> (raw)
In-Reply-To: <20180412190756.16052-1-tom@tromey.com>
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-12 Tom Tromey <tom@tromey.com>
* dwarf2read.c (quirk_rust_enum): Conditionally drop the
discriminant field.
---
gdb/ChangeLog | 5 +++++
gdb/dwarf2read.c | 9 ++++++---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 649c9cea97..ceaa5f92ab 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-04-12 Tom Tromey <tom@tromey.com>
+
+ * dwarf2read.c (quirk_rust_enum): Conditionally drop the
+ discriminant field.
+
2018-03-29 Tom Tromey <tom@tromey.com>
* dwarf2read.c (quirk_rust_enum): Handle unions correctly.
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0d3af00c46..4207e4c531 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,
--
2.13.6
next prev parent reply other threads:[~2018-04-12 19:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-12 19:08 [RFA 0/2] Minor Rust-related DWARF reader fixes Tom Tromey
2018-04-12 19:08 ` Tom Tromey [this message]
2018-04-13 7:36 ` [RFA 1/2] Conditionally drop the discriminant field in quirk_rust_enum Joel Brobecker
2018-04-12 19:12 ` [RFA 2/2] Set TYPE_NAME for Rust unions Tom Tromey
2018-04-13 7:41 ` Joel Brobecker
2018-04-17 19:37 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180412190756.16052-2-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox