From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id n9blEOvlhGJL5wYAWB0awg (envelope-from ) for ; Wed, 18 May 2022 08:26:19 -0400 Received: by simark.ca (Postfix, from userid 112) id 37AAF1E220; Wed, 18 May 2022 08:26:19 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=TzWTx4a0; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 80ED81E143 for ; Wed, 18 May 2022 08:26:18 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 083093856273 for ; Wed, 18 May 2022 12:26:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 083093856273 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1652876778; bh=kiX57SoyXSPbbzNcSDPU690F9buT2O/vMB6zpo0trkk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TzWTx4a0w+HG1mGdFuX55v8dVlMCgJLFQj+OvYG3OKmvFBe9v63bkEwR+/7OseJGR tiGcfVw/N2wyPdnpdfWvWfHpO6jRPJTXqAiotr0uWscwln3TvmT/wPeIbILEFUEP3T 9emllDJWRi60AAT9E3CUpxYqLThlwpbhhJP39l+8= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 444343856DED for ; Wed, 18 May 2022 12:25:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 444343856DED Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 64D531F8CD; Wed, 18 May 2022 12:25:58 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 43130133F5; Wed, 18 May 2022 12:25:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hyw+D9blhGJtbQAAMHmgww (envelope-from ); Wed, 18 May 2022 12:25:58 +0000 Date: Wed, 18 May 2022 14:25:56 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb/testsuite] Fix printing of 0x10000000000000000 Message-ID: <20220518122555.GA24256@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Cc: Tom Tromey , Andrew Burgess , Pedro Alves Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, When printing large literal constants we have an unexpected result for 0x10000000000000000: ... $ gdb -q -batch \ -ex "p /x 0xffffffffffffffff" \ -ex "p /x 0x10000000000000000" \ -ex "p /x 0x10000000000000001" $1 = 0xffffffffffffffff $2 = 0x0 Numeric constant too large. ... Fix this by fixing overflow detecting in parse_number, such that we have: ... $1 = 0xffffffffffffffff Numeric constant too large. Numeric constant too large. ... For rust, I've used as overflow string: "Integer literal is too large", based on what I found at /src/test/ui/parser/int-literal-too-large-span.rs but perhaps someone has a better idea. Don't fix this for modula-2, it makes more sense to do this as part of a parse_number rewrite to use ULONGEST, skip for now. Tested on x86_64-linux, with a build with --enable-targets=all. Any comments? Thanks, - Tom [gdb/testsuite] Fix printing of 0x10000000000000000 --- gdb/c-exp.y | 18 ++++++------------ gdb/f-exp.y | 15 +++++---------- gdb/go-exp.y | 16 +++++----------- gdb/p-exp.y | 16 +++++----------- gdb/rust-parse.c | 5 ++++- gdb/testsuite/gdb.base/parse_number.exp | 17 +++++++++++++++++ 6 files changed, 42 insertions(+), 45 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 72f8dd32d93..84bc0568e8f 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2095,18 +2095,12 @@ parse_number (struct parser_state *par_state, if (i >= base) return ERROR; /* Invalid digit in this base */ - /* Portably test for overflow (only works for nonzero values, so make - a second check for zero). FIXME: Can't we just make n and prevn - unsigned and avoid this? */ - if (c != 'l' && c != 'u' && c != 'i' && (prevn >= n) && n != 0) - unsigned_p = 1; /* Try something unsigned */ - - /* Portably test for unsigned overflow. - FIXME: This check is wrong; for example it doesn't find overflow - on 0x123456789 when LONGEST is 32 bits. */ - if (c != 'l' && c != 'u' && c != 'i' && n != 0) - { - if (unsigned_p && prevn >= n) + if (c != 'l' && c != 'u' && c != 'i') + { + /* Test for overflow. */ + if (prevn == 0 && n == 0) + ; + else if (prevn >= n) error (_("Numeric constant too large.")); } prevn = n; diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 90cc2c65c7b..124dfcb1b8f 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -1076,16 +1076,11 @@ parse_number (struct parser_state *par_state, n *= base; n += i; } - /* Portably test for overflow (only works for nonzero values, so make - a second check for zero). */ - if ((prevn >= n) && n != 0) - unsigned_p=1; /* Try something unsigned */ - /* If range checking enabled, portably test for unsigned overflow. */ - if (RANGE_CHECK && n != 0) - { - if ((unsigned_p && prevn >= n)) - range_error (_("Overflow on numeric constant.")); - } + /* Test for overflow. */ + if (prevn == 0 && n == 0) + ; + else if (RANGE_CHECK && prevn >= n) + range_error (_("Overflow on numeric constant.")); prevn = n; } diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 1b9b6ea7e90..8c9a558262f 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -777,18 +777,12 @@ parse_number (struct parser_state *par_state, if (i >= base) return ERROR; /* Invalid digit in this base. */ - /* Portably test for overflow (only works for nonzero values, so make - a second check for zero). FIXME: Can't we just make n and prevn - unsigned and avoid this? */ - if (c != 'l' && c != 'u' && (prevn >= n) && n != 0) - unsigned_p = 1; /* Try something unsigned. */ - - /* Portably test for unsigned overflow. - FIXME: This check is wrong; for example it doesn't find overflow - on 0x123456789 when LONGEST is 32 bits. */ - if (c != 'l' && c != 'u' && n != 0) + if (c != 'l' && c != 'u') { - if ((unsigned_p && prevn >= n)) + /* Test for overflow. */ + if (n == 0 && prevn == 0) + ; + else if (prevn >= n) error (_("Numeric constant too large.")); } prevn = n; diff --git a/gdb/p-exp.y b/gdb/p-exp.y index 7c88df65e69..7e119963759 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -919,18 +919,12 @@ parse_number (struct parser_state *par_state, if (i >= base) return ERROR; /* Invalid digit in this base. */ - /* Portably test for overflow (only works for nonzero values, so make - a second check for zero). FIXME: Can't we just make n and prevn - unsigned and avoid this? */ - if (c != 'l' && c != 'u' && (prevn >= n) && n != 0) - unsigned_p = 1; /* Try something unsigned. */ - - /* Portably test for unsigned overflow. - FIXME: This check is wrong; for example it doesn't find overflow - on 0x123456789 when LONGEST is 32 bits. */ - if (c != 'l' && c != 'u' && n != 0) + if (c != 'l' && c != 'u') { - if (unsigned_p && prevn >= n) + /* Test for overflow. */ + if (prevn == 0 && n == 0) + ; + else if (prevn >= n) error (_("Numeric constant too large.")); } prevn = n; diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 7d7d882872c..836f49108f8 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -1024,7 +1024,10 @@ rust_parser::lex_number () } } - value = strtoulst (number.c_str () + offset, NULL, radix); + 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"); diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.base/parse_number.exp index 444f5d0534b..60526f5612a 100644 --- a/gdb/testsuite/gdb.base/parse_number.exp +++ b/gdb/testsuite/gdb.base/parse_number.exp @@ -68,6 +68,16 @@ proc test_parse_numbers {arch} { gdb_test_no_output "set language $lang" + if { $lang == "modula-2" || $lang == "fortran" } { + set re_overflow "Overflow on numeric constant\\." + } elseif { $lang == "ada" } { + set re_overflow "Integer literal out of range" + } elseif { $lang == "rust" } { + set re_overflow "Integer literal is too large" + } else { + set re_overflow "Numeric constant too large\\." + } + set val "0xffffffffffffffff" set val [hex_for_lang $lang $val] if {$lang == "fortran"} { @@ -98,6 +108,13 @@ proc test_parse_numbers {arch} { gdb_test "ptype $val" " = $8B_type" } } + + if { $lang == "modula-2" } { + continue + } + + set val [hex_for_lang $lang "10000000000000000"] + gdb_test "p/x $val" $re_overflow } }