+2019-06-26 Jason Merrill <jason@redhat.com>
+
+ PR c++/55442 - memory-hog with highly recursive constexpr.
+ * c.opt (fconstexpr-loop-limit): New.
+
2019-06-25 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/90954
C++ ObjC++ Joined RejectNegative UInteger Var(max_constexpr_depth) Init(512)
-fconstexpr-depth=<number> Specify maximum constexpr recursion depth.
+fconstexpr-cache-depth=
+C++ ObjC++ Joined RejectNegative UInteger Var(constexpr_cache_depth) Init(8)
+-fconstexpr-cache-depth=<number> Specify maximum constexpr recursion cache depth.
+
fconstexpr-loop-limit=
C++ ObjC++ Joined RejectNegative UInteger Var(constexpr_loop_limit) Init(262144)
-fconstexpr-loop-limit=<number> Specify maximum constexpr loop iteration count.
+2019-06-27 Jason Merrill <jason@redhat.com>
+
+ PR c++/55442 - memory-hog with highly recursive constexpr.
+ * constexpr.c (push_cx_call_context): Return depth.
+ (cxx_eval_call_expression): Don't cache past constexpr_cache_depth.
+
2019-06-27 Jan Hubicka <jh@suse.cz>
* class.c (layout_class_type): Set TYPE_CXX_ODR_P for as-base
static int call_stack_tick;
static int last_cx_error_tick;
-static bool
+static int
push_cx_call_context (tree call)
{
++call_stack_tick;
if (!EXPR_HAS_LOCATION (call))
SET_EXPR_LOCATION (call, input_location);
call_stack.safe_push (call);
- if (call_stack.length () > (unsigned) max_constexpr_depth)
+ int len = call_stack.length ();
+ if (len > max_constexpr_depth)
return false;
- return true;
+ return len;
}
static void
tree fun = get_function_named_in_call (t);
constexpr_call new_call
= { NULL, NULL, NULL, 0, ctx->manifestly_const_eval };
- bool depth_ok;
+ int depth_ok;
if (fun == NULL_TREE)
return cxx_eval_internal_function (ctx, t, lval,
entry = *slot;
if (entry == NULL)
{
- /* We need to keep a pointer to the entry, not just the slot, as the
- slot can move in the call to cxx_eval_builtin_function_call. */
- *slot = entry = ggc_alloc<constexpr_call> ();
- *entry = new_call;
- fb.preserve ();
+ /* Only cache up to constexpr_cache_depth to limit memory use. */
+ if (depth_ok < constexpr_cache_depth)
+ {
+ /* We need to keep a pointer to the entry, not just the slot, as
+ the slot can move during evaluation of the body. */
+ *slot = entry = ggc_alloc<constexpr_call> ();
+ *entry = new_call;
+ fb.preserve ();
+ }
}
- /* Calls that are in progress have their result set to NULL,
- so that we can detect circular dependencies. */
+ /* Calls that are in progress have their result set to NULL, so that we
+ can detect circular dependencies. Now that we only cache up to
+ constexpr_cache_depth this won't catch circular dependencies that
+ start deeper, but they'll hit the recursion or ops limit. */
else if (entry->result == NULL)
{
if (!ctx->quiet)
@xref{C++ Dialect Options,,Options Controlling C++ Dialect}.
@gccoptlist{-fabi-version=@var{n} -fno-access-control @gol
-faligned-new=@var{n} -fargs-in-order=@var{n} -fchar8_t -fcheck-new @gol
--fconstexpr-depth=@var{n} -fconstexpr-loop-limit=@var{n} @gol
--fconstexpr-ops-limit=@var{n} -fno-elide-constructors @gol
+-fconstexpr-depth=@var{n} -fconstexpr-cache-depth=@var{n} @gol
+-fconstexpr-loop-limit=@var{n} -fconstexpr-ops-limit=@var{n} @gol
+-fno-elide-constructors @gol
-fno-enforce-eh-specs @gol
-fno-gnu-keywords @gol
-fno-implicit-templates @gol
constant expression evaluation. The minimum specified by the standard
is 512.
+@item -fconstexpr-cache-depth=@var{n}
+@opindex fconstexpr-cache-depth
+Set the maximum level of nested evaluation depth for C++11 constexpr
+functions that will be cached to @var{n}. This is a heuristic that
+trades off compilation speed (when the cache avoids repeated
+calculations) against memory consumption (when the cache grows very
+large from highly recursive evaluations). The default is 8. Very few
+users are likely to want to adjust it, but if your code does heavy
+constexpr calculations you might want to experiment to find which
+value works best for you.
+
@item -fconstexpr-loop-limit=@var{n}
@opindex fconstexpr-loop-limit
Set the maximum number of iterations for a loop in C++14 constexpr functions