-/* See if the case values LOW and HIGH are in the range of the original
- type (i.e. before the default conversion to int) of the switch testing
- expression.
- TYPE is the promoted type of the testing expression, and ORIG_TYPE is
- the type before promoting it. CASE_LOW_P is a pointer to the lower
- bound of the case label, and CASE_HIGH_P is the upper bound or NULL
- if the case is not a case range.
- The caller has to make sure that we are not called with NULL for
- CASE_LOW_P (i.e. the default case). OUTSIDE_RANGE_P says whether there
- was a case value that doesn't fit into the range of the ORIG_TYPE.
- Returns true if the case label is in range of ORIG_TYPE (saturated or
- untouched) or false if the label is out of range. */
-
-static bool
-check_case_bounds (location_t loc, tree type, tree orig_type,
- tree *case_low_p, tree *case_high_p,
- bool *outside_range_p)
-{
- tree min_value, max_value;
- tree case_low = *case_low_p;
- tree case_high = case_high_p ? *case_high_p : case_low;
-
- /* If there was a problem with the original type, do nothing. */
- if (orig_type == error_mark_node)
- return true;
-
- min_value = TYPE_MIN_VALUE (orig_type);
- max_value = TYPE_MAX_VALUE (orig_type);
-
- /* We'll really need integer constants here. */
- case_low = fold (case_low);
- case_high = fold (case_high);
-
- /* Case label is less than minimum for type. */
- if (tree_int_cst_compare (case_low, min_value) < 0
- && tree_int_cst_compare (case_high, min_value) < 0)
- {
- warning_at (loc, 0, "case label value is less than minimum value "
- "for type");
- *outside_range_p = true;
- return false;
- }
-
- /* Case value is greater than maximum for type. */
- if (tree_int_cst_compare (case_low, max_value) > 0
- && tree_int_cst_compare (case_high, max_value) > 0)
- {
- warning_at (loc, 0, "case label value exceeds maximum value for type");
- *outside_range_p = true;
- return false;
- }
-
- /* Saturate lower case label value to minimum. */
- if (tree_int_cst_compare (case_high, min_value) >= 0
- && tree_int_cst_compare (case_low, min_value) < 0)
- {
- warning_at (loc, 0, "lower value in case label range"
- " less than minimum value for type");
- *outside_range_p = true;
- case_low = min_value;
- }
-
- /* Saturate upper case label value to maximum. */
- if (tree_int_cst_compare (case_low, max_value) <= 0
- && tree_int_cst_compare (case_high, max_value) > 0)
- {
- warning_at (loc, 0, "upper value in case label range"
- " exceeds maximum value for type");
- *outside_range_p = true;
- case_high = max_value;
- }
-
- if (*case_low_p != case_low)
- *case_low_p = convert (type, case_low);
- if (case_high_p && *case_high_p != case_high)
- *case_high_p = convert (type, case_high);
-
- return true;
-}
-\f