From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 39496 invoked by alias); 31 Oct 2016 03:13:52 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 38956 invoked by uid 89); 31 Oct 2016 03:13:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=rustc, H*RU:sk:gproxy1, H*RU:cmgw3, HX-HELO:sk:gproxy1 X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Mon, 31 Oct 2016 03:13:05 +0000 Received: (qmail 20041 invoked by uid 0); 31 Oct 2016 03:13:03 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy10.mail.unifiedlayer.com with SMTP; 31 Oct 2016 03:13:03 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 23Cz1u01i2f2jeq013D2pp; Sun, 30 Oct 2016 21:13:03 -0600 X-Authority-Analysis: v=2.1 cv=WL/sABcR c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=CH0kA5CcgfcA:10 a=BzObnAOqAAAA:8 a=ghYZxFToZOMGpY9v98QA:9 a=PuSIgb6VMkSJ0_1bSHE4:22 Received: from 174-16-143-211.hlrn.qwest.net ([174.16.143.211]:32922 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c131v-0007Iu-PM; Sun, 30 Oct 2016 21:12:59 -0600 From: Tom Tromey To: Manish Goregaokar Cc: gdb-patches@sourceware.org, Tom Tromey Subject: Re: [PATCH] Add support for untagged unions References: Date: Mon, 31 Oct 2016 03:13:00 -0000 In-Reply-To: (Manish Goregaokar's message of "Fri, 28 Oct 2016 18:02:12 -0700") Message-ID: <87shrdus79.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BWhitelist: no X-Exim-ID: 1c131v-0007Iu-PM X-Source-Sender: 174-16-143-211.hlrn.qwest.net (bapiya) [174.16.143.211]:32922 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-SW-Source: 2016-10/txt/msg00852.txt.bz2 >>>>> "Manish" == Manish Goregaokar writes: Manish> Rust supports untagged unions (C unions) now (using the same Manish> syntax as structs but with `union` instead of `struct` in the Manish> declaration). These are mainly used for FFI. Thank you. Manish> No tests because stable Rust doesn't have these yet. Let me know Manish> if I should add them. I think they're necessary but I want to understand the options. Is it hard to determine if rustc supports unions? Is there some flag that must be passed? I suppose one idea would be to feature test rustc in the test suite, then change the new tests to be unsupported if this fails. And, if a flag is needed, pass it -- but go back once the feature hits stable and remove the flag? I think the essentials of the patch are fine. Manish> * rust-lang.c (rust_union_is_untagged): Add function to Manish> check if a union is an untagged unioni Manish> * rust-lang.c (rust_val_print): Handle printing of untagged union values Just the first entry needs the "* FILENAME" bit. Manish> +/* Whether or not a TYPE_CODE_UNION value is an untagged union Manish> + as opposed to being a regular Rust enum. */ Manish> +static bool Manish> +rust_union_is_untagged(struct type *type) { This has various style issues. Thanks for using bool. Manish> + Since the field bit positions overlap in the debuginfo, Manish> + the code for printing a union is same as that for a struct, Manish> + the only difference is that the input type will have overlapping Manish> + fields. */ Manish> + if (rust_union_is_untagged (type)) Manish> + goto struct_val; I think it'd be better to turn the specific case's body into a helper function. I'd like to get rid of a lot of these gotos; and I also plan to remove as many cleanups as possible from the rust code in gdb... Manish> + /* This code path is also used by unions. */ Manish> + if (TYPE_CODE (type) == TYPE_CODE_STRUCT) Manish> + fputs_filtered ("struct ", stream); Manish> + else Manish> + fputs_filtered ("union ", stream); Manish> + Manish> if (TYPE_TAG_NAME (type) != NULL) Indentation of that addition looks wrong. Manish> + /* Field access in structs and untagged unions works like C. */ Manish> *pos = pc; Same here. Tom