c++: constexpr-evaluate more assumes
commite6a29aab51122103e677ffed523371c9c816ec98
authorJason Merrill <jason@redhat.com>
Tue, 25 Oct 2022 00:36:32 +0000 (24 20:36 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 25 Oct 2022 16:38:26 +0000 (25 12:38 -0400)
tree54f053da8bde4ffac115f19216fee5d14ce45573
parentac8f92c18886057261d61d45b8d339629464c77e
c++: constexpr-evaluate more assumes

The initial [[assume]] support avoided evaluating assumes with
TREE_SIDE_EFFECTS set, such as calls, because we don't want any side-effects
that change the constexpr state.  This patch allows us to evaluate
expressions with that flag set by tracking which variables the evaluation is
allowed to modify, and giving up if it tries to touch any others.

I considered allowing changes to other variables and then rolling them back,
but that seems like a rare enough situation that it doesn't seem worth
working to handle nicely at this point.

gcc/cp/ChangeLog:

* constexpr.cc (class constexpr_global_ctx): Add modifiable field,
get_value, get_value_ptr, put_value, remove_value, flush_modifiable
member functions.
(class modifiable_tracker): New.
(cxx_eval_internal_function): Use it.
(diagnose_failing_condition): Strip CLEANUP_POINT_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/attr-assume9.C: New test.
* g++.dg/cpp23/attr-assume10.C: New test.
gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp23/attr-assume10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp23/attr-assume9.C [new file with mode: 0644]