Skip to content

Commit febb5cf

Browse files
authored
Merge pull request #5412 from NlightNFotis/fix_static_symbols_referencing
Fix static symbols referencing in harness file
2 parents f166858 + d8ad34f commit febb5cf

File tree

7 files changed

+76
-3
lines changed

7 files changed

+76
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "first_one.h"
2+
#include <assert.h>
3+
4+
static int static_function(int a)
5+
{
6+
assert(a == 0);
7+
return a;
8+
}
9+
10+
int non_static_function(int a)
11+
{
12+
return static_function(a);
13+
}
14+
15+
static int with_matching_signature(int a)
16+
{
17+
assert(0 && "this is not reachable as far as goto-harness is concerned");
18+
return 0;
19+
}
20+
21+
void non_static_with_non_matching_signature(void)
22+
{
23+
// this is just here so `static_with_matching_signature` has a non-file-local use
24+
assert(static_with_matching_signature(10) == 10);
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int non_static_function(int a);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "first_one.h"
2+
3+
int another(int (*fun_ptr)(int), int c)
4+
{
5+
int a = (*fun_ptr)(c);
6+
7+
return a;
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
dummy.c
3+
--function another --harness-type call-function
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[static_function\.assertion\.1\] line \d assertion a == 0: FAILURE
7+
\[non_static_with_non_matching_signature\.assertion\.1] line \d+ assertion static_with_matching_signature\(10\) == 10: SUCCESS
8+
9+
^VERIFICATION FAILED$
10+
--
11+
^CONVERSION ERROR$
12+
--
13+
For this particular error, we care mostly that goto-harness
14+
doesn't reference static symbols in other files, which would
15+
cause analysis through CBMC to fail with a conversion error.

src/goto-harness/recursive_initialization.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Diffblue Ltd.
88

99
#include "recursive_initialization.h"
1010

11+
#include <goto-programs/name_mangler.h>
1112
#include <util/allocate_objects.h>
1213
#include <util/arith_tools.h>
1314
#include <util/c_types.h>
@@ -1008,6 +1009,27 @@ code_blockt recursive_initializationt::build_function_pointer_constructor(
10081009
for(const auto &target : targets)
10091010
{
10101011
auto const assign = code_assignt{dereference_exprt{result}, target};
1012+
auto const sym_to_lookup =
1013+
target.id() == ID_address_of
1014+
?
1015+
// This is either address of or pointer; in pointer case, we don't
1016+
// need to do anything. In the address of case, the operand is
1017+
// a symbol representing a target function.
1018+
to_symbol_expr(to_address_of_expr(target).object()).get_identifier()
1019+
: "";
1020+
// skip referencing globals because the corresponding symbols in the symbol
1021+
// table are no longer marked as file local.
1022+
if(has_prefix(id2string(sym_to_lookup), FILE_LOCAL_PREFIX))
1023+
{
1024+
continue;
1025+
}
1026+
else if(
1027+
goto_model.get_symbol_table().lookup(sym_to_lookup) &&
1028+
goto_model.get_symbol_table().lookup(sym_to_lookup)->is_file_local)
1029+
{
1030+
continue;
1031+
}
1032+
10111033
if(function_pointer_index != targets.size() - 1)
10121034
{
10131035
auto const condition = equal_exprt{

src/goto-programs/name_mangler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ operator()(const symbolt &src, const std::string &extra_info)
1919
std::string basename = get_base_name(src.location.get_file().c_str(), false);
2020

2121
std::stringstream ss;
22-
ss << CPROVER_PREFIX << "file_local_";
22+
ss << FILE_LOCAL_PREFIX;
2323
ss << std::regex_replace(
2424
std::regex_replace(basename, forbidden, "_"), multi_under, "_")
2525
<< "_";
@@ -42,7 +42,7 @@ operator()(const symbolt &src, const std::string &extra_info)
4242
uint32_t eight_nibble_hash = (uint32_t)hash;
4343

4444
std::stringstream ss;
45-
ss << CPROVER_PREFIX << "file_local_" << std::setfill('0') << std::setw(8)
46-
<< std::hex << eight_nibble_hash << "_" << extra_info << "_" << src.name;
45+
ss << FILE_LOCAL_PREFIX << std::setfill('0') << std::setw(8) << std::hex
46+
<< eight_nibble_hash << "_" << extra_info << "_" << src.name;
4747
return irep_idt(ss.str());
4848
}

src/goto-programs/name_mangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <regex>
1414
#include <vector>
1515

16+
#define FILE_LOCAL_PREFIX CPROVER_PREFIX "file_local_"
17+
1618
/// \brief Mangles the names in an entire program and its symbol table
1719
///
1820
/// The type parameter to this class should be a functor that has a no-arg

0 commit comments

Comments
 (0)