Skip to content

Commit 7a5d238

Browse files
Merge pull request gcc-mirror#83 from NinaRanns/contracts-various-fixes
various fixes
2 parents 1eb297e + 97cb15d commit 7a5d238

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed

gcc/cp/contracts.cc

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,11 @@ build_contract_condition_function (tree fndecl, bool pre)
14741474
including the original contracts. */
14751475
DECL_ATTRIBUTES (fn) = NULL_TREE;
14761476

1477+
/* DECL_ASSEMBLER_NAME will be copied from FNDECL if it's already set. Unset
1478+
it so fn name later gets mangled according to the rules for pre and post
1479+
functions. */
1480+
SET_DECL_ASSEMBLER_NAME (fn, NULL_TREE);
1481+
14771482
/* If requested, disable optimisation of checking functions; this can, in
14781483
some cases, prevent UB from eliding the checks themselves. */
14791484
if (flag_contract_disable_optimized_checks)
@@ -1939,8 +1944,6 @@ build_contract_wrapper_function (tree fndecl, bool is_cvh)
19391944

19401945
/* Copy selected attributes from the original function. */
19411946
TREE_USED (wrapdecl) = TREE_USED (fndecl);
1942-
if (DECL_SECTION_NAME (fndecl))
1943-
set_decl_section_name (wrapdecl, fndecl);
19441947

19451948
/* Copy any alignment that the FE added. */
19461949
if (DECL_ALIGN (fndecl))
@@ -3430,14 +3433,6 @@ maybe_contract_wrap_call (tree fndecl, tree call)
34303433
if (!should_contract_wrap_call (do_pre, do_post, is_virtual))
34313434
return call;
34323435

3433-
/* We should not have reached here with nothing to do. */
3434-
/* We check postconditions on virtual function calls or if postcondition
3435-
checks are enabled for all clients. */
3436-
gcc_checking_assert (do_pre
3437-
|| (do_post
3438-
&& ((flag_contract_nonattr_client_check > 1)
3439-
|| is_virtual)));
3440-
34413436
/* Build the declaration of the wrapper, if we need to. */
34423437
tree wrapdecl = get_contract_wrapper_function (fndecl);
34433438
if (!wrapdecl)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check that we do not a section type conflict with virtual bases or a duplicate symbol
2+
// { dg-do run }
3+
// { dg-options "-fcontracts -std=c++23 -fcontracts-nonattr" }
4+
5+
int x = 9;
6+
struct Base
7+
{
8+
virtual void f(){};
9+
};
10+
11+
12+
struct Child0 : virtual Base
13+
{
14+
virtual void f() pre(x>2) {};
15+
};
16+
17+
18+
19+
int main(int, char**)
20+
{
21+
Base b0;
22+
Child0 c0;
23+
c0.f();
24+
}

gcc/testsuite/g++.dg/contracts/cpp26/virtual_func.C

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// test that contracts on overriding functions are found correctly
2-
// { dg-do compile }
3-
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on -fcontracts-nonattr -g3" }
2+
// { dg-do run }
3+
// { dg-options "-std=c++2a -fcontracts -fcontract-continuation-mode=on -fcontracts-nonattr" }
44
#include <cstdio>
55

66
struct Base
@@ -62,33 +62,33 @@ int main(int, char**)
6262
return 0;
6363
}
6464

65-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 5.*(\n|\r\n|\r)" }
65+
// { dg-output "contract violation in function .* at .*: a > 5.*(\n|\r\n|\r)" }
6666
// { dg-output "contract violation in function Base::f at .*: a > 5.*(\n|\r\n|\r)" }
6767
// { dg-output "Base: 3(\n|\r\n|\r)" }
68-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 5.*(\n|\r\n|\r)" }
68+
// { dg-output "contract violation in function .* at .*: a > 5.*(\n|\r\n|\r)" }
6969
// { dg-output "contract violation in function Base::f at .*: a > 5.*(\n|\r\n|\r)" }
7070
// { dg-output "Child0: 3(\n|\r\n|\r)" }
71-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 14.*(\n|\r\n|\r)" }
71+
// { dg-output "contract violation in function .* at .*: a > 14.*(\n|\r\n|\r)" }
7272
// { dg-output "contract violation in function Child1::f at .*: a > 14.*(\n|\r\n|\r)" }
7373
// { dg-output "Child1: 17(\n|\r\n|\r)" }
7474
// { dg-output "contract violation in function GChild1::f at .*: a > 6.*(\n|\r\n|\r)" }
75-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 6.*(\n|\r\n|\r)" }
75+
// { dg-output "contract violation in function .* at .*: a > 6.*(\n|\r\n|\r)" }
7676
// { dg-output "GChild1: 103(\n|\r\n|\r)" }
7777
// { dg-output "contract violation in function GChild2::f at .*: a > 30.*(\n|\r\n|\r)" }
78-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 30.*(\n|\r\n|\r)" }
78+
// { dg-output "contract violation in function .* at .*: a > 30.*(\n|\r\n|\r)" }
7979
// { dg-output "GChild2: 207(\n|\r\n|\r)" }
80-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 5.*(\n|\r\n|\r)" }
80+
// { dg-output "contract violation in function .* at .*: a > 5.*(\n|\r\n|\r)" }
8181
// { dg-output "contract violation in function Base::f at .*: a > 5.*(\n|\r\n|\r)" }
8282
// { dg-output "fooBase.Base.: 1(\n|\r\n|\r)" }
83-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 5.*(\n|\r\n|\r)" }
83+
// { dg-output "contract violation in function .* at .*: a > 5.*(\n|\r\n|\r)" }
8484
// { dg-output "contract violation in function Base::f at .*: a > 5.*(\n|\r\n|\r)" }
8585
// { dg-output "fooBase.Child0.: 1(\n|\r\n|\r)" }
86-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 5.*(\n|\r\n|\r)" }
86+
// { dg-output "contract violation in function .* at .*: a > 5.*(\n|\r\n|\r)" }
8787
// { dg-output "contract violation in function Child1::f at .*: a > 14.*(\n|\r\n|\r)" }
8888
// { dg-output "fooBase.Child1.: 11(\n|\r\n|\r)" }
89-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 5.*(\n|\r\n|\r)" }
89+
// { dg-output "contract violation in function .* at .*: a > 5.*(\n|\r\n|\r)" }
9090
// { dg-output "contract violation in function GChild1::f at .*: a > 6.*(\n|\r\n|\r)" }
9191
// { dg-output "fooBase.GChild1.: 101(\n|\r\n|\r)" }
92-
// { dg-output "contract violation in function .*contract_wrapper at .*: a > 5.*(\n|\r\n|\r)" }
92+
// { dg-output "contract violation in function .* at .*: a > 5.*(\n|\r\n|\r)" }
9393
// { dg-output "contract violation in function GChild2::f at .*: a > 30.*(\n|\r\n|\r)" }
9494
// { dg-output "fooBase.GChild2.: 201(\n|\r\n|\r)" }

0 commit comments

Comments
 (0)