From patchwork Tue Mar 28 15:49:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 67030 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5BFF83858004 for ; Tue, 28 Mar 2023 15:50:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BFF83858004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680018634; bh=eZflJ5ajI4rFMlpPyHD3KB/Rwl4AXFd5MJHS52lDXa4=; h=Date:Subject:References:In-Reply-To:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aE4bGsMtGNSUKv0wHNP1N86qcQwcv3XJ6kdFZsGE7JsPSpv86uFS5QC6cO3ppqObh 18xqLP2jPbIlNAEdC1HyM+VjOl/nunUF1Zek0UaS0ekaxHMxWAttsz4MQCqxbWO9M/ k870P1ARHXAg3ATA3AE14AgnvqXa8N04JokpiYSs= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id 1F6453857C5A for ; Tue, 28 Mar 2023 15:49:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F6453857C5A Received: by mail-io1-xd29.google.com with SMTP id n28so1128835ioz.11 for ; Tue, 28 Mar 2023 08:49:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680018581; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eZflJ5ajI4rFMlpPyHD3KB/Rwl4AXFd5MJHS52lDXa4=; b=7U9gnjWJ2PniBvfa1xv5zR3dAxSkpgmE1reN4+3TJ0H1FCNKHe6PtPDhFnlKZOpSrl uub2GLD2nY1JC99V03y9VQ70IkaahdDihXvUfzJ/amGphGEUTAbMtOVfH+cNLFyoU886 Qq5rBeIokkKYPyPmJpKOHBnxVrBg20aJBB24CC3MUXcWj7sYNHWtos+zijRnKwOILnGW H9AjVfnD7oGPPwrTsNkkXAFqsWCecFDyxCx7sQWDC4BpjaWTJtjTHMGmV8hM49RPqtMl Ykz8W0vaf5JAGaQgN9/DSipHXx27NjVn7cn8kvZD3BMsyDY6+6f+i0JQ6HpuePkUXfm4 WIAw== X-Gm-Message-State: AO0yUKWVMH3CtyMkjEOBMgdTdy5vOyAS6bLAt2hEmIHje81DC2xcJcTS BIHjzuBHuh7AgPBQOOoxp1voOV3XyGCb05srnsKfmQ== X-Google-Smtp-Source: AK7set/zb6deamkdgsqloz0dgWxZ6hKXEriwXIlC3+g5DzD7ial5lw5e+5Lfh99lRuEeUSmZjMIkTA== X-Received: by 2002:a05:6602:2052:b0:751:d1a9:964f with SMTP id z18-20020a056602205200b00751d1a9964fmr11621327iod.17.1680018581306; Tue, 28 Mar 2023 08:49:41 -0700 (PDT) Received: from localhost.localdomain (71-211-185-113.hlrn.qwest.net. [71.211.185.113]) by smtp.gmail.com with ESMTPSA id u5-20020a5ec005000000b0075c37601b5csm1684522iol.4.2023.03.28.08.49.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 08:49:41 -0700 (PDT) Date: Tue, 28 Mar 2023 09:49:39 -0600 Subject: [PATCH 3/6] Add 128-bit integer support to the Rust parser MIME-Version: 1.0 Message-Id: <20230328-expr-128-bit-v1-3-f9eeb0143318@adacore.com> References: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> In-Reply-To: <20230328-expr-128-bit-v1-0-f9eeb0143318@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This adds support for 128-bit integers to the Rust parser. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21185 --- gdb/rust-lang.c | 2 ++ gdb/rust-parse.c | 37 ++++++++++++++++++++------------- gdb/testsuite/gdb.base/parse_number.exp | 7 ++++--- gdb/testsuite/gdb.rust/onetwoeight.exp | 4 ++++ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index cb128f13f0e..3ef8fcaa329 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1607,6 +1607,8 @@ rust_language::language_arch_info (struct gdbarch *gdbarch, add (init_integer_type (alloc, 32, 1, "u32")); add (init_integer_type (alloc, 64, 0, "i64")); add (init_integer_type (alloc, 64, 1, "u64")); + add (init_integer_type (alloc, 128, 0, "i128")); + add (init_integer_type (alloc, 128, 1, "u128")); unsigned int length = 8 * builtin->builtin_data_ptr->length (); add (init_integer_type (alloc, length, 0, "isize")); diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index eca98aa286f..6c7922de9c7 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -69,7 +69,7 @@ static const char number_regex_text[] = #define INT_TEXT 5 #define INT_TYPE 6 "(0x[a-fA-F0-9_]+|0o[0-7_]+|0b[01_]+|[0-9][0-9_]*)" - "([iu](size|8|16|32|64))?" + "([iu](size|8|16|32|64|128))?" ")"; /* The number of subexpressions to allocate space for, including the "0th" whole match subexpression. */ @@ -126,7 +126,7 @@ enum token_type : int struct typed_val_int { - ULONGEST val; + gdb_mpz val; struct type *type; }; @@ -1007,7 +1007,6 @@ rust_parser::lex_number () /* Parse the number. */ if (is_integer) { - uint64_t value; int radix = 10; int offset = 0; @@ -1026,14 +1025,22 @@ rust_parser::lex_number () } } - const char *trailer; - value = strtoulst (number.c_str () + offset, &trailer, radix); - if (*trailer != '\0') - error (_("Integer literal is too large")); - if (implicit_i32 && value >= ((uint64_t) 1) << 31) - type = get_type ("i64"); + if (!current_int_val.val.set (number.c_str () + offset, radix)) + { + /* Shouldn't be possible. */ + error (_("Invalid integer")); + } + if (implicit_i32) + { + static gdb_mpz sixty_three_bit = gdb_mpz::pow (2, 63); + static gdb_mpz thirty_one_bit = gdb_mpz::pow (2, 31); + + if (current_int_val.val >= sixty_three_bit) + type = get_type ("i128"); + else if (current_int_val.val >= thirty_one_bit) + type = get_type ("i64"); + } - current_int_val.val = value; current_int_val.type = type; } else @@ -1556,9 +1563,11 @@ rust_parser::parse_field (operation_up &&lhs) break; case DECIMAL_INTEGER: - result = make_operation (current_int_val.val, - std::move (lhs)); - lex (); + { + int idx = current_int_val.val.as_integer (); + result = make_operation (idx, std::move (lhs)); + lex (); + } break; case INTEGER: @@ -1659,7 +1668,7 @@ rust_parser::parse_array_type () if (current_token != INTEGER && current_token != DECIMAL_INTEGER) error (_("integer expected")); - ULONGEST val = current_int_val.val; + ULONGEST val = current_int_val.val.as_integer (); lex (); require (']'); diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.base/parse_number.exp index 07104433a16..5dd4fa705e9 100644 --- a/gdb/testsuite/gdb.base/parse_number.exp +++ b/gdb/testsuite/gdb.base/parse_number.exp @@ -108,9 +108,10 @@ proc parse_number { lang n } { return [list "i32" $n] } elseif { [fits_in_type $n 64 s] } { return [list "i64" $n] - } elseif { [fits_in_type $n 64 u] } { - # Note: Interprets MAX_U64 as -1. - return [list "i64" $n] + } elseif { [fits_in_type $n 128 u] } { + return [list "i128" $n] + } elseif { [fits_in_type $n 128 u] } { + return [list "i128" $n] } else { # Overflow. return [list $re_overflow $re_overflow] diff --git a/gdb/testsuite/gdb.rust/onetwoeight.exp b/gdb/testsuite/gdb.rust/onetwoeight.exp index ef56bcafda2..5ca30712830 100644 --- a/gdb/testsuite/gdb.rust/onetwoeight.exp +++ b/gdb/testsuite/gdb.rust/onetwoeight.exp @@ -64,3 +64,7 @@ gdb_test "print x >> 2" "= 85070591730234615865843651857942052863" gdb_test "print/x x & mask" " = 0xf0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0" gdb_test "print/x x ^ mask" " = 0xf0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f" gdb_test "print/x mask | (mask >> 4)" " = 0xffffffffffffffffffffffffffffffff" + +gdb_test "print 170141183460469231731687303715884105727" \ + " = 170141183460469231731687303715884105727" +gdb_test "ptype 23i128" "type = i128"