summaryrefslogtreecommitdiffstats
path: root/gcc/stmt.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2002-02-04 22:05:15 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2002-02-04 22:05:15 +0000
commit79dc3b8eebe13e6e2cd6d8813aeaaa4171e307b2 (patch)
treeabbbeb9e68d3bc70e43d55d15b23db2b78adbf38 /gcc/stmt.c
parent5c56a3a9aa6da6b2b1e51b4dcbc2745cd77ef44b (diff)
downloadppe42-gcc-79dc3b8eebe13e6e2cd6d8813aeaaa4171e307b2.tar.gz
ppe42-gcc-79dc3b8eebe13e6e2cd6d8813aeaaa4171e307b2.zip
PR c/4475, c++/3780:
* c-common.def (SWITCH_STMT): Add SWITCH_TYPE operand. * c-common.h (SWITCH_TYPE): Define. * c-typeck.c (c_start_case): Set SWITCH_TYPE. * stmt.c (all_cases_count): Set lastval to thisval at end of loop. Rename spareness variable to sparseness. (expand_end_case_type): Renamed from expand_end_case, use orig_type if non-NULL instead of TREE_TYPE (orig_index). * tree.h (expand_end_case_type): Renamed from expand_end_case. (expand_end_case): Define using expand_end_case_type. * c-semantics.c (genrtl_switch_stmt): Pass SWITCH_TYPE to expand_end_case_type. * doc/c-tree.texi (SWITCH_STMT): Document SWITCH_TYPE. * semantics.c (begin_switch_stmt): Clear SWITCH_TYPE. (finish_switch_cond): Set SWITCH_TYPE. * gcc.dg/Wswitch.c: Fix typos. Don't return unconditionally before all tests. Move warning one line above to match where it C frontend emits. * gcc.dg/Wswitch-2.c: New test. * g++.dg/warn/Wswitch-1.C: New test. * g++.dg/warn/Wswitch-2.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@49497 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/stmt.c')
-rw-r--r--gcc/stmt.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/gcc/stmt.c b/gcc/stmt.c
index 5d0e4c44388..99f910a9d21 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -4876,20 +4876,20 @@ add_case_node (low, high, label, duplicate)
/* Returns the number of possible values of TYPE.
Returns -1 if the number is unknown, variable, or if the number does not
fit in a HOST_WIDE_INT.
- Sets *SPARENESS to 2 if TYPE is an ENUMERAL_TYPE whose values
+ Sets *SPARSENESS to 2 if TYPE is an ENUMERAL_TYPE whose values
do not increase monotonically (there may be duplicates);
to 1 if the values increase monotonically, but not always by 1;
otherwise sets it to 0. */
HOST_WIDE_INT
-all_cases_count (type, spareness)
+all_cases_count (type, sparseness)
tree type;
- int *spareness;
+ int *sparseness;
{
tree t;
HOST_WIDE_INT count, minval, lastval;
- *spareness = 0;
+ *sparseness = 0;
switch (TREE_CODE (type))
{
@@ -4928,11 +4928,12 @@ all_cases_count (type, spareness)
{
HOST_WIDE_INT thisval = tree_low_cst (TREE_VALUE (t), 0);
- if (*spareness == 2 || thisval < lastval)
- *spareness = 2;
+ if (*sparseness == 2 || thisval <= lastval)
+ *sparseness = 2;
else if (thisval != minval + count)
- *spareness = 1;
+ *sparseness = 1;
+ lastval = thisval;
count++;
}
}
@@ -5213,11 +5214,13 @@ free_case_nodes (cn)
/* Terminate a case (Pascal) or switch (C) statement
in which ORIG_INDEX is the expression to be tested.
+ If ORIG_TYPE is not NULL, it is the original ORIG_INDEX
+ type as given in the source before any compiler conversions.
Generate the code to test it and jump to the right place. */
void
-expand_end_case (orig_index)
- tree orig_index;
+expand_end_case_type (orig_index, orig_type)
+ tree orig_index, orig_type;
{
tree minval = NULL_TREE, maxval = NULL_TREE, range = NULL_TREE;
rtx default_label = 0;
@@ -5241,6 +5244,8 @@ expand_end_case (orig_index)
index_expr = thiscase->data.case_stmt.index_expr;
index_type = TREE_TYPE (index_expr);
unsignedp = TREE_UNSIGNED (index_type);
+ if (orig_type == NULL)
+ orig_type = TREE_TYPE (orig_index);
do_pending_stack_adjust ();
@@ -5261,9 +5266,9 @@ expand_end_case (orig_index)
No sense trying this if there's a default case, however. */
if (!thiscase->data.case_stmt.default_label
- && TREE_CODE (TREE_TYPE (orig_index)) == ENUMERAL_TYPE
+ && TREE_CODE (orig_type) == ENUMERAL_TYPE
&& TREE_CODE (index_expr) != INTEGER_CST)
- check_for_full_enumeration_handling (TREE_TYPE (orig_index));
+ check_for_full_enumeration_handling (orig_type);
/* If we don't have a default-label, create one here,
after the body of the switch. */
@@ -5420,7 +5425,7 @@ expand_end_case (orig_index)
default code is emitted. */
use_cost_table
- = (TREE_CODE (TREE_TYPE (orig_index)) != ENUMERAL_TYPE
+ = (TREE_CODE (orig_type) != ENUMERAL_TYPE
&& estimate_case_costs (thiscase->data.case_stmt.case_list));
balance_case_nodes (&thiscase->data.case_stmt.case_list, NULL);
emit_case_nodes (index, thiscase->data.case_stmt.case_list,
OpenPOWER on IntegriCloud