[patch] expr.c: Make expand_expr_real_1 safer on COND_EXPR.
Kazu Hirata
kazu@cs.umass.edu
Sun Dec 5 22:24:00 GMT 2004
Hi,
Attached is a patch to make expand_expr_real_1 safer on COND_EXPR.
COND_EXPR of VOID_TYPE, which is really a COND_EXPR with GOTO_EXPRs,
is handled by expand_gimple_cond_expr.
The patch causes GCC to abort if expand_expr_real_1 is passed such a
COND_EXPR.
Even if there were a path to the code under the "if" statement shown
in the patch, I don't know how one could guarantee that the existing
gcc_assert there never triggers because disband_implicit_edges
sometimes puts an empty statement in one of the arms if the control
falls through.
This is probably garbage from the old days we didn't carry over CFG
during tree->RTL expansion.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2004-12-05 Kazu Hirata <kazu@cs.umass.edu>
* expr.c (expand_expr_real_1): Abort on COND_EXPR of
VOID_TYPE.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.754
diff -c -d -p -r1.754 expr.c
*** expr.c 4 Dec 2004 00:20:30 -0000 1.754
--- expr.c 5 Dec 2004 15:06:32 -0000
*************** expand_expr_real_1 (tree exp, rtx target
*** 8063,8083 ****
return const0_rtx;
case COND_EXPR:
! /* If it's void, we don't need to worry about computing a value. */
! if (VOID_TYPE_P (TREE_TYPE (exp)))
! {
! tree pred = TREE_OPERAND (exp, 0);
! tree then_ = TREE_OPERAND (exp, 1);
! tree else_ = TREE_OPERAND (exp, 2);
!
! gcc_assert (TREE_CODE (then_) == GOTO_EXPR
! && TREE_CODE (GOTO_DESTINATION (then_)) == LABEL_DECL
! && TREE_CODE (else_) == GOTO_EXPR
! && TREE_CODE (GOTO_DESTINATION (else_)) == LABEL_DECL);
!
! jumpif (pred, label_rtx (GOTO_DESTINATION (then_)));
! return expand_expr (else_, const0_rtx, VOIDmode, 0);
! }
/* Note that COND_EXPRs whose type is a structure or union
are required to be constructed to contain assignments of
--- 8063,8072 ----
return const0_rtx;
case COND_EXPR:
! /* A COND_EXPR with its type being VOID_TYPE represents a
! conditional jump and is handled in
! expand_gimple_cond_expr. */
! gcc_assert (!VOID_TYPE_P (TREE_TYPE (exp)));
/* Note that COND_EXPRs whose type is a structure or union
are required to be constructed to contain assignments of
More information about the Gcc-patches
mailing list