diff mbox

Fix PR rust/20110

Message ID 1465220495-4388-1-git-send-email-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey June 6, 2016, 1:41 p.m. UTC
PR rust/20110 concerns the type of an integer constant that is too
large for "i32", the default integer type.  This patch changes the
type of such a constant to i64.  This is important because such values
are often addresses, so truncating them by default is unfriendly.

Built and regtested on x86-64 Fedora 23.

I plan to check this in after some a reasonable interval.

2016-06-04  Tom Tromey  <tom@tromey.com>

	PR rust/20110:
	* rust-exp.y (lex_number): Don't truncate large numbers to i32.

2016-06-04  Tom Tromey  <tom@tromey.com>

	PR rust/20110:
	* gdb.rust/expr.exp: Add test for integer constant larger than
	i32.
---
 gdb/ChangeLog                   |  5 +++++
 gdb/rust-exp.y                  | 15 +++++++++++++--
 gdb/testsuite/ChangeLog         |  6 ++++++
 gdb/testsuite/gdb.rust/expr.exp |  2 ++
 4 files changed, 26 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a163b38..fb99fb5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@ 
 2016-06-04  Tom Tromey  <tom@tromey.com>
 
+	PR rust/20110:
+	* rust-exp.y (lex_number): Don't truncate large numbers to i32.
+
+2016-06-04  Tom Tromey  <tom@tromey.com>
+
 	* Makefile.in (COMMON_OBS): Remove rust-exp.o.
 	(YYFILES): Add rust-exp.c.
 	(YYOBJ): Add rust-exp.o.
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index c1a863c..aeb6058 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -1418,6 +1418,7 @@  lex_number (void)
   int match;
   int is_integer = 0;
   int could_be_decimal = 1;
+  int implicit_i32 = 0;
   char *type_name = NULL;
   struct type *type;
   int end_index;
@@ -1436,7 +1437,10 @@  lex_number (void)
       is_integer = 1;
       end_index = subexps[INT_TEXT].rm_eo;
       if (subexps[INT_TYPE].rm_so == -1)
-	type_name = "i32";
+	{
+	  type_name = "i32";
+	  implicit_i32 = 1;
+	}
       else
 	{
 	  type_index = INT_TYPE;
@@ -1478,6 +1482,7 @@  lex_number (void)
 	  end_index = subexps[0].rm_eo;
 	  type_name = "i32";
 	  could_be_decimal = 1;
+	  implicit_i32 = 1;
 	}
     }
 
@@ -1512,6 +1517,7 @@  lex_number (void)
   /* Parse the number.  */
   if (is_integer)
     {
+      uint64_t value;
       int radix = 10;
       if (number[0] == '0')
 	{
@@ -1527,7 +1533,12 @@  lex_number (void)
 	      could_be_decimal = 0;
 	    }
 	}
-      rustyylval.typed_val_int.val = strtoul (number, NULL, radix);
+
+      value = strtoul (number, NULL, radix);
+      if (implicit_i32 && value >= ((uint64_t) 1) << 31)
+	type = rust_type ("i64");
+
+      rustyylval.typed_val_int.val = value;
       rustyylval.typed_val_int.type = type;
     }
   else
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 3b305a6..c075f22 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@ 
+2016-06-04  Tom Tromey  <tom@tromey.com>
+
+	PR rust/20110:
+	* gdb.rust/expr.exp: Add test for integer constant larger than
+	i32.
+
 2016-06-02  Tom Tromey  <tom@tromey.com>
 
 	PR python/18984:
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
index 99a697e..fff3eef 100644
--- a/gdb/testsuite/gdb.rust/expr.exp
+++ b/gdb/testsuite/gdb.rust/expr.exp
@@ -104,6 +104,8 @@  gdb_test "print 1 << 5" " = 32"
 gdb_test "print 32usize >> 5" " = 1"
 gdb_test "ptype 32i32 as f64" "type = f64"
 
+gdb_test "ptype 0xf9f9f9f90000" "type = i64"
+
 gdb_test "print ()" " = \\(\\)"
 
 gdb_test "print \[1,2,3,4\]" " = \\\[1, 2, 3, 4\\\]"