From patchwork Mon Jun 6 13:41:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 12795 Received: (qmail 82147 invoked by alias); 6 Jun 2016 13:42:06 -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 82110 invoked by uid 89); 6 Jun 2016 13:42:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, FSL_HELO_HOME, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=sk:3b305a6, 1234, H*MI:tom X-HELO: gproxy1-pub.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1-pub.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with SMTP; Mon, 06 Jun 2016 13:41:55 +0000 Received: (qmail 21828 invoked by uid 0); 6 Jun 2016 13:41:54 -0000 Received: from unknown (HELO cmgw3) (10.0.90.84) by gproxy1.mail.unifiedlayer.com with SMTP; 6 Jun 2016 13:41:54 -0000 Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 3Rhn1t00M2f2jeq01Rhq9Q; Mon, 06 Jun 2016 07:41:53 -0600 X-Authority-Analysis: v=2.1 cv=KpLehwmN 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=-N9Dh3nx2ZYA:10 a=pD_ry4oyNxEA:10 a=zstS-IiYAAAA:8 a=RlHvSrwEERLLXQ724KQA:9 a=UBuo5PP0h2SwqDOP:21 a=htI3UTkjEjKuhLIz:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from [65.128.48.199] (port=44588 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_2) (envelope-from ) id 1b9ump-000257-1C; Mon, 06 Jun 2016 07:41:47 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix PR rust/20110 Date: Mon, 6 Jun 2016 07:41:35 -0600 Message-Id: <1465220495-4388-1-git-send-email-tom@tromey.com> X-Identified-User: {36111:box522.bluehost.com:elynrobi:tromey.com} {sentby:smtp auth 65.128.48.199 authed with tom+tromey.com} X-Exim-ID: 1b9ump-000257-1C X-Source-Sender: (bapiya.Home) [65.128.48.199]:44588 X-Source-Auth: tom+tromey.com X-Email-Count: 0 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== PR rust/20110 concerns the type of an integer constant that is too large for "i32", the default integer type. This patch changes the type of such a constant to i64. This is important because such values are often addresses, so truncating them by default is unfriendly. Built and regtested on x86-64 Fedora 23. I plan to check this in after some a reasonable interval. 2016-06-04 Tom Tromey PR rust/20110: * rust-exp.y (lex_number): Don't truncate large numbers to i32. 2016-06-04 Tom Tromey PR rust/20110: * gdb.rust/expr.exp: Add test for integer constant larger than i32. --- gdb/ChangeLog | 5 +++++ gdb/rust-exp.y | 15 +++++++++++++-- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.rust/expr.exp | 2 ++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a163b38..fb99fb5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2016-06-04 Tom Tromey + PR rust/20110: + * rust-exp.y (lex_number): Don't truncate large numbers to i32. + +2016-06-04 Tom Tromey + * Makefile.in (COMMON_OBS): Remove rust-exp.o. (YYFILES): Add rust-exp.c. (YYOBJ): Add rust-exp.o. diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index c1a863c..aeb6058 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -1418,6 +1418,7 @@ lex_number (void) int match; int is_integer = 0; int could_be_decimal = 1; + int implicit_i32 = 0; char *type_name = NULL; struct type *type; int end_index; @@ -1436,7 +1437,10 @@ lex_number (void) is_integer = 1; end_index = subexps[INT_TEXT].rm_eo; if (subexps[INT_TYPE].rm_so == -1) - type_name = "i32"; + { + type_name = "i32"; + implicit_i32 = 1; + } else { type_index = INT_TYPE; @@ -1478,6 +1482,7 @@ lex_number (void) end_index = subexps[0].rm_eo; type_name = "i32"; could_be_decimal = 1; + implicit_i32 = 1; } } @@ -1512,6 +1517,7 @@ lex_number (void) /* Parse the number. */ if (is_integer) { + uint64_t value; int radix = 10; if (number[0] == '0') { @@ -1527,7 +1533,12 @@ lex_number (void) could_be_decimal = 0; } } - rustyylval.typed_val_int.val = strtoul (number, NULL, radix); + + value = strtoul (number, NULL, radix); + if (implicit_i32 && value >= ((uint64_t) 1) << 31) + type = rust_type ("i64"); + + rustyylval.typed_val_int.val = value; rustyylval.typed_val_int.type = type; } else diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 3b305a6..c075f22 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-06-04 Tom Tromey + + PR rust/20110: + * gdb.rust/expr.exp: Add test for integer constant larger than + i32. + 2016-06-02 Tom Tromey PR python/18984: diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp index 99a697e..fff3eef 100644 --- a/gdb/testsuite/gdb.rust/expr.exp +++ b/gdb/testsuite/gdb.rust/expr.exp @@ -104,6 +104,8 @@ gdb_test "print 1 << 5" " = 32" gdb_test "print 32usize >> 5" " = 1" gdb_test "ptype 32i32 as f64" "type = f64" +gdb_test "ptype 0xf9f9f9f90000" "type = i64" + gdb_test "print ()" " = \\(\\)" gdb_test "print \[1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"