Skip to content

Commit d1960c2

Browse files
committed
c++, contracts: Update handling of pre/post decls to avoid dups.
1 parent 7b2eb4b commit d1960c2

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

gcc/cp/contracts.cc

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,8 +1404,8 @@ static GTY(()) tree contracts_source_location_type;
14041404
tree
14051405
get_precondition_function (tree fndecl)
14061406
{
1407-
hash_map_maybe_create<hm_ggc> (decl_pre_fn);
1408-
tree *result = decl_pre_fn->get (fndecl);
1407+
gcc_checking_assert (fndecl);
1408+
tree *result = hash_map_safe_get (decl_pre_fn, fndecl);
14091409
return result ? *result : NULL_TREE;
14101410
}
14111411

@@ -1414,8 +1414,8 @@ get_precondition_function (tree fndecl)
14141414
tree
14151415
get_postcondition_function (tree fndecl)
14161416
{
1417-
hash_map_maybe_create<hm_ggc> (decl_post_fn);
1418-
tree *result = decl_post_fn->get (fndecl);
1417+
gcc_checking_assert (fndecl);
1418+
tree *result = hash_map_safe_get (decl_post_fn, fndecl);
14191419
return result ? *result : NULL_TREE;
14201420
}
14211421

@@ -1442,13 +1442,15 @@ set_postcondition_function (tree fndecl, tree post)
14421442
}
14431443

14441444
/* Set the PRE and POST functions for FNDECL. Note that PRE and POST can
1445-
be null in this case. If so the functions are not recorded. */
1445+
be null in this case. If so the functions are not recorded. Used by the
1446+
modules code. */
14461447

14471448
void
14481449
set_contract_functions (tree fndecl, tree pre, tree post)
14491450
{
14501451
if (pre)
14511452
set_precondition_function (fndecl, pre);
1453+
14521454
if (post)
14531455
set_postcondition_function (fndecl, post);
14541456
}
@@ -1550,6 +1552,7 @@ build_contract_condition_function (tree fndecl, bool pre)
15501552
DECL_NAME (fn) = copy_node (DECL_NAME (fn));
15511553
DECL_INITIAL (fn) = NULL_TREE;
15521554
CONTRACT_HELPER (fn) = pre ? ldf_contract_pre : ldf_contract_post;
1555+
DECL_CONTRACT_WRAPPER (fn) = false;
15531556

15541557
IDENTIFIER_VIRTUAL_P (DECL_NAME (fn)) = false;
15551558
DECL_VIRTUAL_P (fn) = false;
@@ -1709,10 +1712,20 @@ build_contract_function_decls (tree fndecl)
17091712
if (!outline_contracts_p (fndecl))
17101713
return;
17111714

1712-
/* Build the pre/post functions (or not). */
1713-
tree pre = build_precondition_function (fndecl);
1714-
tree post = build_postcondition_function (fndecl);
1715-
set_contract_functions (fndecl, pre, post);
1715+
if (!get_precondition_function (fndecl))
1716+
{
1717+
/* Build the pre/post functions (or not). */
1718+
tree pre = build_precondition_function (fndecl);
1719+
if (pre)
1720+
set_precondition_function (fndecl, pre);
1721+
}
1722+
1723+
if (!get_postcondition_function (fndecl))
1724+
{
1725+
tree post = build_postcondition_function (fndecl);
1726+
if (post)
1727+
set_postcondition_function (fndecl, post);
1728+
}
17161729
}
17171730

17181731
/* Build a layout-compatible internal version of source location __impl

0 commit comments

Comments
 (0)