[FIXED,1/1] rust-parse: Infer some integer constants as u64

Message ID 47-655f8d80-3-52811600@102229502
State New
Headers
Series [FIXED,1/1] rust-parse: Infer some integer constants as u64 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

The Puzzlemaker Nov. 23, 2023, 5:36 p.m. UTC
  This is a bit hacky, I admit. This commit causes integers in the range
`2^63-1 <= x <= 2^64 - 1` to be inferred as `u64` instead of as `i128`.
This helps solve an issue where these integers would not be able to be
used as addresses, helpful when e.g. debugging higher-half kernels.
---
 gdb/rust-parse.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Tom Tromey Nov. 25, 2023, 3:41 a.m. UTC | #1
>>>>> The Puzzlemaker <tpzker@thepuzzlemaker.info> writes:

> This is a bit hacky, I admit. This commit causes integers in the range
> `2^63-1 <= x <= 2^64 - 1` to be inferred as `u64` instead of as `i128`.
> This helps solve an issue where these integers would not be able to be
> used as addresses, helpful when e.g. debugging higher-half kernels.

Thanks for the patch.

I sent a different one for the same problem, that fixes it more
generically in value_cast.

> Sorry about the last email, my email client was not set up right for plaintext.
> See #31082, https://sourceware.org/bugzilla/show_bug.cgi?id=31082

> Let me know if there's anything I missed here.

If you stick "Bug: ... url of bug" as a git trailer, the eventual commit
will be mentioned in bugzilla.  We're trying to get this to happen for
patch submissions as well.

thanks,
Tom
  

Patch

diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 4b3348d8ca6..a807884bd20 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -1033,9 +1033,13 @@  rust_parser::lex_number ()
       if (implicit_i32)
 	{
 	 static gdb_mpz sixty_three_bit = gdb_mpz::pow (2, 63);
+	 static gdb_mpz sixty_four_bit = gdb_mpz::pow (2, 64);
 	 static gdb_mpz thirty_one_bit = gdb_mpz::pow (2, 31);
-
-	 if (current_int_val.val >= sixty_three_bit)
+	 static gdb_mpz thirty_two_bit = gdb_mpz::pow (2, 32);
+  
+	 if (current_int_val.val < sixty_four_bit && current_int_val.val >= thirty_two_bit)
+	   type = get_type ("u64");
+	 else if (current_int_val.val >= sixty_three_bit)
 	   type = get_type ("i128");
 	 else if (current_int_val.val >= thirty_one_bit)
 	   type = get_type ("i64");