Skip to content

Commit e64de21

Browse files
authored
Merge pull request #7063 from remi-delmas-3000/contract-base-name-fix
CONTRACTS: filter out contract symbols when resolving entry points and interrupt handlers
2 parents fabaaf4 + 50dd44b commit e64de21

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int foo(char *arr, unsigned int size)
2+
// clang-format off
3+
__CPROVER_requires(__CPROVER_is_fresh(arr, size))
4+
__CPROVER_assigns(arr &&size > 0: arr[0])
5+
// clang-format on
6+
{
7+
if(arr && size > 0)
8+
arr[0] = 1;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-contract foo _ --function foo
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
This test checks that we can use a function with a contract as entry point
10+
for the analysis when its contract gets enforced.

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool ansi_c_entry_point(
130130
if(s_it==symbol_table.symbols.end())
131131
continue;
132132

133-
if(s_it->second.type.id()==ID_code)
133+
if(s_it->second.type.id() == ID_code && !s_it->second.is_property)
134134
matches.push_back(symbol_name_entry.second);
135135
}
136136

src/ansi-c/c_typecheck_base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ void c_typecheck_baset::typecheck_declaration(
877877
// create a contract symbol
878878
symbolt contract;
879879
contract.name = "contract::" + id2string(new_symbol.name);
880-
contract.base_name = new_symbol.name;
881-
contract.pretty_name = new_symbol.name;
880+
contract.base_name = new_symbol.base_name;
881+
contract.pretty_name = new_symbol.pretty_name;
882882
contract.is_property = true;
883883
contract.type = code_type;
884884
contract.mode = new_symbol.mode;

src/goto-instrument/interrupt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ get_isr(const symbol_tablet &symbol_table, const irep_idt &interrupt_handler)
165165
if(s_it==symbol_table.symbols.end())
166166
continue;
167167

168-
if(s_it->second.type.id()==ID_code)
168+
if(s_it->second.type.id() == ID_code && !s_it->second.is_property)
169169
matches.push_back(s_it->second.symbol_expr());
170170
}
171171

src/jsil/jsil_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool jsil_entry_point(
7474
if(s_it==symbol_table.symbols.end())
7575
continue;
7676

77-
if(s_it->second.type.id()==ID_code)
77+
if(s_it->second.type.id() == ID_code && !s_it->second.is_property)
7878
matches.push_back(symbol_name_entry.second);
7979
}
8080

0 commit comments

Comments
 (0)