Skip to content

Commit d9e83d4

Browse files
committed
Library functions: mark them as compiled
When adding library functions to the goto model we no longer need their function bodies as values in the symbol table. Marking them as "compiled" will make sure we don't re-convert them in any subsequent run (e.g., running cbmc after goto-instrument). Doing so would undo any application of "drop-unused-functions." This was most notable with contracts/dynamic frames, where we ended up reporting thousands of properties as "SUCCESS" in library functions that were never actually called. For some contracts examples this now reduces the number of properties reported from over a thousand to tens of properties.
1 parent 0760cd7 commit d9e83d4

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

regression/contracts-dfcc/chain.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@ elif echo $args_inst | grep -q -- "--dump-c" ; then
5858

5959
rm "${name}${dfcc_suffix}-mod.c"
6060
fi
61+
if ! echo "${args_cbmc}" | grep -q -- --function ; then
62+
$goto_instrument --drop-unused-functions "${name}${dfcc_suffix}-mod.gb" "${name}${dfcc_suffix}-mod.gb"
63+
fi
6164
$goto_instrument --show-goto-functions "${name}${dfcc_suffix}-mod.gb"
6265
$cbmc "${name}${dfcc_suffix}-mod.gb" ${args_cbmc}

regression/contracts/chain.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ elif echo $args_inst | grep -q -- "--dump-c" ; then
4141

4242
rm "${name}-mod.c"
4343
fi
44+
if ! echo "${args_cbmc}" | grep -q -- --function ; then
45+
$goto_instrument --drop-unused-functions "${name}-mod.gb" "${name}-mod.gb"
46+
fi
4447
$goto_instrument --show-goto-functions "${name}-mod.gb"
4548
$cbmc "${name}-mod.gb" ${args_cbmc}

src/ansi-c/goto-conversion/link_to_library.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,31 @@ add_one_function(
4141
// convert to CFG
4242
if(
4343
library_model.symbol_table.symbols.find(missing_function) !=
44-
library_model.symbol_table.symbols.end())
44+
library_model.symbol_table.symbols.end() &&
45+
library_model.symbol_table.lookup_ref(missing_function).value.is_not_nil())
4546
{
4647
goto_convert(
4748
missing_function,
4849
library_model.symbol_table,
4950
library_model.goto_functions,
5051
message_handler);
52+
library_model.symbol_table.get_writeable_ref(missing_function)
53+
.set_compiled();
5154
}
5255
// We might need a function that's outside our own library, but brought in via
5356
// some header file included by the library. Those functions already exist in
5457
// goto_model.symbol_table, but haven't been converted just yet.
5558
else if(
5659
goto_model.symbol_table.symbols.find(missing_function) !=
57-
goto_model.symbol_table.symbols.end())
60+
goto_model.symbol_table.symbols.end() &&
61+
goto_model.symbol_table.lookup_ref(missing_function).value.is_not_nil())
5862
{
5963
goto_convert(
6064
missing_function,
6165
goto_model.symbol_table,
6266
library_model.goto_functions,
6367
message_handler);
68+
goto_model.symbol_table.get_writeable_ref(missing_function).set_compiled();
6469
}
6570

6671
// check whether additional initialization may be required

src/goto-instrument/contracts/dynamic-frames/dfcc_library.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ void dfcc_libraryt::load(std::set<irep_idt> &to_instrument)
326326
{
327327
goto_convert(
328328
id, goto_model.symbol_table, goto_model.goto_functions, message_handler);
329+
goto_model.symbol_table.get_writeable_ref(id).set_compiled();
329330
}
330331

331332
// check that all symbols have a goto_implementation

0 commit comments

Comments
 (0)