From patchwork Wed Feb 28 15:55:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26121 Received: (qmail 5017 invoked by alias); 28 Feb 2018 15:55:10 -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 4989 invoked by uid 89); 28 Feb 2018 15:55:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 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= X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Feb 2018 15:55:08 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway22.websitewelcome.com (Postfix) with ESMTP id EEFBA14454 for ; Wed, 28 Feb 2018 09:55:06 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id r44Qe9SUsiQI2r44QeiE1e; Wed, 28 Feb 2018 09:55:06 -0600 Received: from 174-29-60-18.hlrn.qwest.net ([174.29.60.18]:34102 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1er44Q-001gNB-NY; Wed, 28 Feb 2018 09:55:06 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [v2] Fix Rust enum test failures Date: Wed, 28 Feb 2018 08:55:03 -0700 Message-Id: <20180228155503.24537-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1er44Q-001gNB-NY X-Source-Sender: 174-29-60-18.hlrn.qwest.net (pokyo.Home) [174.29.60.18]:34102 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes Pedro pointed out that some Rust tests were failing after the recent enum change. I was able to reproduce this even with the most current Rust compiler -- no test was failing, but rather the gdb internal error was causing an "untested" result, which I didn't notice. The internal error is caused by a bad assertion in alloc_discriminant_info. This happened because, in an earlier version of the patch, the discriminant could only appear at index 0. However, it can now appear anywhere. This patch fixes the assertion in the obvious way, and adds a second assertion to ensure that the discriminant is also correct. Fixing this revealed a real failure, which was caused by using the wrong base name when computing the name of a univariant enum's sole member. This is also fixed here. Tested by running the gdb.rust tests with rustc 1.23 and double-checking the summary: # of expected passes 276 Note that if you try this yourself, it is still possible to get an "untested" result from traits.exp if your Rust compiler is old enough. 2018-02-28 Tom Tromey * dwarf2read.c (alloc_discriminant_info): Fix default_index assertion. Add assertion for discriminant_index. (quirk_rust_enum): Use correct base type name in univariant case. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2read.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8ab6381add..5d2778fc06 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-02-28 Tom Tromey + + * dwarf2read.c (alloc_discriminant_info): Fix default_index + assertion. Add assertion for discriminant_index. + (quirk_rust_enum): Use correct base type name in univariant case. + 2018-02-28 John Baldwin * fbsd-nat.c (fbsd_resume): Use PT_SETSTEP for stepping and a diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 1e4376e4de..aea46d50c0 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10363,8 +10363,11 @@ alloc_discriminant_info (struct type *type, int discriminant_index, int default_index) { gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION); + gdb_assert (discriminant_index == -1 + || (discriminant_index >= 0 + && discriminant_index < TYPE_NFIELDS (type))); gdb_assert (default_index == -1 - || (default_index > 0 && default_index < TYPE_NFIELDS (type))); + || (default_index >= 0 && default_index < TYPE_NFIELDS (type))); TYPE_FLAG_DISCRIMINATED_UNION (type) = 1; @@ -10517,7 +10520,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile) TYPE_FIELD_NAME (union_type, 0) = variant_name; TYPE_NAME (field_type) = rust_fully_qualify (&objfile->objfile_obstack, - TYPE_NAME (field_type), variant_name); + TYPE_NAME (type), variant_name); /* Install the union in the outer struct type. */ TYPE_NFIELDS (type) = 1;