@@ -980,6 +980,20 @@ extract_contract_attributes (tree fndecl)
980
980
return contracts;
981
981
}
982
982
983
+ /*
984
+ */
985
+
986
+ /* Set contracts of FNDECL to be CONTRACTS. */
987
+
988
+ void
989
+ set_contract_attributes (tree fndecl, tree contracts)
990
+ {
991
+ remove_contract_attributes (fndecl);
992
+ tree attrs = chainon (DECL_ATTRIBUTES (fndecl), contracts);
993
+ DECL_ATTRIBUTES (fndecl) = attrs;
994
+ }
995
+
996
+
983
997
/* Copy contract attributes from NEWDECL onto the attribute list of
984
998
OLDDECL. */
985
999
@@ -3049,11 +3063,6 @@ maybe_apply_function_contracts (tree fndecl)
3049
3063
/* We should not have reached here with nothing to do... */
3050
3064
gcc_checking_assert (do_pre || do_post);
3051
3065
3052
- if (contract_any_deferred_p (DECL_CONTRACTS (fndecl)))
3053
- {
3054
- // debug_tree (DECL_CONTRACTS (fndecl));
3055
- }
3056
-
3057
3066
/* If the function is noexcept, the user's written body will be wrapped in a
3058
3067
MUST_NOT_THROW expression. In that case we want to extract the body from
3059
3068
that and build the replacement (including the pre and post-conditions as
@@ -3126,16 +3135,18 @@ maybe_apply_function_contracts (tree fndecl)
3126
3135
If remap_post is false, postconditions are dropped from the destination. */
3127
3136
3128
3137
tree
3129
- remap_contracts (tree dest, tree source, bool remap_result = true ,
3130
- bool remap_post = true )
3138
+ copy_and_remap_contracts (tree dest, tree source, bool remap_result = true ,
3139
+ contract_match_kind remap_kind = cmk_all )
3131
3140
{
3132
3141
tree last = NULL_TREE, contract_attrs = NULL_TREE;
3133
3142
for (tree a = DECL_CONTRACTS (source);
3134
3143
a != NULL_TREE;
3135
3144
a = CONTRACT_CHAIN (a))
3136
3145
{
3137
- if (!remap_post
3138
- && (TREE_CODE (CONTRACT_STATEMENT (a)) == POSTCONDITION_STMT))
3146
+ if ((remap_kind == cmk_pre
3147
+ && (TREE_CODE (CONTRACT_STATEMENT (a)) == POSTCONDITION_STMT))
3148
+ || (remap_kind == cmk_post
3149
+ && (TREE_CODE (CONTRACT_STATEMENT (a)) == PRECONDITION_STMT)))
3139
3150
continue ;
3140
3151
3141
3152
tree c = copy_node (a);
@@ -3535,18 +3546,19 @@ define_contract_wrapper_func (const tree& fndecl, const tree& wrapdecl, void*)
3535
3546
bool is_virtual = DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
3536
3547
&& DECL_VIRTUAL_P (fndecl);
3537
3548
/* We check postconditions on virtual function calls or if postcondition
3538
- checks are enabled for all clients. We should not get here unless there
3549
+ checks are enabled for clients. We should not get here unless there
3539
3550
are some checks to make. */
3540
3551
bool check_post
3541
3552
= (flag_contract_nonattr_client_check > 1 )
3542
3553
|| (is_virtual
3543
3554
&& (flag_contracts_on_virtual_functions
3544
- == CONTRACTS_ON_VIRTUALS_P2900R13 ));
3555
+ != CONTRACTS_ON_VIRTUALS_NONE ));
3545
3556
/* For wrappers on CDTORs we need to refer to the original contracts,
3546
3557
when the wrapper is around a clone. */
3547
3558
set_decl_contracts ( wrapdecl,
3548
- remap_contracts (wrapdecl, DECL_ORIGIN (fndecl),
3549
- /* remap_result*/ true , check_post));
3559
+ copy_and_remap_contracts (wrapdecl, DECL_ORIGIN (fndecl),
3560
+ /* remap_result*/ true ,
3561
+ check_post? cmk_all : cmk_pre));
3550
3562
3551
3563
start_preparsed_function (wrapdecl, /* DECL_ATTRIBUTES*/ NULL_TREE,
3552
3564
SF_DEFAULT | SF_PRE_PARSED);
0 commit comments