From a6c0a76c5f9eb216b5f08ffc4624a6d039ca3977 Mon Sep 17 00:00:00 2001 From: Steven Bosscher Date: Tue, 20 Jul 2004 09:57:13 +0000 Subject: c-common.h (check_case_value): Remove prototype. * c-common.h (check_case_value): Remove prototype. (c_add_case_label): Adjust prototype. * c-common.c (check_case_value): Make static. (check_case_bounds): New function. (c_add_case_label): Use it. Take new argument orig_type. * c-typeck.c (struct c_switch): New orig_type field. (c_start_case): Set it. (do_case): Pass it to c_add_case_label. * expr.c (expand_expr_real_1): Don't warn for out-of-bounds cases from here. Add the labels in reverse order. * stmt.c (struct case_node): Adjust comment. Remove balance field. (add_case_node): Return nothing, don't check for duplicate cases. Insert new case nodes in a list, not in an AVL tree. (expand_end_case_type): Don't turn a case tree into a case list. (case_tree2list): Remove. * tree.h (add_case_node): Adjust prototype. cp/ * cp-tree.h (struct lang_decl_flags): Unify the template_info and thunk_alias, and the access and virtual_offset fields. (THUNK_VIRTUAL_OFFSET, THUNK_ALIAS): Adjust. * decl.c (finish_case_label): Update c_add_case_node call. testsuite/ * testsuite/gcc.dg/switch-warn-1.c: New test. * testsuite/gcc.dg/switch-warn-2.c: New test. * gcc.c-torture/compile/pr14730.c: Update From-SVN: r84947 --- gcc/expr.c | 64 ++++++++------------------------------------------------------ 1 file changed, 8 insertions(+), 56 deletions(-) (limited to 'gcc/expr.c') diff --git a/gcc/expr.c b/gcc/expr.c index 2ca28db..858a7ff 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -8569,67 +8569,19 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode, abort (); if (SWITCH_LABELS (exp)) { - tree duplicate = 0; tree vec = SWITCH_LABELS (exp); - size_t i, n = TREE_VEC_LENGTH (vec); + size_t i = TREE_VEC_LENGTH (vec); - for (i = 0; i < n; ++i) + do { - tree elt = TREE_VEC_ELT (vec, i); - tree controlling_expr_type = TREE_TYPE (SWITCH_COND (exp)); - tree min_value = TYPE_MIN_VALUE (controlling_expr_type); - tree max_value = TYPE_MAX_VALUE (controlling_expr_type); - - tree case_low = CASE_LOW (elt); - tree case_high = CASE_HIGH (elt) ? CASE_HIGH (elt) : case_low; - if (case_low && case_high) - { - /* Case label is less than minimum for type. */ - if (TREE_CODE (min_value) == INTEGER_CST - && tree_int_cst_compare (case_low, min_value) < 0 - && tree_int_cst_compare (case_high, min_value) < 0) - { - warning ("case label value %d is less than minimum value for type", - TREE_INT_CST (case_low)); - continue; - } - - /* Case value is greater than maximum for type. */ - if (TREE_CODE (max_value) == INTEGER_CST - && tree_int_cst_compare (case_low, max_value) > 0 - && tree_int_cst_compare (case_high, max_value) > 0) - { - warning ("case label value %d exceeds maximum value for type", - TREE_INT_CST (case_high)); - continue; - } - - /* Saturate lower case label value to minimum. */ - if (TREE_CODE (min_value) == INTEGER_CST - && tree_int_cst_compare (case_high, min_value) >= 0 - && tree_int_cst_compare (case_low, min_value) < 0) - { - warning ("lower value %d in case label range less than minimum value for type", - TREE_INT_CST (case_low)); - case_low = min_value; - } - - /* Saturate upper case label value to maximum. */ - if (TREE_CODE (max_value) == INTEGER_CST - && tree_int_cst_compare (case_low, max_value) <= 0 - && tree_int_cst_compare (case_high, max_value) > 0) - { - warning ("upper value %d in case label range exceeds maximum value for type", - TREE_INT_CST (case_high)); - case_high = max_value; - } - } - - add_case_node (case_low, case_high, CASE_LABEL (elt), &duplicate); - if (duplicate) - abort (); + tree elt = TREE_VEC_ELT (vec, --i); + add_case_node (CASE_LOW (elt), CASE_HIGH (elt), + CASE_LABEL (elt)); } + while (i); } + else + abort (); expand_end_case_type (SWITCH_COND (exp), TREE_TYPE (exp)); return const0_rtx; -- cgit v1.1