public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-contracts] c++: contracts postcondition id redeclaration
@ 2021-07-06 20:43 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-07-06 20:43 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:6e2be2d05164c927b04a384844d181d2114219ad
commit 6e2be2d05164c927b04a384844d181d2114219ad
Author: Jason Merrill <jason@redhat.com>
Date: Mon Jul 5 17:04:41 2021 -0400
c++: contracts postcondition id redeclaration
We were crashing because the variable for the postcondition identifier was
referring to the second declaration after it was ggc_freed. When we copy
the contracts from newdecl back to olddecl, we need to update the dummy
return variable's DECL_CONTEXT.
And the use of newdecl/olddecl here didn't match either the comment or the
use of those names in the call from duplicate_decls.
gcc/cp/ChangeLog:
* contracts.cc (copy_contract_attributes): Swap parameter names.
Call rebuild_postconditions.
Diff:
---
gcc/cp/contracts.cc | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index 4df25a104d2..c343fcf3f3b 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -896,17 +896,20 @@ tree splice_out_contracts (tree attributes)
/* Copy contract attributes from NEWDECL onto the attribute list of OLDDECL. */
-void copy_contract_attributes (tree newdecl, tree olddecl)
+void copy_contract_attributes (tree olddecl, tree newdecl)
{
tree attrs = NULL_TREE;
- for (tree c = DECL_CONTRACTS (olddecl); c; c = TREE_CHAIN (c))
+ for (tree c = DECL_CONTRACTS (newdecl); c; c = TREE_CHAIN (c))
{
if (!cxx_contract_attribute_p (c))
continue;
attrs = tree_cons (TREE_PURPOSE (c), TREE_VALUE (c), attrs);
}
- attrs = chainon (DECL_ATTRIBUTES (newdecl), nreverse (attrs));
- DECL_ATTRIBUTES (newdecl) = attrs;
+ attrs = chainon (DECL_ATTRIBUTES (olddecl), nreverse (attrs));
+ DECL_ATTRIBUTES (olddecl) = attrs;
+
+ /* And update DECL_CONTEXT of the postcondition result identifier. */
+ rebuild_postconditions (olddecl);
}
/* Returns the parameter corresponding to the return value of a guarded
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-06 20:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 20:43 [gcc/devel/c++-contracts] c++: contracts postcondition id redeclaration 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).