From patchwork Tue Apr 9 19:21:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32229 Received: (qmail 74226 invoked by alias); 9 Apr 2019 19:21: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 74214 invoked by uid 89); 9 Apr 2019 19:21:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=Ivan, ivan, sk:rust_le, HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Apr 2019 19:21:04 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id E8A24560A4; Tue, 9 Apr 2019 15:21:02 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2qm2ief+JTJ0; Tue, 9 Apr 2019 15:21:02 -0400 (EDT) Received: from murgatroyd.Home (174-29-37-56.hlrn.qwest.net [174.29.37.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 8FC9A560A3; Tue, 9 Apr 2019 15:21:02 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Fix Rust lexer buglet Date: Tue, 9 Apr 2019 13:21:00 -0600 Message-Id: <20190409192100.13780-1-tromey@adacore.com> MIME-Version: 1.0 PR rust/24414 points out that the Rust lexer uses strtoul when lexing an integer, and that this can give the wrong results in some situations. This patch changes it to use strtoulst, like most of the rest of gdb. It also adds a self test. Tested on x86-64 Fedora 29 using an i686 build. gdb/ChangeLog 2019-04-09 Ivan Begert Tom Tromey PR rust/24414: * rust-exp.y (rust_parser::lex_number): Use strtoulst. (rust_lex_int_test): Change "value" to be LONGEST. (rust_lex_tests): Add test for long integer literal. --- gdb/ChangeLog | 8 ++++++++ gdb/rust-exp.y | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y index 2be2532eb84..15932638397 100644 --- a/gdb/rust-exp.y +++ b/gdb/rust-exp.y @@ -1610,7 +1610,7 @@ rust_parser::lex_number (YYSTYPE *lvalp) } } - value = strtoul (number.c_str () + offset, NULL, radix); + value = strtoulst (number.c_str () + offset, NULL, radix); if (implicit_i32 && value >= ((uint64_t) 1) << 31) type = get_type ("i64"); @@ -2603,7 +2603,8 @@ rust_lex_test_one (rust_parser *parser, const char *input, int expected) /* Test that INPUT lexes as the integer VALUE. */ static void -rust_lex_int_test (rust_parser *parser, const char *input, int value, int kind) +rust_lex_int_test (rust_parser *parser, const char *input, + LONGEST value, int kind) { RUSTSTYPE result = rust_lex_test_one (parser, input, kind); SELF_CHECK (result.typed_val_int.val == value); @@ -2781,6 +2782,7 @@ rust_lex_tests (void) rust_lex_int_test (&parser, "0x1_f", 0x1f, INTEGER); rust_lex_int_test (&parser, "0b1_101011__", 0x6b, INTEGER); rust_lex_int_test (&parser, "0o001177i64", 639, INTEGER); + rust_lex_int_test (&parser, "0x123456789u64", 0x123456789ull, INTEGER); rust_lex_test_trailing_dot (&parser);