]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix compile-time-hog in cp_fold_immediate_r [PR111660]
authorMarek Polacek <polacek@redhat.com>
Thu, 12 Oct 2023 19:58:05 +0000 (15:58 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 17 Oct 2023 21:41:44 +0000 (17:41 -0400)
commit765c3b8f82d50961008c214ac2113f35e7532aa9
tree7db78233c62877764f7da71812e9f8218d372739
parentbac21b7ea62bd3a7911e01cf803d6bf6516fbf7b
c++: Fix compile-time-hog in cp_fold_immediate_r [PR111660]

My recent patch introducing cp_fold_immediate_r caused exponential
compile time with nested COND_EXPRs.  The problem is that the COND_EXPR
case recursively walks the arms of a COND_EXPR, but after processing
both arms it doesn't end the walk; it proceeds to walk the
sub-expressions of the outermost COND_EXPR, triggering again walking
the arms of the nested COND_EXPR, and so on.  This patch brings the
compile time down to about 0m0.030s.

The ff_fold_immediate flag is unused after this patch but since I'm
using it in the P2564 patch, I'm not removing it now.  Maybe at_eof
can be used instead and then we can remove ff_fold_immediate.

PR c++/111660

gcc/cp/ChangeLog:

* cp-gimplify.cc (cp_fold_immediate_r) <case COND_EXPR>: Don't
handle it here.
(cp_fold_r): Handle COND_EXPR here.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/hog1.C: New test.
* g++.dg/cpp2a/consteval36.C: New test.
gcc/cp/cp-gimplify.cc
gcc/testsuite/g++.dg/cpp0x/hog1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/consteval36.C [new file with mode: 0644]