https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128970
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:a38d46e1ddf4c735a82728701c987979dc30ce64 commit r17-6719-ga38d46e1ddf4c735a82728701c987979dc30ce64 Author: Jakub Jelinek <[email protected]> Date: Thu Nov 26 09:30:24 2026 +0100 match.pd: Disable A ? B : B folding for C++ FE COND_EXPRs with bit-fields [PR128970] The following testcase ICEs because match.pd folds a from GENERIC POV invalid COND_EXPR and then type verification fails. The C++ FE for COND_EXPRs with bit-fields in second and/or third operand uses TREE_TYPE on the COND_EXPR the promoted type, but on the second/third operand unpromoted, because COND_EXPRs can also appear on lhs and in that case promotion would be harmful. Normally the C++ FE fixes this in cp_fold_r soon before gimplification. Now, on this testcase before we do so we call cp_fully_fold which in the end does fold on the COND_EXPR and cache that. That already returns and caches invalid expression (without needed cast). cp_fold_r then modifies the COND_EXPR in place (and I think doesn't invalidate the cache) and then we end up IL without necessary conversion and ICE on type verification. cp_fold actually already has code to fix it up, added for PR70285, PR81607. The reason why it doesn't work here is that the first operand of COND_EXPR (i.e. the condition) has side-effects, and then match.pd emitted code wraps it into a COMPOUND_EXPR with the side-effects evaluated in its first operand and the missing cast in the second operand. This patch fixes it by performing the promotion on the COND_EXPR before we pass it to middle-end for optimizations rather than trying to fix it afterwards. 2026-11-26 Jakub Jelinek <[email protected]> PR c++/128970 * cp-gimplify.cc (cp_fold) <case COND_EXPR>: If op1 and/or op2 are bit-fields, promote them to TREE_TYPE (x) before folding instead of trying to fix it after folding. * g++.dg/opt/pr128970.C: New test. Reviewed-by: Jason Merrill <[email protected]>
