From patchwork Thu Apr 12 19:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26701 Received: (qmail 39490 invoked by alias); 12 Apr 2018 19:08:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 39077 invoked by uid 89); 12 Apr 2018 19:08:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=disc X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Apr 2018 19:08:00 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway23.websitewelcome.com (Postfix) with ESMTP id EB660B073 for ; Thu, 12 Apr 2018 14:07:58 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 6hZefugBp6il36hZefy4GC; Thu, 12 Apr 2018 14:07:58 -0500 Received: from 75-166-37-45.hlrn.qwest.net ([75.166.37.45]:55312 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f6hZe-001aZT-Oj; Thu, 12 Apr 2018 14:07:58 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 1/2] Conditionally drop the discriminant field in quirk_rust_enum Date: Thu, 12 Apr 2018 13:07:55 -0600 Message-Id: <20180412190756.16052-2-tom@tromey.com> In-Reply-To: <20180412190756.16052-1-tom@tromey.com> References: <20180412190756.16052-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f6hZe-001aZT-Oj X-Source-Sender: 75-166-37-45.hlrn.qwest.net (pokyo.Home) [75.166.37.45]:55312 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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 * 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 + + * dwarf2read.c (quirk_rust_enum): Conditionally drop the + discriminant field. + 2018-03-29 Tom Tromey * 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,