Blame SOURCES/gcc32-java-intlex.patch

4ac4fd
2002-11-05  Tom Tromey  <tromey@redhat.com>
4ac4fd
4ac4fd
	Fix for PR java/6388.
4ac4fd
	* lex.h (JAVA_INTEGRAL_RANGE_ERROR): Wrap in do...while.
4ac4fd
	* java-tree.h (enum java_tree_index): New values
4ac4fd
	JTI_DECIMAL_INT_MAX_NODE, JTI_DECIMAL_LONG_MAX_NODE.
4ac4fd
	(decimal_int_max, decimal_long_max): New defines.
4ac4fd
	* lex.c (yylex): Rewrote range checking.  Sign extend literals.
4ac4fd
	(error_if_numeric_overflow): Rewrote range checking.
4ac4fd
	* decl.c (java_init_decl_processing): Initialize decimal_int_max,
4ac4fd
	decimal_long_max.
4ac4fd
4ac4fd
--- gcc/java/decl.c	2 Nov 2002 21:29:36 -0000	1.134
4ac4fd
+++ gcc/java/decl.c	6 Nov 2002 00:01:00 -0000	1.135
4ac4fd
@@ -454,6 +454,20 @@ java_init_decl_processing ()
4ac4fd
   integer_four_node = build_int_2 (4, 0);
4ac4fd
   integer_minus_one_node = build_int_2 (-1, -1);
4ac4fd
 
4ac4fd
+  /* A few values used for range checking in the lexer.  */
4ac4fd
+  decimal_int_max = build_int_2 (0x80000000, 0);
4ac4fd
+  TREE_TYPE (decimal_int_max) = unsigned_int_type_node;
4ac4fd
+#if HOST_BITS_PER_WIDE_INT == 64
4ac4fd
+  decimal_long_max = build_int_2 (0x8000000000000000, 0);
4ac4fd
+#else
4ac4fd
+#if HOST_BITS_PER_WIDE_INT == 32
4ac4fd
+  decimal_long_max = build_int_2 (0, 0x80000000);
4ac4fd
+#else
4ac4fd
+ #error "unsupported size"
4ac4fd
+#endif
4ac4fd
+#endif
4ac4fd
+  TREE_TYPE (decimal_long_max) = unsigned_long_type_node;
4ac4fd
+
4ac4fd
   size_zero_node = size_int (0);
4ac4fd
   size_one_node = size_int (1);
4ac4fd
   bitsize_zero_node = bitsize_int (0);
4ac4fd
--- gcc/java/java-tree.h	2 Nov 2002 23:52:26 -0000	1.161
4ac4fd
+++ gcc/java/java-tree.h	6 Nov 2002 00:01:00 -0000	1.162
4ac4fd
@@ -275,6 +275,9 @@ enum java_tree_index
4ac4fd
   JTI_UNSIGNED_INT_TYPE_NODE,
4ac4fd
   JTI_UNSIGNED_LONG_TYPE_NODE,
4ac4fd
   
4ac4fd
+  JTI_DECIMAL_INT_MAX_NODE,
4ac4fd
+  JTI_DECIMAL_LONG_MAX_NODE,
4ac4fd
+
4ac4fd
   JTI_BOOLEAN_TYPE_NODE,
4ac4fd
 
4ac4fd
   JTI_OBJECT_TYPE_NODE,
4ac4fd
@@ -441,6 +444,11 @@ extern GTY(()) tree java_global_trees[JT
4ac4fd
 #define unsigned_long_type_node \
4ac4fd
   java_global_trees[JTI_UNSIGNED_LONG_TYPE_NODE]
4ac4fd
 
4ac4fd
+#define decimal_int_max \
4ac4fd
+  java_global_trees[JTI_DECIMAL_INT_MAX_NODE]
4ac4fd
+#define decimal_long_max \
4ac4fd
+  java_global_trees[JTI_DECIMAL_LONG_MAX_NODE]
4ac4fd
+
4ac4fd
 #define boolean_type_node \
4ac4fd
   java_global_trees[JTI_BOOLEAN_TYPE_NODE]
4ac4fd
 
4ac4fd
--- gcc/java/lex.c	2 Nov 2002 21:29:36 -0000	1.94
4ac4fd
+++ gcc/java/lex.c	6 Nov 2002 00:01:01 -0000	1.95
4ac4fd
@@ -1218,34 +1218,35 @@ java_lex (java_lval)
4ac4fd
 	}
4ac4fd
       /* End borrowed section.  */
4ac4fd
 
4ac4fd
+#ifndef JC1_LITE
4ac4fd
       /* Range checking.  */
