Skip to content

Commit 6b6dae6

Browse files
authored
Merge pull request diffblue#7225 from tautschnig/bugfixes/7156-contracts-linking
Linking: accept the same contract from multiple translation units
2 parents 396ff10 + 8efe88d commit 6b6dae6

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdbool.h>
2+
3+
bool util_func(int a)
4+
// clang-format off
5+
__CPROVER_ensures(
6+
__CPROVER_return_value == true || __CPROVER_return_value == false)
7+
// clang-format on
8+
{
9+
if(a > 0)
10+
{
11+
return true;
12+
}
13+
else
14+
{
15+
return false;
16+
}
17+
}
18+
19+
int test1(int a);
20+
int test2(int a);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "header.h"
2+
3+
int test1(int a)
4+
{
5+
return util_func(a);
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "header.h"
2+
3+
int test2(int a)
4+
{
5+
return util_func(a);
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
module.c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$
9+
conflict on code contract
10+
--
11+
This test makes sure we support contracts in header files, which may then end up
12+
in multiple translation units.

src/linking/linking.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,15 @@ void linkingt::duplicate_non_type_symbol(
11051105
symbolt &old_symbol,
11061106
symbolt &new_symbol)
11071107
{
1108-
// we do not permit multiple contracts to be defined, or cases where only one
1109-
// of the symbols is a contract
1110-
if(old_symbol.is_property || new_symbol.is_property)
1108+
// we do not permit different contracts with the same name to be defined, or
1109+
// cases where only one of the symbols is a contract
1110+
if(
1111+
old_symbol.is_property != new_symbol.is_property ||
1112+
(old_symbol.is_property && new_symbol.is_property &&
1113+
old_symbol.type != new_symbol.type))
1114+
{
11111115
link_error(old_symbol, new_symbol, "conflict on code contract");
1116+
}
11121117

11131118
// see if it is a function or a variable
11141119

0 commit comments

Comments
 (0)