https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81607
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code Status|ASSIGNED |NEW Component|tree-optimization |c++ Assignee|rguenth at gcc dot gnu.org |unassigned at gcc dot gnu.org --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- 0x000000000088d7d5 in cp_fold (x=<lshift_expr 0x7ffff69e6618>) at /tmp/trunk/gcc/cp/cp-gimplify.c:2251 2251 x = fold_build2_loc (loc, code, TREE_TYPE (x), op0, op1); Value returned is $25 = (tree_node *) 0x7ffff69e6640 (gdb) p debug_generic_expr (op1) a $26 = void (gdb) p debug_generic_expr (op0) (long int) d.c $27 = void (gdb) p debug_generic_expr (x) (1 ? (int) (long int) d.c : 0) << a $28 = void because we run into static tree cp_fold (tree x) { ... case VEC_COND_EXPR: case COND_EXPR: ... /* A COND_EXPR might have incompatible types in branches if one or both arms are bitfields. If folding exposed such a branch, fix it up. */ if (TREE_CODE (x) != code) if (tree type = is_bitfield_expr_with_lowered_type (x)) x = fold_convert (type, x); and fold (int) (long int) d.c to (long int) d.c here. C++ FE bug. Not sure why this isn't simply the following as we surely have to preserve the type of the COND_EXPR when folding. Index: gcc/cp/cp-gimplify.c =================================================================== --- gcc/cp/cp-gimplify.c (revision 250725) +++ gcc/cp/cp-gimplify.c (working copy) @@ -2314,8 +2314,7 @@ cp_fold (tree x) /* A COND_EXPR might have incompatible types in branches if one or both arms are bitfields. If folding exposed such a branch, fix it up. */ if (TREE_CODE (x) != code) - if (tree type = is_bitfield_expr_with_lowered_type (x)) - x = fold_convert (type, x); + x = fold_convert (TREE_TYPE (org_x), x); break; Leaving to C++ folks.