4ac4fd
-      if (long_suffix)
4ac4fd
+      value = build_int_2 (low, high);
4ac4fd
+      /* Temporarily set type to unsigned.  */
4ac4fd
+      SET_LVAL_NODE_TYPE (value, (long_suffix
4ac4fd
+				  ? unsigned_long_type_node
4ac4fd
+				  : unsigned_int_type_node));
4ac4fd
+
4ac4fd
+      /* For base 10 numbers, only values up to the highest value
4ac4fd
+	 (plus one) can be written.  For instance, only ints up to
4ac4fd
+	 2147483648 can be written.  The special case of the largest
4ac4fd
+	 negative value is handled elsewhere.  For other bases, any
4ac4fd
+	 number can be represented.  */
4ac4fd
+      if (overflow || (radix == 10
4ac4fd
+		       && tree_int_cst_lt (long_suffix
4ac4fd
+					   ? decimal_long_max
4ac4fd
+					   : decimal_int_max,
4ac4fd
+					   value)))
4ac4fd
 	{
4ac4fd
-	  /* 9223372036854775808L is valid if operand of a '-'. Otherwise
4ac4fd
-	     9223372036854775807L is the biggest `long' literal that can be
4ac4fd
-	     expressed using a 10 radix. For other radices, everything that
4ac4fd
-	     fits withing 64 bits is OK.  */
4ac4fd
-	  int hb = (high >> 31);
4ac4fd
-	  if (overflow || (hb && low && radix == 10)
4ac4fd
-	      || (hb && high & 0x7fffffff && radix == 10))
4ac4fd
+	  if (long_suffix)
4ac4fd
 	    JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `long' literal");
4ac4fd
-	}
4ac4fd
-      else
4ac4fd
-	{
4ac4fd
-	  /* 2147483648 is valid if operand of a '-'. Otherwise,
4ac4fd
-	     2147483647 is the biggest `int' literal that can be
4ac4fd
-	     expressed using a 10 radix. For other radices, everything
4ac4fd
-	     that fits within 32 bits is OK.  As all literals are
4ac4fd
-	     signed, we sign extend here.  */
4ac4fd
-	  int hb = (low >> 31) & 0x1;
4ac4fd
-	  if (overflow || high || (hb && low & 0x7fffffff && radix == 10))
4ac4fd
+	  else
4ac4fd
 	    JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `int' literal");
4ac4fd
-	  high = -hb;
4ac4fd
 	}
4ac4fd
-#ifndef JC1_LITE
4ac4fd
-      value = build_int_2 (low, high);
4ac4fd
+
4ac4fd
+      /* Sign extend the value.  */
4ac4fd
+      SET_LVAL_NODE_TYPE (value, (long_suffix ? long_type_node : int_type_node));
4ac4fd
+      force_fit_type (value, 0);
4ac4fd
       JAVA_RADIX10_FLAG (value) = radix == 10;
4ac4fd
-      SET_LVAL_NODE_TYPE (value, long_suffix ? long_type_node : int_type_node);
4ac4fd
 #else
4ac4fd
       SET_LVAL_NODE_TYPE (build_int_2 (low, high),
4ac4fd
 			  long_suffix ? long_type_node : int_type_node);
4ac4fd
@@ -1661,24 +1662,14 @@ static void
4ac4fd
 error_if_numeric_overflow (value)
4ac4fd
      tree value;
4ac4fd
 {
4ac4fd
-  if (TREE_CODE (value) == INTEGER_CST && JAVA_RADIX10_FLAG (value))
4ac4fd
+  if (TREE_CODE (value) == INTEGER_CST
4ac4fd
+      && JAVA_RADIX10_FLAG (value)
4ac4fd
+      && tree_int_cst_sgn (value) < 0)
4ac4fd
     {
4ac4fd
-      unsigned HOST_WIDE_INT lo, hi;
4ac4fd
-
4ac4fd
-      lo = TREE_INT_CST_LOW (value);
4ac4fd
-      hi = TREE_INT_CST_HIGH (value);
4ac4fd
       if (TREE_TYPE (value) == long_type_node)
4ac4fd
-	{
4ac4fd
-	  int hb = (hi >> 31);
4ac4fd
-	  if (hb && !(hi & 0x7fffffff))
4ac4fd
-	    java_lex_error ("Numeric overflow for `long' literal", 0);
4ac4fd
-	}
4ac4fd
+	java_lex_error ("Numeric overflow for `long' literal", 0);
4ac4fd
       else
4ac4fd
-	{
4ac4fd
-	  int hb = (lo >> 31) & 0x1;
4ac4fd
-	  if (hb && !(lo & 0x7fffffff))
4ac4fd
-	    java_lex_error ("Numeric overflow for `int' literal", 0);
4ac4fd
-	}
4ac4fd
+	java_lex_error ("Numeric overflow for `int' literal", 0);
4ac4fd
     }
4ac4fd
 }
4ac4fd
 #endif /* JC1_LITE */
4ac4fd
--- gcc/java/lex.h	2 Nov 2002 21:29:36 -0000	1.28
4ac4fd
+++ gcc/java/lex.h	6 Nov 2002 00:01:01 -0000	1.29
4ac4fd
@@ -185,7 +185,7 @@ extern void java_destroy_lexer PARAMS ((
4ac4fd
 #define SET_LVAL_NODE_TYPE(NODE, TYPE)
4ac4fd
 #define BUILD_ID_WFL(EXP) (EXP)
4ac4fd
 #define JAVA_FLOAT_RANGE_ERROR(S) {}
4ac4fd
-#define JAVA_INTEGRAL_RANGE_ERROR(S) {}
4ac4fd
+#define JAVA_INTEGRAL_RANGE_ERROR(S) do { } while (0)
4ac4fd
 
4ac4fd
 #else
4ac4fd
 
4ac4fd
@@ -237,12 +237,12 @@ extern void java_destroy_lexer PARAMS ((
4ac4fd
     ctxp->c_line->current = i;						  \
4ac4fd
   }
4ac4fd
 #define JAVA_INTEGRAL_RANGE_ERROR(m)		\
4ac4fd
-  {						\
4ac4fd
+  do {						\
4ac4fd
     int i = ctxp->c_line->current;		\
4ac4fd
     ctxp->c_line->current = number_beginning;	\
4ac4fd
     java_lex_error (m, 0);			\
4ac4fd
     ctxp->c_line->current = i;			\
4ac4fd
-  }
4ac4fd
+  } while (0)
4ac4fd
 
4ac4fd
 #endif /* Definitions for jc1 compilation only */
4ac4fd