Skip to content

Commit c50de43

Browse files
committed
CONTRACTS: is_fresh declarations are handled via the symbol table
Update the symbol table and auto-generate __CPROVER_initialize instead of hand-tweaking the function. This will ensure that any further rebuilding of __CPROVER_initialize preserves those changes.
1 parent 9f9ee07 commit c50de43

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/goto-instrument/contracts/memory_predicates.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Date: July 2021
1616
#include <ansi-c/ansi_c_language.h>
1717
#include <ansi-c/expr2c.h>
1818

19+
#include <goto-programs/goto_convert_functions.h>
20+
1921
#include <linking/static_lifetime_init.h>
2022

2123
#include <util/config.h>
@@ -188,21 +190,18 @@ void is_fresh_baset::add_declarations(const std::string &decl_string)
188190
}
189191
}
190192

191-
// We have to set the global memory map array to
192-
// all zeros for this to work properly
193-
const array_typet ty =
194-
to_array_type(tmp_symbol_table.lookup_ref(memmap_name).type);
195-
constant_exprt initial_value(irep_idt(dstringt("0")), ty.subtype());
196-
array_of_exprt memmap_init(initial_value, ty);
197-
goto_programt::instructiont a =
198-
goto_programt::make_assignment(symbol_exprt(memmap_name, ty), memmap_init);
199-
200-
// insert the assignment into the initialize function.
201-
auto called_func =
202-
parent.get_goto_functions().function_map.find(INITIALIZE_FUNCTION);
203-
goto_programt &body = called_func->second.body;
204-
auto target = body.get_end_function();
205-
body.insert_before(target, a);
193+
if(parent.get_goto_functions().function_map.erase(INITIALIZE_FUNCTION) != 0)
194+
{
195+
static_lifetime_init(
196+
parent.get_symbol_table(),
197+
parent.get_symbol_table().lookup_ref(INITIALIZE_FUNCTION).location);
198+
goto_convert(
199+
INITIALIZE_FUNCTION,
200+
parent.get_symbol_table(),
201+
parent.get_goto_functions(),
202+
log.get_message_handler());
203+
parent.get_goto_functions().update();
204+
}
206205
}
207206

208207
void is_fresh_baset::update_fn_call(

0 commit comments

Comments
 (0)