aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Hainque <hainque@act-europe.fr>2001-12-12 13:44:46 +0100
committerRichard Kenner <kenner@gcc.gnu.org>2001-12-12 07:44:46 -0500
commit2d9d49e4477346398ed3cc8827680069837afb0e (patch)
tree958f04f76d8223301468d3e179631568421364ae
parentcdb290580c0adf1dd4e1467e8d3afeaa13fa0df7 (diff)
downloadgcc-2d9d49e4477346398ed3cc8827680069837afb0e.zip
gcc-2d9d49e4477346398ed3cc8827680069837afb0e.tar.gz
gcc-2d9d49e4477346398ed3cc8827680069837afb0e.tar.bz2
stmt.c (expand_end_case): Do subtraction of lower bound as trees to avoid overflow.
* stmt.c (expand_end_case): Do subtraction of lower bound as trees to avoid overflow. From-SVN: r47932
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/stmt.c26
2 files changed, 19 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c34e921..319e07e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+Wed Dec 12 07:37:52 2001 Olivier Hainque <hainque@act-europe.fr>
+
+ * stmt.c (expand_end_case): Do subtraction of lower bound as trees
+ to avoid overflow.
+
Wed Dec 12 07:35:24 2001 Douglas B. Rupp <rupp@gnat.com>
* cppfiles.c (read_include_file): Set buffer size properly when
diff --git a/gcc/stmt.c b/gcc/stmt.c
index 3c4ccd1..7978554 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -5525,18 +5525,20 @@ expand_end_case (orig_index)
for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
{
- HOST_WIDE_INT i
- = tree_low_cst (n->low, 0) - tree_low_cst (minval, 0);
-
- while (1)
- {
- labelvec[i]
- = gen_rtx_LABEL_REF (Pmode, label_rtx (n->code_label));
- if (i + tree_low_cst (minval, 0)
- == tree_low_cst (n->high, 0))
- break;
- i++;
- }
+ /* Compute the low and high bounds relative to the minimum
+ value since that should fit in a HOST_WIDE_INT while the
+ actual values may not. */
+ HOST_WIDE_INT i_low
+ = tree_low_cst (fold (build (MINUS_EXPR, index_type,
+ n->low, minval)), 1);
+ HOST_WIDE_INT i_high
+ = tree_low_cst (fold (build (MINUS_EXPR, index_type,
+ n->high, minval)), 1);
+ HOST_WIDE_INT i;
+
+ for (i = i_low; i <= i_high; i ++)
+ labelvec[i]
+ = gen_rtx_LABEL_REF (Pmode, label_rtx (n->code_label));
}
/* Fill in the gaps with the default. */