public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-contracts] c++: use cleanup for cdtor postconditions
@ 2022-10-17 21:16 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-10-17 21:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:99e1cabe020ca94e63008f1b5f7e0a7df11b4cfc
commit 99e1cabe020ca94e63008f1b5f7e0a7df11b4cfc
Author: Jason Merrill <jason@redhat.com>
Date: Mon Oct 17 15:59:51 2022 -0400
c++: use cleanup for cdtor postconditions
The contracts branch used the cdtor label for emitting postconditions, but
that's been removed on trunk, so let's use a CLEANUP_STMT instead. And tell
set_cleanup_locs to leave its location alone.
gcc/cp/ChangeLog:
* cp-tree.h (emit_postconditions): Rename...
(emit_postconditions_cleanup): ...to this.
* contracts.cc: Likewise.
* decl.cc (maybe_return_this): Don't emit_postconditions.
(begin_destructor_body): Do it here.
* semantics.cc (finish_mem_initializers): And here.
(set_cleanup_locs): Don't mess with POSTCONDITION_STMT.
Diff:
---
gcc/cp/cp-tree.h | 2 +-
gcc/cp/contracts.cc | 7 +++++--
gcc/cp/decl.cc | 8 +++-----
gcc/cp/semantics.cc | 4 +++-
4 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index f171ebc6eba..29d49466525 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -7785,7 +7785,7 @@ extern tree get_contracts_original_fn (tree);
extern void emit_assertion (tree);
extern void emit_preconditions (tree);
-extern void emit_postconditions (tree);
+extern void emit_postconditions_cleanup (tree);
extern void maybe_update_postconditions (tree);
extern void start_function_contracts (tree);
extern void finish_function_contracts (tree);
diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index 0efbfb176c8..93048f7203d 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -1748,9 +1748,12 @@ emit_preconditions (tree attr)
/* Emit statements for postcondition attributes. */
void
-emit_postconditions (tree contracts)
+emit_postconditions_cleanup (tree contracts)
{
- return emit_contract_conditions (contracts, POSTCONDITION_STMT);
+ tree stmts = push_stmt_list ();
+ emit_contract_conditions (contracts, POSTCONDITION_STMT);
+ stmts = pop_stmt_list (stmts);
+ push_cleanup (NULL_TREE, stmts, /*eh_only*/false);
}
/* We're compiling the pre/postcondition function CONDFN; remap any FN
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 613a715f5cf..1384358d079 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -17816,9 +17816,6 @@ store_parm_decls (tree current_function_parms)
void
maybe_return_this (void)
{
- // FIXME make this work like other functions
- emit_postconditions (DECL_CONTRACTS (current_function_decl));
-
if (targetm.cxx.cdtor_returns_this ())
{
/* Return the address of the object. */
@@ -17840,6 +17837,9 @@ begin_destructor_body (void)
{
tree compound_stmt;
+ emit_preconditions (DECL_CONTRACTS (current_function_decl));
+ emit_postconditions_cleanup (DECL_CONTRACTS (current_function_decl));
+
/* If the CURRENT_CLASS_TYPE is incomplete, we will have already
issued an error message. We still want to try to process the
body of the function, but initialize_vtbl_ptrs will crash if
@@ -17898,8 +17898,6 @@ begin_destructor_body (void)
will be properly destroyed if we throw. */
push_base_cleanups ();
}
-
- emit_preconditions (DECL_CONTRACTS (current_function_decl));
}
/* Do the necessary processing for the beginning of a function body, which
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 9174375567d..05db605a701 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -610,7 +610,8 @@ set_cleanup_locs (tree stmts, location_t loc)
if (TREE_CODE (stmts) == CLEANUP_STMT)
{
tree t = CLEANUP_EXPR (stmts);
- protected_set_expr_location (t, loc);
+ if (t && TREE_CODE (t) != POSTCONDITION_STMT)
+ protected_set_expr_location (t, loc);
/* Avoid locus differences for C++ cdtor calls depending on whether
cdtor_returns_this: a conversion to void is added to discard the return
value, and this conversion ends up carrying the location, and when it
@@ -2063,6 +2064,7 @@ finish_mem_initializers (tree mem_inits)
else
{
emit_preconditions (DECL_CONTRACTS (current_function_decl));
+ emit_postconditions_cleanup (DECL_CONTRACTS (current_function_decl));
emit_mem_initializers (mem_inits);
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-10-17 21:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-17 21:16 [gcc/devel/c++-contracts] c++: use cleanup for cdtor postconditions 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).