https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128970
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
>From what I can see, the problem is that COND_EXPRs in the FE are not
necessarily valid GENERIC, and only cp_fold_r fixes this up:
/* COND_EXPR might have incompatible types in branches if one or both
arms are bitfields. Fix it up now. */
case COND_EXPR:
{
tree type_left
= (TREE_OPERAND (stmt, 1)
? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 1))
: NULL_TREE);
tree type_right
= (TREE_OPERAND (stmt, 2)
? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 2))
: NULL_TREE);
if (type_left
&& !useless_type_conversion_p (TREE_TYPE (stmt),
TREE_TYPE (TREE_OPERAND (stmt, 1))))
{
TREE_OPERAND (stmt, 1)
= fold_convert (type_left, TREE_OPERAND (stmt, 1));
gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt),
type_left));
}
if (type_right
&& !useless_type_conversion_p (TREE_TYPE (stmt),
TREE_TYPE (TREE_OPERAND (stmt, 2))))
{
TREE_OPERAND (stmt, 2)
= fold_convert (type_right, TREE_OPERAND (stmt, 2));
gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt),
type_right));
}
}
But before that happens cp_fully_fold -> cp_fold_rvalue -> cp_fold -> fold is
called on it and uses the match.pd
/* A ? B : B -> B. */
(simplify
(cnd @0 @1 @1)
@1)
optimization, so we loose COND_EXPR guarding missing extension in the IL, the
cp_fold_r modification is in place
and so doesn't invalidate caching and there is also COMPOUND_EXPR involved,
likely for proper side-effect ordering and we end up with
mismatching types.
Dunno what to do best for this, maybe guard this match.pd optimization on
types_match? It would be a hack, sure...