diff options
author | Roger Sayle <roger@eyesopen.com> | 2003-12-29 16:16:39 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2003-12-29 16:16:39 +0000 |
commit | b66906a8ff79931bc3d23b9362833b1567c5ac56 (patch) | |
tree | 8cc330d809fbbe70f50065f881b684ae3503d29c /gcc/fold-const.c | |
parent | 68deab91f26e8a5266a8bd9086bbf5129c619c03 (diff) | |
download | gcc-b66906a8ff79931bc3d23b9362833b1567c5ac56.zip gcc-b66906a8ff79931bc3d23b9362833b1567c5ac56.tar.gz gcc-b66906a8ff79931bc3d23b9362833b1567c5ac56.tar.bz2 |
re PR fortran/12632 ([g77 only] -fbounds-check ICE)
PR fortran/12632
* fold-const.c (fold) <COND_EXPR>: Don't fold a constant condition,
if the type of the selected branch doesn't match its' parent.
* com.c (ffecom_subscript_check_): Take as an extra argument the
(possibly NULL) decl of the array. Don't create unnecessary tree
nodes if the array index is known to be safe at compile-time.
If the array index is unsafe, force the array decl into memory to
avoid RTL expansion problems.
(ffecom_array_ref_): Update calls to ffecom_subscript_check_.
(ffecom_char_args_x_): Likewise.
* g77.dg/12632.f: New test case.
From-SVN: r75203
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 3da0ebf..5565932 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7864,9 +7864,16 @@ fold (tree expr) /* Pedantic ANSI C says that a conditional expression is never an lvalue, so all simple results must be passed through pedantic_non_lvalue. */ if (TREE_CODE (arg0) == INTEGER_CST) - return pedantic_non_lvalue - (TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1))); - else if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0)) + { + tem = TREE_OPERAND (t, (integer_zerop (arg0) ? 2 : 1)); + /* Only optimize constant conditions when the selected branch + has the same type as the COND_EXPR. This avoids optimizing + away "c ? x : throw", where the throw has a void type. */ + if (TREE_TYPE (tem) == TREE_TYPE (t)) + return pedantic_non_lvalue (tem); + return t; + } + if (operand_equal_p (arg1, TREE_OPERAND (expr, 2), 0)) return pedantic_omit_one_operand (type, arg1, arg0); /* If we have A op B ? A : C, we may be able to convert this to a |