This is the mail archive of the
mailing list for the GCC project.
Re: [patch] Cleanup tree-switch-conversion a bit
On Wed, Apr 18, 2012 at 11:10 AM, Richard Guenther <firstname.lastname@example.org> wrote:
> I wonder about
> @@ -1575,6 +1575,9 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pr
> ? tree switch_expr = *expr_p;
> ? gimple_seq switch_body_seq = NULL;
> ? enum gimplify_status ret;
> + ?tree index_type = TREE_TYPE (switch_expr);
> + ?if (index_type == void_type_node)
> + ? ?index_type = TREE_TYPE (SWITCH_COND (switch_expr));
> what frontends use void_type_node here contrary to the docs in tree.def:
> ? TREE_TYPE is the original type of the condition, before any
> ? language required type conversions. ?It may be NULL, in which case
> ? the original type and final types are assumed to be the same.
> which says you'd need to handle NULL instead? ?Thus, can you either
> adjust the docs in tree.def or the frontends?
That code was copied from stmt.c, and I was surprised by it, too.
The Fortran frond end builds SWITCH_EXPRs with build3_v, i.e.
void_type_node-typed. The Go front ends also build SWITCH_EXPRs with
void_type_node. The C-family and Java front ends build SWITCH_EXPRs
with a non-void type.
But from gimplify.c:is_gimple_stmt():
/* These are always void. */
See these files for all the locations I could find where a SWITCH_EXPR is built:
java/expr.c: switch_expr = build3 (SWITCH_EXPR, TREE_TYPE (selector), selector,
go/go-gcc.cc: tree t = build3_loc(switch_location.gcc_location(), SWITCH_EXPR,
cp/cp-gimplify.c: t = build3 (SWITCH_EXPR, SWITCH_STMT_TYPE (stmt),
c-typeck.c: cs->switch_expr = build3 (SWITCH_EXPR, orig_type, exp,
fortran/trans-stmt.c: tmp = build3_v (SWITCH_EXPR, se.expr, tmp, NULL_TREE);
fortran/trans-stmt.c: tmp = build3_v (SWITCH_EXPR, case_num, tmp,
fortran/trans-stmt.c: tmp = build3_v (SWITCH_EXPR, case_num, tmp, NULL_TREE);
fortran/trans-io.c: tmp = build3_v (SWITCH_EXPR, rc, tmp, NULL_TREE);
fortran/trans-decl.c: tmp = build3_v (SWITCH_EXPR, val, tmp, NULL_TREE);
ada/gcc-interface/trans.c: gnu_result = build3 (SWITCH_EXPR,
TREE_TYPE (gnu_expr), gnu_expr,
Perhaps the Fortran and Go front ends should build SWITCH_EXPRs with a
NULL type, and gimplify_switch_expr() should assert that the
SWITCH_EXPR type is never void_type node. That would make things match
the documentation in tree.def again. I'll test a patch with these
changes and commit it if it works.