This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tuples] Don't ICE if a switch() only has the default label
- From: Diego Novillo <dnovillo at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 01 Aug 2007 13:08:40 -0400
- Subject: [tuples] Don't ICE if a switch() only has the default label
This fixes a couple of tests in compile.exp. If a switch only has the
default label, the call to sort_case_labels in gimplify_switch_expr()
was segfaulting as the vector was empty.
2007-08-01 Diego Novillo <dnovillo@google.com>
* gimplify.c (gimplify_switch_expr): Do not call sort_case_labels
if there are no labels other than 'default'.
* gimple.h (gimple_num_ops, gimple_op, gimple_set_op): Use
result of GIMPLE_RANGE_CHECK call.
Index: gimplify.c
===================================================================
--- gimplify.c (revision 127104)
+++ gimplify.c (working copy)
@@ -1455,7 +1455,9 @@ gimplify_switch_expr (tree *expr_p, gimp
default_case = gimple_label_label (new_default);
}
- sort_case_labels (labels);
+ if (!VEC_empty (tree, labels))
+ sort_case_labels (labels);
+
gimple_switch = build_gimple_switch_vec (SWITCH_COND (switch_expr),
default_case, labels);
gimple_add (pre_p, gimple_switch);
Index: gimple.h
===================================================================
--- gimple.h (revision 127104)
+++ gimple.h (working copy)
@@ -472,24 +472,24 @@ extern void gimple_range_check_failed (c
static inline size_t
gimple_num_ops (gimple gs)
{
- GIMPLE_RANGE_CHECK (gs, GIMPLE_ASSIGN, GIMPLE_RETURN);
- return gs->with_ops.num_ops;
+ gimple g = GIMPLE_RANGE_CHECK (gs, GIMPLE_ASSIGN, GIMPLE_RETURN);
+ return g->with_ops.num_ops;
}
static inline tree
gimple_op (gimple gs, size_t i)
{
- GIMPLE_RANGE_CHECK (gs, GIMPLE_ASSIGN, GIMPLE_RETURN);
- gcc_assert (i < gs->with_ops.num_ops);
- return gs->with_ops.op[i];
+ gimple g = GIMPLE_RANGE_CHECK (gs, GIMPLE_ASSIGN, GIMPLE_RETURN);
+ gcc_assert (i < g->with_ops.num_ops);
+ return g->with_ops.op[i];
}
static inline void
gimple_set_op (gimple gs, size_t i, tree op)
{
- GIMPLE_RANGE_CHECK (gs, GIMPLE_ASSIGN, GIMPLE_RETURN);
- gcc_assert (i < gs->with_ops.num_ops);
- gs->with_ops.op[i] = op;
+ gimple g = GIMPLE_RANGE_CHECK (gs, GIMPLE_ASSIGN, GIMPLE_RETURN);
+ gcc_assert (i < g->with_ops.num_ops);
+ g->with_ops.op[i] = op;
}