From patchwork Mon Jul 11 21:10:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 13736 Received: (qmail 109841 invoked by alias); 11 Jul 2016 21:11:02 -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 109831 invoked by uid 89); 11 Jul 2016 21:11:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*F:U*tom, H*Ad:U*tom, bob, **result X-HELO: gproxy4-pub.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4-pub.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Mon, 11 Jul 2016 21:10:51 +0000 Received: (qmail 17776 invoked by uid 0); 11 Jul 2016 21:10:49 -0000 Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy4.mail.unifiedlayer.com with SMTP; 11 Jul 2016 21:10:49 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id HZAj1t00w2f2jeq01ZAmE5; Mon, 11 Jul 2016 15:10:49 -0600 X-Authority-Analysis: v=2.1 cv=ecGuId0H 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=PnD2wP_eR3oA:10 a=wTNNr4PC6uwA:10 a=cAmyUtKerLwA:10 a=zstS-IiYAAAA:8 a=QyXUC8HyAAAA:8 a=BPDDDUAHFKxfo1YVaJ8A:9 a=4G6NA9xxw8l3yy4pmD5M:22 a=avl4LiGQNoF5OB0DmCJ7:22 Received: from [65.128.62.222] (port=47526 helo=pokyo.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1bMiTT-0002Ed-DP; Mon, 11 Jul 2016 15:10:43 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Allow empty struct expressions in Rust Date: Mon, 11 Jul 2016 15:10:38 -0600 Message-Id: <1468271438-5389-1-git-send-email-tom@tromey.com> X-Identified-User: {36111:box522.bluehost.com:elynrobi:tromey.com} {sentby:smtp auth 65.128.62.222 authed with tom+tromey.com} X-Exim-ID: 1bMiTT-0002Ed-DP X-Source-Sender: (pokyo.Home) [65.128.62.222]:47526 X-Source-Auth: tom+tromey.com X-Email-Count: 0 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== I learned recently that empty struct expressions, like "X{}", have been promoted from experimental to stable in Rust. This patch changes the Rust expression parser to allow this case. New test case included. Built and regtested on x86-64 Fedora 23, using Rust 1.11 beta. I plan to check this in after a reasonable interval. 2016-07-11 Tom Tromey * rust-lang.c (rust_tuple_struct_type_p): Return false for empty structs. * rust-exp.y (struct_expr_list): Allow empty elements. 2016-07-11 Tom Tromey * gdb.rust/simple.rs (main): Use empty struct expression. * gdb.rust/simple.exp: Add tests for empty struct expression. --- gdb/ChangeLog | 6 ++++++ gdb/rust-exp.y | 10 +++++++--- gdb/rust-lang.c | 5 ++++- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.rust/simple.exp | 3 +++ gdb/testsuite/gdb.rust/simple.rs | 1 + 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 92c1337..dd678f5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2016-07-11 Tom Tromey + + * rust-lang.c (rust_tuple_struct_type_p): Return false for empty + structs. + * rust-exp.y (struct_expr_list): Allow empty elements. + 2016-07-07 Walfred Tedeschi * cp-namespace.c (cp_lookup_bare_symbol): Initialize diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index aeb6058..443c356 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -428,10 +428,14 @@ struct_expr_tail: } ; -/* S{} is documented as valid but seems to be an unstable feature, so - it is left out here. */ struct_expr_list: - struct_expr_tail + /* %empty */ + { + VEC (set_field) **result + = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *); + $$ = result; + } +| struct_expr_tail { VEC (set_field) **result = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *); diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 17b20c6..6e317fb 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -294,7 +294,10 @@ rust_underscore_fields (struct type *type, int offset) int rust_tuple_struct_type_p (struct type *type) { - return rust_underscore_fields (type, 0); + /* This is just an approximation until DWARF can represent Rust more + precisely. We exclude zero-length structs because they may not + be tuple structs, and there's no way to tell. */ + return TYPE_NFIELDS (type) > 0 && rust_underscore_fields (type, 0); } /* Return true if a variant TYPE is a tuple variant, false otherwise. */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b6f21d7..2eba208 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-07-11 Tom Tromey + + * gdb.rust/simple.rs (main): Use empty struct expression. + * gdb.rust/simple.exp: Add tests for empty struct expression. + 2016-07-07 Walfred Tedeschi * gdb.fortran/derived-types.exp (result_line, result_line_2): diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index 32b3785..5e00b03 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -55,7 +55,10 @@ gdb_test "print *(&c as *mut i32)" " = 0" gdb_test "print j" " = simple::Unit" gdb_test "ptype j" " = struct simple::Unit" +gdb_test "print j2" " = simple::Unit" +gdb_test "ptype j2" " = struct simple::Unit" gdb_test "print simple::Unit" " = simple::Unit" +gdb_test "print simple::Unit{}" " = simple::Unit" gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\"" gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]" diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index 4980826..eeff3d7 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -81,6 +81,7 @@ fn main () { let i = ["whatever"; 8]; let j = Unit; + let j2 = Unit{}; let k = SpaceSaver::Nothing; let l = SpaceSaver::Thebox(9, Box::new(1729));