Skip to content

Commit a44feeb

Browse files
Merge pull request gcc-mirror#68 from iains/contracts-nonattr-fix-dbg-and-opt
c++, contracts: Fix debug and optimisation.
2 parents 4030af5 + 7cacfc7 commit a44feeb

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

gcc/cp/contracts.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ build_contract_condition_function (tree fndecl, bool pre)
15591559

15601560
DECL_NAME (fn) = copy_node (DECL_NAME (fn));
15611561
DECL_INITIAL (fn) = error_mark_node;
1562-
DECL_ABSTRACT_ORIGIN (fn) = fndecl;
1562+
CONTRACT_HELPER (fn) = pre ? ldf_contract_pre : ldf_contract_post;
15631563

15641564
IDENTIFIER_VIRTUAL_P (DECL_NAME (fn)) = false;
15651565
DECL_VIRTUAL_P (fn) = false;
@@ -1662,7 +1662,7 @@ handle_contracts_p (tree fndecl)
16621662
{
16631663
return (flag_contracts
16641664
&& !processing_template_decl
1665-
&& (DECL_ABSTRACT_ORIGIN (fndecl) == NULL_TREE)
1665+
&& (CONTRACT_HELPER (fndecl) == ldf_contract_none)
16661666
&& contract_any_active_p (DECL_CONTRACTS (fndecl)));
16671667
}
16681668

gcc/cp/contracts.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,13 @@ enum contract_matching_context
311311

312312
/* True iff the FUNCTION_DECL is the pre function for a guarded function. */
313313
#define DECL_IS_PRE_FN_P(NODE) \
314-
(DECL_ABSTRACT_ORIGIN (NODE) && DECL_PRE_FN (DECL_ABSTRACT_ORIGIN (NODE)) == NODE)
314+
(DECL_DECLARES_FUNCTION_P (NODE) && DECL_LANG_SPECIFIC (NODE) && \
315+
CONTRACT_HELPER (NODE) == ldf_contract_pre)
315316

316317
/* True iff the FUNCTION_DECL is the post function for a guarded function. */
317318
#define DECL_IS_POST_FN_P(NODE) \
318-
(DECL_ABSTRACT_ORIGIN (NODE) && DECL_POST_FN (DECL_ABSTRACT_ORIGIN (NODE)) == NODE)
319-
319+
(DECL_DECLARES_FUNCTION_P (NODE) && DECL_LANG_SPECIFIC (NODE) && \
320+
CONTRACT_HELPER (NODE) == ldf_contract_post)
320321

321322
extern void remove_contract_attributes (tree);
322323
extern void copy_contract_attributes (tree, tree);

gcc/cp/cp-tree.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3015,6 +3015,13 @@ struct GTY(()) lang_decl_min {
30153015
tree access;
30163016
};
30173017

3018+
enum lang_contract_helper
3019+
{
3020+
ldf_contract_none = 0,
3021+
ldf_contract_pre,
3022+
ldf_contract_post
3023+
};
3024+
30183025
/* Additional DECL_LANG_SPECIFIC information for functions. */
30193026

30203027
struct GTY(()) lang_decl_fn {
@@ -3045,8 +3052,9 @@ struct GTY(()) lang_decl_fn {
30453052

30463053
unsigned xobj_func : 1;
30473054
unsigned contract_wrapper : 1;
3055+
ENUM_BITFIELD(lang_contract_helper) contract_helper : 2;
30483056

3049-
unsigned spare : 6;
3057+
unsigned spare : 4;
30503058

30513059
/* 32-bits padding on 64-bit host. */
30523060

@@ -3194,6 +3202,9 @@ struct GTY(()) lang_decl {
31943202

31953203
#endif /* ENABLE_TREE_CHECKING */
31963204

3205+
#define CONTRACT_HELPER(NODE) \
3206+
(LANG_DECL_FN_CHECK (NODE)->contract_helper)
3207+
31973208
/* For a FUNCTION_DECL or a VAR_DECL, the language linkage for the
31983209
declaration. Some entities (like a member function in a local
31993210
class, or a local variable) do not have linkage at all, and this

gcc/cp/mangle.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,9 @@ write_mangled_name (const tree decl, bool top_level)
822822
/* If this is the pre/post function for a guarded function, append
823823
.pre/post, like something from create_virtual_clone. */
824824
if (DECL_IS_PRE_FN_P (decl))
825-
write_string (".pre");
825+
write_string (JOIN_STR "pre");
826826
else if (DECL_IS_POST_FN_P (decl))
827-
write_string (".post");
827+
write_string (JOIN_STR "post");
828828

829829
/* If this is a coroutine helper, then append an appropriate string to
830830
identify which. */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// { dg-options "-std=c++23 -fcontracts -fcontracts-nonattr -fcontract-evaluation-semantic=observe" }
2+
// { dg-additional-options "-O -g" }
3+
4+
// Check that we do not ICE with debug + optimisation.
5+
6+
int foo (const int i)
7+
pre (i > 3)
8+
{
9+
return i;
10+
}
11+
12+
int main()
13+
{
14+
foo (1);
15+
}

0 commit comments

Comments
 (0)