public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9989] c++: fix contracts with NRV
@ 2023-11-17 0:21 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2023-11-17 0:21 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:11afe64fb71c83cef7d56fe6c411fb7adeee59cb
commit r12-9989-g11afe64fb71c83cef7d56fe6c411fb7adeee59cb
Author: Jason Merrill <jason@redhat.com>
Date: Mon Jun 5 23:58:32 2023 -0400
c++: fix contracts with NRV
The NRV implementation was blindly replacing the operand of RETURN_EXPR,
clobbering anything that check_return_expr might have added on to the actual
initialization, such as checking the postcondition.
GCC 12 note: There are no contracts in GCC 12, but this issue also broke
setting current_retval_sentinel.
gcc/cp/ChangeLog:
* semantics.cc (finalize_nrv_r): [RETURN_EXPR]: Only replace the
INIT_EXPR.
Diff:
---
gcc/cp/semantics.cc | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 5289131e591..d6351d2d8a3 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -4859,9 +4859,17 @@ finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
*walk_subtrees = 0;
/* Change all returns to just refer to the RESULT_DECL; this is a nop,
but differs from using NULL_TREE in that it indicates that we care
- about the value of the RESULT_DECL. */
+ about the value of the RESULT_DECL. But preserve anything appended
+ by check_return_expr. */
else if (TREE_CODE (*tp) == RETURN_EXPR)
- TREE_OPERAND (*tp, 0) = dp->result;
+ {
+ tree *p = &TREE_OPERAND (*tp, 0);
+ while (TREE_CODE (*p) == COMPOUND_EXPR)
+ p = &TREE_OPERAND (*p, 0);
+ gcc_checking_assert (TREE_CODE (*p) == INIT_EXPR
+ && TREE_OPERAND (*p, 0) == dp->result);
+ *p = dp->result;
+ }
/* Change all cleanups for the NRV to only run when an exception is
thrown. */
else if (TREE_CODE (*tp) == CLEANUP_STMT
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-11-17 0:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 0:21 [gcc r12-9989] c++: fix contracts with NRV Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).