aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.cc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2023-02-08 19:13:18 -0500
committerMarek Polacek <polacek@redhat.com>2023-02-20 12:29:35 -0500
commitb2287a4d9a640fdc2caef6a067830ea65044deb7 (patch)
treee7ad2d9875dcbd7b463a442fa801044a6ad23cf4 /gcc/cp/constexpr.cc
parentbb920f561e983c64d146f173dc4ebc098441a962 (diff)
downloadgcc-b2287a4d9a640fdc2caef6a067830ea65044deb7.zip
gcc-b2287a4d9a640fdc2caef6a067830ea65044deb7.tar.gz
gcc-b2287a4d9a640fdc2caef6a067830ea65044deb7.tar.bz2
c++: ICE with -fno-elide-constructors and trivial fn [PR101073]
In constexpr-nsdmi3.C, with -fno-elide-constructors, we don't elide the Y::Y(const Y&) call used to initialize o.c. So store_init_value -> cxx_constant_init must constexpr-evaluate the call to Y::Y(const Y&) in cxx_eval_call_expression. It's a trivial function, so we do the "Shortcut trivial constructor/op=" code and rather than evaluating the function, we just create an assignment o.c = *(const struct Y &) (const struct Y *) &(&<PLACEHOLDER_EXPR struct X>)->b which is a MODIFY_EXPR, so the preeval code in cxx_eval_store_expression clears .ctor and .object, therefore we can't replace the PLACEHOLDER_EXPR whereupon we crash at /* A placeholder without a referent. We can get here when checking whether NSDMIs are noexcept, or in massage_init_elt; just say it's non-constant for now. */ gcc_assert (ctx->quiet); The PLACEHOLDER_EXPR can also be on the LHS as in constexpr-nsdmi10.C. I don't think we can do much here, but I noticed that the whole trivial_fn_p (fun) block is only entered when -fno-elide-constructors. This is true since GCC 9; it wasn't easy to bisect what changes made it so, but r240845 is probably one of them. -fno-elide-constructors is an option for experiments only so it's not clear to me why we'd still want to shortcut trivial constructor/op=. I propose to remove the code and add a checking assert to make sure we're not getting a trivial_fn_p unless -fno-elide-constructors. PR c++/101073 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_call_expression): Replace shortcutting trivial constructor/op= with a checking assert. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-nsdmi3.C: New test. * g++.dg/cpp1y/constexpr-nsdmi10.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r--gcc/cp/constexpr.cc25
1 files changed, 3 insertions, 22 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index aa2c1435..b4d3e95 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -2866,28 +2866,9 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
ctx = &new_ctx;
}
- /* Shortcut trivial constructor/op=. */
- if (trivial_fn_p (fun))
- {
- tree init = NULL_TREE;
- if (call_expr_nargs (t) == 2)
- init = convert_from_reference (get_nth_callarg (t, 1));
- else if (TREE_CODE (t) == AGGR_INIT_EXPR
- && AGGR_INIT_ZERO_FIRST (t))
- init = build_zero_init (DECL_CONTEXT (fun), NULL_TREE, false);
- if (init)
- {
- tree op = get_nth_callarg (t, 0);
- if (is_dummy_object (op))
- op = ctx->object;
- else
- op = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (op)), op);
- tree set = build2 (MODIFY_EXPR, TREE_TYPE (op), op, init);
- new_ctx.call = &new_call;
- return cxx_eval_constant_expression (&new_ctx, set, lval,
- non_constant_p, overflow_p);
- }
- }
+ /* We used to shortcut trivial constructor/op= here, but nowadays
+ we can only get a trivial function here with -fno-elide-constructors. */
+ gcc_checking_assert (!trivial_fn_p (fun) || !flag_elide_constructors);
bool non_constant_args = false;
new_call.bindings