public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH + 12.1] Fix bug in Ada number lexing
@ 2022-04-08 19:27 Tom Tromey
  2022-04-08 19:31 ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2022-04-08 19:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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                      | 4 ++--
 gdb/testsuite/gdb.ada/literals.exp | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 3980889f5ab..33a08eaa93b 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -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)
diff --git a/gdb/testsuite/gdb.ada/literals.exp b/gdb/testsuite/gdb.ada/literals.exp
index 92a9a1954fc..a6ac89b540f 100644
--- a/gdb/testsuite/gdb.ada/literals.exp
+++ b/gdb/testsuite/gdb.ada/literals.exp
@@ -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"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH + 12.1] Fix bug in Ada number lexing
  2022-04-08 19:27 [PATCH + 12.1] Fix bug in Ada number lexing Tom Tromey
@ 2022-04-08 19:31 ` Pedro Alves
  2022-04-12 18:39   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2022-04-08 19:31 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2022-04-08 20:27, Tom Tromey via Gdb-patches wrote:
> 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.

Oh, cool, thanks.  I believe you need to fix gdb.base/parse_number.exp too, though:

        set val "0xffffffffffffffff"
        if {$lang == "ada"} {
            gdb_test "p/x $val" "Integer literal out of range"

If I'm right, please add a matching ptype like for other languages in that loop.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH + 12.1] Fix bug in Ada number lexing
  2022-04-08 19:31 ` Pedro Alves
@ 2022-04-12 18:39   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2022-04-12 18:39 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

Pedro> Oh, cool, thanks.  I believe you need to fix
Pedro> gdb.base/parse_number.exp too, though:

Yep, thanks.

Pedro>         set val "0xffffffffffffffff"
Pedro>         if {$lang == "ada"} {
Pedro>             gdb_test "p/x $val" "Integer literal out of range"

Pedro> If I'm right, please add a matching ptype like for other languages in that loop.

I did this and I'm going to check this in.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-12 18:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08 19:27 [PATCH + 12.1] Fix bug in Ada number lexing Tom Tromey
2022-04-08 19:31 ` Pedro Alves
2022-04-12 18:39   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).