https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118525
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <pins...@gcc.gnu.org>: https://gcc.gnu.org/g:0d25d45c9d3a54b21f9dce43beb0b5ced4db0409 commit r15-7113-g0d25d45c9d3a54b21f9dce43beb0b5ced4db0409 Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Thu Jan 16 12:53:21 2025 -0800 c++: Don't call fold from cp_fold if one of the operands is an error_mark [PR118525] While adding a new match pattern, g++.dg/cpp2a/consteval36.C started to ICE and that was because we would call fold even if one of the operands of the comparison was an error_mark_node. I found a new testcase which also ICEs before this patch too so show the issue was latent. So there is code in cp_fold to avoid calling fold when one of the operands become error_mark_node but with the addition of consteval, the replacement of an invalid call is replaced before the call to cp_fold and there is no way to pop up the error_mark. So this patch changes the current code to check if the operands of the expression are error_mark_node before checking if the folded operand is different from the previous one. Bootstrapped and tested on x86_64-linux-gnu. PR c++/118525 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_fold): Check operands of unary, binary, cond/vec_cond and array_ref for error_mark before checking if the operands had changed. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/consteval38.C: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>