From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id AFC843858C60 for ; Tue, 1 Mar 2022 17:00:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AFC843858C60 Received: by mail-io1-xd36.google.com with SMTP id r8so5588658ioj.9 for ; Tue, 01 Mar 2022 09:00:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5rVA0OIoQTO7seTAdlqsxmvO2kOEkZGtz+9P+cDbniw=; b=Zk+wLCO2m1dPvEvYNrGwZ4sS2VK1XorU6s4nWp8A8GnnLJOX43EwEsa4qU0SFIb7vo 4sEZf7d3XnqIOXkJrP39mJA4lmt5TXIwBqwgRF3pTcvIj0Sru6tANFchCcOCTv8++JvE X8rMUIppLxV/GJ/uIGEi1CdMSvYQi4VHahsxE40ddrTLgZ4eb1Sksv+WrI52oYpV8fu3 YwSu27bT+Abt8GP1Q1h1bvz+uzsJLCoh4BS41+7NWnDT/ymqVzpSX5FfNQb9CZmyx8j3 nmqT6frI4QkfjLC/syI/U+6cRqW//s6u20pQ+PCwIGuYQC+2X/yqcsVH0X7w6gJ1NA75 jcXA== X-Gm-Message-State: AOAM533DxHwUZ7Tm7eHsTZn0SSmmqofTM+Ik11lD+F00sGyFSlvDNyMW 5Ehqf95kOmNOIZU7YxRq6JdFgkC/5u0+CQ== X-Google-Smtp-Source: ABdhPJy3iUP7JIfqJp7F7olRS5ib334CBjv+g8TaRJN7nN+pDUAxxZWhO4KavxVbJtkepgvsDgqEVg== X-Received: by 2002:a02:2406:0:b0:317:1aea:c8a4 with SMTP id f6-20020a022406000000b003171aeac8a4mr13945162jaa.65.1646154057967; Tue, 01 Mar 2022 09:00:57 -0800 (PST) Received: from murgatroyd.Home (75-166-141-253.hlrn.qwest.net. [75.166.141.253]) by smtp.gmail.com with ESMTPSA id 6-20020a056e0211a600b002c2494a5479sm8214281ilj.2.2022.03.01.09.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Mar 2022 09:00:57 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] Fix Ada integer literals with exponents Date: Tue, 1 Mar 2022 10:00:53 -0700 Message-Id: <20220301170055.1520935-2-tromey@adacore.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220301170055.1520935-1-tromey@adacore.com> References: <20220301170055.1520935-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Tue, 01 Mar 2022 17:01:03 -0000 While working on another patch, I noticed that Ada integer literals with exponents did not work. For example, with one form you get an error: (gdb) print 8e2 Invalid digit `e' in based literal And with another form you get an incorrect value: (gdb) print 16#8#e2 $2 = 8 This patch fixes the bugs and adds tests. --- gdb/ada-lex.l | 9 +++++--- gdb/testsuite/gdb.ada/literals.exp | 36 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/literals.exp diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l index f61efba81a9..aab53b397ec 100644 --- a/gdb/ada-lex.l +++ b/gdb/ada-lex.l @@ -103,8 +103,9 @@ static int paren_depth; {NUM10}{POSEXP} { canonicalizeNumeral (numbuf, yytext); - return processInt (pstate, NULL, numbuf, - strrchr (numbuf, 'e') + 1); + char *e_ptr = strrchr (numbuf, 'e'); + *e_ptr = '\0'; + return processInt (pstate, nullptr, numbuf, e_ptr + 1); } {NUM10} { @@ -114,9 +115,11 @@ static int paren_depth; {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#"{POSEXP} { canonicalizeNumeral (numbuf, yytext); + char *e_ptr = strrchr (numbuf, 'e'); + *e_ptr = '\0'; return processInt (pstate, numbuf, strchr (numbuf, '#') + 1, - strrchr(numbuf, '#') + 1); + e_ptr + 1); } {NUM10}"#"{HEXDIG}({HEXDIG}|_)*"#" { diff --git a/gdb/testsuite/gdb.ada/literals.exp b/gdb/testsuite/gdb.ada/literals.exp new file mode 100644 index 00000000000..92a9a1954fc --- /dev/null +++ b/gdb/testsuite/gdb.ada/literals.exp @@ -0,0 +1,36 @@ +# Copyright 2022 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test some literal syntax. + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +clean_restart + +gdb_test_no_output "set lang ada" +gdb_test "print 7#10#" " = 7" +gdb_test "print 77#10#" "Invalid base: 77." +gdb_test "print 7#8#" "Invalid digit `8' in based literal" + +gdb_test "print 8e2" " = 800" +gdb_test "print 9999999999999999999999999999999999999999999999" \ + "Integer literal out of range" +gdb_test "print 2e1000" "Integer literal out of range" + +gdb_test "print 16#ffff#" " = 65535" +gdb_test "print 16#f#e1" " = 240" +gdb_test "print 16#1#e10" " = 1099511627776" -- 2.31.1