@@ -1547,7 +1547,8 @@ build_contract_condition_function (tree fndecl, bool pre)
1547
1547
DECL_NAME (fn) = copy_node (DECL_NAME (fn));
1548
1548
DECL_INITIAL (fn) = NULL_TREE;
1549
1549
CONTRACT_HELPER (fn) = pre ? ldf_contract_pre : ldf_contract_post;
1550
- DECL_CONTRACT_WRAPPER (fn) = false ;
1550
+ /* We might have a pre/post for a wrapper. */
1551
+ DECL_CONTRACT_WRAPPER (fn) = DECL_CONTRACT_WRAPPER (fndecl);
1551
1552
1552
1553
IDENTIFIER_VIRTUAL_P (DECL_NAME (fn)) = false ;
1553
1554
DECL_VIRTUAL_P (fn) = false ;
@@ -1863,15 +1864,7 @@ build_contract_wrapper_function (tree fndecl, bool is_cvh)
1863
1864
if (is_cvh)
1864
1865
fnname = get_identifier (" handle_contract_violation.noexcept_wrapper" );
1865
1866
else
1866
- {
1867
- /* Use mangled name so we can differentiate between different virtual
1868
- functions of the same name. */
1869
- const char *name = IDENTIFIER_POINTER ((mangle_decl_string (fndecl)));
1870
- char *buf = xasprintf (" %s.contract_wrapper" , name);
1871
- fnname = get_identifier (buf);
1872
- free (buf);
1873
- }
1874
-
1867
+ fnname = copy_node (DECL_NAME (fndecl));
1875
1868
location_t loc = DECL_SOURCE_LOCATION (fndecl);
1876
1869
1877
1870
/* Handle the arg types list. */
@@ -1898,19 +1891,20 @@ build_contract_wrapper_function (tree fndecl, bool is_cvh)
1898
1891
if (flag_exceptions && (is_cvh || type_noexcept_p (TREE_TYPE (fndecl))))
1899
1892
wrapper_type = build_exception_variant (wrapper_type, noexcept_true_spec);
1900
1893
1901
- /* This will create a member function if fndecl is a member function, so we
1902
- will need to adjust the type later. */
1903
1894
tree wrapdecl
1904
1895
= build_lang_decl_loc (loc, FUNCTION_DECL, fnname, wrapper_type);
1905
1896
1906
- DECL_CONTEXT (wrapdecl) = NULL_TREE;
1897
+ /* Put the wrapper in the same context as the callee. */
1898
+ DECL_CONTEXT (wrapdecl) = DECL_CONTEXT (fndecl);
1899
+ if (!is_cvh)
1900
+ /* This declaration is a contract wrapper function. */
1901
+ DECL_CONTRACT_WRAPPER (wrapdecl) = true ;
1902
+
1907
1903
DECL_SOURCE_LOCATION (wrapdecl) = loc;
1908
1904
/* The declaration was implicitly generated by the compiler. */
1909
1905
DECL_ARTIFICIAL (wrapdecl) = true ;
1910
1906
/* Declaration, no definition yet. */
1911
1907
DECL_INITIAL (wrapdecl) = NULL_TREE;
1912
- /* This declaration is a contract wrapper function. */
1913
- DECL_CONTRACT_WRAPPER (wrapdecl) = true ;
1914
1908
1915
1909
/* Let the start function code fill in the result decl. */
1916
1910
DECL_RESULT (wrapdecl) = NULL_TREE;
@@ -2351,7 +2345,6 @@ declare_noexcept_cvh_wrapper (tree fncvh_decl)
2351
2345
if (!wrapdecl)
2352
2346
{
2353
2347
wrapdecl = build_contract_wrapper_function (fncvh_decl, /* is_cvh*/ true );
2354
- wrapdecl = pushdecl_top_level (wrapdecl);
2355
2348
set_contract_wrapper_function (fncvh_decl, wrapdecl);
2356
2349
}
2357
2350
@@ -2842,9 +2835,13 @@ start_function_contracts (tree fndecl)
2842
2835
/* If this is not a client side check and definition side checks are
2843
2836
disabled, do nothing. */
2844
2837
if (!flag_contracts_nonattr_definition_check
2845
- && !DECL_CONTRACT_WRAPPER (fndecl))
2838
+ && !DECL_CONTRACT_WRAPPER (fndecl))
2846
2839
return ;
2847
2840
2841
+ /* Even if we will use an outlined function for the check (which will be the
2842
+ same one we might use on the callee-side) we still need to check the re-
2843
+ mapped contracts for shadowing. */
2844
+
2848
2845
/* Check that the user did not try to shadow a function parameter with the
2849
2846
specified postcondition result name. */
2850
2847
if (flag_contracts_nonattr)
0 commit comments