]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix bug in Ada number lexing
authorTom Tromey <tromey@adacore.com>
Fri, 8 Apr 2022 16:11:58 +0000 (10:11 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 12 Apr 2022 18:59:28 +0000 (12:59 -0600)
On irc, Pedro pointed out that Ada couldn't properly handle
0xffffffffffffffff.  This used to work, but is a regression due to
some patches I wrote in the Ada lexer.  This patch fixes the bug.

gdb/ada-lex.l
gdb/testsuite/gdb.ada/literals.exp
gdb/testsuite/gdb.base/parse_number.exp

index 3980889f5ab727199e63ad8b85694e0a5c28f5ad..33a08eaa93b8cb1b30a1915da5e82feeda5f815f 100644 (file)
@@ -462,11 +462,11 @@ processInt (struct parser_state *par_state, const char *base0,
       return FLOAT;
     }
 
-  gdb_mpz maxval (ULONGEST_MAX / base);
+  gdb_mpz maxval (ULONGEST_MAX);
   if (mpz_cmp (result.val, maxval.val) > 0)
     error (_("Integer literal out of range"));
 
-  LONGEST value = result.as_integer<LONGEST> ();
+  ULONGEST value = result.as_integer<ULONGEST> ();
   if ((value >> (gdbarch_int_bit (par_state->gdbarch ())-1)) == 0)
     yylval.typed_val.type = type_int (par_state);
   else if ((value >> (gdbarch_long_bit (par_state->gdbarch ())-1)) == 0)
index 92a9a1954fc7ada7d56dd9d3d1093604b8b69d5c..a6ac89b540fdb5eace0c06ffa72fb18529fd5b7a 100644 (file)
@@ -34,3 +34,6 @@ 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"
+
+gdb_test "print/x 16#7fffffffffffffff#" " = 0x7fffffffffffffff"
+gdb_test "print 16#ffffffffffffffff#" " = -1"
index 8849c99a3f991d256aef1070f2c18dbdf19e80c0..dc6d358ca4889e2369478eaf498072c004c0b572 100644 (file)
@@ -28,7 +28,8 @@ proc test_parse_numbers {} {
 
        set val "0xffffffffffffffff"
        if {$lang == "ada"} {
-           gdb_test "p/x $val" "Integer literal out of range"
+           gdb_test "p/x $val" " = 0xffffffffffffffff"
+           gdb_test "ptype $val" " = <8-byte integer>"
        } elseif {$lang == "fortran"} {
            gdb_test "p/x $val" " = 0xffffffff"
            gdb_test "ptype $val" " = unsigned int"