[Bug c++/87481] [7/8/9 Regression] Endless loop with optimisation in C++17

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 8 12:51:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87481

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I don't think it is a hang.

void
foo ()
{
  [] { while (true) for (int i = 0; i < 10; ++i) ; } };
}

takes 7 seconds to compile.

We have -fconstexpr-loop-limit= option with default of 262144, but that is just
an upper bound for number of iterations for a single loop, but in your testcase
you have two nested loops, so the compiler will stop after doing 262144
iterations of the outer loop and 10000 iterations of the inner loop.

Perhaps we want in addition to -fconstexpr-loop-limit= that affects just a
single loop have -fconstexpr-loop-nest-limit= that bounds the total number of
loop iterations in the whole constexpr evaluation, all nested loops.

Though, something is really strange, with

void
foo ()
{
  [] { while (true) for (int i = 0; i < 10000; ++i) ; } };
}

-fconstexpr-loop-limit=10000 this compiles immediately, likewise with
-fconstexpr-loop-limit=10001, but with -fconstexpr-loop-limit=10002 it already
takes a long time.


More information about the Gcc-bugs mailing list