[FYI] c++: check for trying to cache non-constant expressions
Checks
Commit Message
Just for reference, not applying.
-- 8< --
This is what I used to check for what non-constant results we were
previously caching. After the previous two patches it's just address
of a local and a partially-uninitialized COMPLEX_EXPR.
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_call_expression): Add checking.
---
gcc/cp/constexpr.cc | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
base-commit: c7ac1de5f5c561b2d90c084a638c232d322d54e6
@@ -3206,6 +3206,11 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
cacheable = false;
break;
}
+ /* Also don't cache a call that returns a deallocated pointer. */
+ if (cacheable && CHECKING_P
+ && (cp_walk_tree_without_duplicates
+ (&result, find_heap_var_refs, NULL)))
+ cacheable = false;
}
/* Rewrite all occurrences of the function's RESULT_DECL with the
@@ -3215,10 +3220,6 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
&& !is_empty_class (TREE_TYPE (res)))
if (replace_decl (&result, res, ctx->object))
cacheable = false;
-
- /* Only cache a permitted result of a constant expression. */
- if (cacheable && !reduced_constant_expression_p (result))
- cacheable = false;
}
else
/* Couldn't get a function copy to evaluate. */
@@ -3230,6 +3231,18 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
result = error_mark_node;
else if (!result)
result = void_node;
+
+ /* Only cache a permitted result of a constant expression. */
+ if (cacheable && !reduced_constant_expression_p (result))
+ {
+ cacheable = false;
+ if (CHECKING_P
+ && result != void_node && result != error_mark_node
+ && !(TREE_CODE (result) == CONSTRUCTOR
+ && CONSTRUCTOR_NO_CLEARING (result)))
+ internal_error ("caching %qE", result);
+ }
+
if (entry)
entry->result = cacheable ? result : error_mark_node;
}