[binutils-gdb] Fix Ada integer literals with exponents

Tom Tromey tromey@sourceware.org
Mon Mar 7 15:35:40 GMT 2022


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c9bfa277e9e6467dad91641357e09bf0a7ac0dc2

commit c9bfa277e9e6467dad91641357e09bf0a7ac0dc2
Author: Tom Tromey <tromey@adacore.com>
Date:   Wed Feb 16 12:01:52 2022 -0700

    Fix Ada integer literals with exponents
    
    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.

Diff:
---
 gdb/ada-lex.l                      |  9 ++++++---
 gdb/testsuite/gdb.ada/literals.exp | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index f698ad4dd57..e4f18f18605 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 <http://www.gnu.org/licenses/>.
+
+# 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"


More information about the Gdb-cvs mailing list