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