On Fri, Mar 08, 2019 at 11:36:36AM +0100, Richard Biener wrote: > Shouldn't we somehow limit the number of stmt evaluations instead? > I can imagine using constexpr templates you can do "loops" easily > without actually writing loops ...
Maybe. The question is what exactly should we count. We could count only in the cxx_eval_statement_list loop individual non-debug statements, but that would miss statements that aren't in STATEMENT_LISTs. Or we could count number of cxx_eval_constant_expression calls (perhaps after the initial if (jump_target && *jump_target) skipping) within a single cxx_eval_outermost_constant_expr, but we couldn't call that number of statements even when it would be much more accurate on how long actually something will take to evaluate, because one can have a single statement with hundreds of thousands of operations in it. So -fconstexpr-ops-limit= ? Probably should use Host_Wide_Int in that case rather than UInteger though, so users can allow more than 4G ops. Looking at what clang++ does, they have -fconstexpr-steps= limit which is declared to count statements with a quite low default 1048576 and it rejects already constexpr unsigned foo () { unsigned int r = 0; for (int i = 0; i < 65536; i++) for (int j = 0; j < 14; j++) r += (i + j); return r; } constexpr auto x = foo (); (but not 13 instead of 14). 13 * 65536 is 851968, so that would be count of r += (i + j); statements, plus the inner for as whole probably 65536 times and with 14 * 65536 + 65536 we are still below the limit, so it must count something else, but e.g. can't count j++ already. > > 2019-03-07 Jakub Jelinek <ja...@redhat.com> > > > > PR c++/87481 > > * doc/invoke.texi (-fconstexpr-loop-nest-limit=): Document. > > (-fconstexpr-loop-limit=): Slightly adjust wording. > > > > * c.opt (-fconstexpr-loop-nest-limit=): New option. > > (-fconstexpr-loop-limit=): Slightly adjust description. > > > > * constexpr.c (cxx_eval_loop_expr): Count also number of iterations > > of all nested loops and punt if it is above > > constexpr_loop_nest_limit. > > > > * g++.dg/cpp1y/constexpr-87481.C: New test. Jakub