static int node_has_high_bound (case_node_ptr, tree);
static int node_is_bounded (case_node_ptr, tree);
static void emit_case_nodes (rtx, case_node_ptr, rtx, tree);
-static struct case_node *add_case_node (struct case_node *, tree, tree, tree);
+static struct case_node *add_case_node (struct case_node *, tree,
+ tree, tree, tree);
\f
/* Return the rtx-label that corresponds to a LABEL_DECL,
/* Do the insertion of a case label into case_list. The labels are
fed to us in descending order from the sorted vector of case labels used
in the tree part of the middle end. So the list we construct is
- sorted in ascending order. */
+ sorted in ascending order. The bounds on the case range, LOW and HIGH,
+ are converted to case's index type TYPE. */
-struct case_node *
-add_case_node (struct case_node *head, tree low, tree high, tree label)
+static struct case_node *
+add_case_node (struct case_node *head, tree type, tree low, tree high,
+ tree label)
{
+ tree min_value, max_value;
struct case_node *r;
+ gcc_assert (TREE_CODE (low) == INTEGER_CST);
+ gcc_assert (!high || TREE_CODE (high) == INTEGER_CST);
+
+ min_value = TYPE_MIN_VALUE (type);
+ max_value = TYPE_MAX_VALUE (type);
+
/* If there's no HIGH value, then this is not a case range; it's
just a simple case label. But that's just a degenerate case
range.
If the bounds are equal, turn this into the one-value case. */
if (!high || tree_int_cst_equal (low, high))
- high = low;
+ {
+ /* If the simple case value is unreachable, ignore it. */
+ if (tree_int_cst_compare (low, min_value) < 0
+ || tree_int_cst_compare (low, max_value) > 0)
+ return head;
+ low = fold_convert (type, low);
+ high = low;
+ }
+ else
+ {
+ /* If the entire case range is unreachable, ignore it. */
+ if (tree_int_cst_compare (high, min_value) < 0
+ || tree_int_cst_compare (low, max_value) > 0)
+ return head;
+
+ /* If the lower bound is less than the index type's minimum
+ value, truncate the range bounds. */
+ if (tree_int_cst_compare (low, min_value) < 0)
+ low = min_value;
+ low = fold_convert (type, low);
+
+ /* If the upper bound is greater than the index type's maximum
+ value, truncate the range bounds. */
+ if (tree_int_cst_compare (high, max_value) > 0)
+ high = max_value;
+ high = fold_convert (type, high);
+ }
+
/* Add this label to the chain. */
r = ggc_alloc (sizeof (struct case_node));
rtx table_label;
int ncases;
rtx *labelvec;
- int i;
+ int i, fail;
rtx before_case, end, lab;
tree vec = SWITCH_LABELS (exp);
gcc_assert (!SWITCH_BODY (exp));
gcc_assert (SWITCH_LABELS (exp));
- for (i = TREE_VEC_LENGTH (vec); --i >= 0; )
- {
- tree elt = TREE_VEC_ELT (vec, i);
-
- /* Handle default labels specially. */
- if (!CASE_HIGH (elt) && !CASE_LOW (elt))
- {
- gcc_assert (!default_label_decl);
- default_label_decl = CASE_LABEL (elt);
- }
- else
- case_list = add_case_node (case_list, CASE_LOW (elt), CASE_HIGH (elt),
- CASE_LABEL (elt));
- }
-
do_pending_stack_adjust ();
- /* Make sure start points to something that won't need any transformation
- before the end of this function. */
- if (!NOTE_P (get_last_insn ()))
- emit_note (NOTE_INSN_DELETED);
-
- start = get_last_insn ();
-
/* An ERROR_MARK occurs for various reasons including invalid data type. */
if (index_type != error_mark_node)
{
- int fail;
+ for (i = TREE_VEC_LENGTH (vec); --i >= 0; )
+ {
+ tree elt = TREE_VEC_ELT (vec, i);
+
+ /* Handle default labels specially. */
+ if (!CASE_HIGH (elt) && !CASE_LOW (elt))
+ {
+ gcc_assert (!default_label_decl);
+ default_label_decl = CASE_LABEL (elt);
+ }
+ else
+ case_list = add_case_node (case_list, index_type,
+ CASE_LOW (elt), CASE_HIGH (elt),
+ CASE_LABEL (elt));
+ }
+
+
+ /* Make sure start points to something that won't need any
+ transformation before the end of this function. */
+ start = get_last_insn ();
+ if (! NOTE_P (start))
+ {
+ emit_note (NOTE_INSN_DELETED);
+ start = get_last_insn ();
+ }
/* If we don't have a default-label, create one here,
after the body of the switch. */
count = 0;
for (n = case_list; n; n = n->right)
{
- /* Check low and high label values are integers. */
- gcc_assert (TREE_CODE (n->low) == INTEGER_CST);
- gcc_assert (TREE_CODE (n->high) == INTEGER_CST);
-
- n->low = convert (index_type, n->low);
- n->high = convert (index_type, n->high);
-
/* Count the elements and track the largest and smallest
of them (treating them as signed even if they are not). */
if (count++ == 0)