Skip to content

Commit 818afcc

Browse files
Merge pull request #5383 from hannes-steffenhagen-diffblue/fix/missing-decl-for-malloc-symbols
Make filter_goto_model remove file local symbols
2 parents 823782c + 6c2de2f commit 818afcc

File tree

9 files changed

+135
-5
lines changed

9 files changed

+135
-5
lines changed

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ add_subdirectory(statement-list)
5353
add_subdirectory(systemc)
5454
add_subdirectory(contracts)
5555
add_subdirectory(goto-harness)
56+
add_subdirectory(goto-harness-multi-file-project)
5657
add_subdirectory(goto-cc-file-local)
5758
add_subdirectory(linking-goto-binaries)
5859
add_subdirectory(symtab2gb)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_test_pl_tests(
2+
"${CMAKE_CURRENT_LIST_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-harness> $<TARGET_FILE:cbmc>")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
default: test
2+
3+
test:
4+
@../test.pl -e -p -c "../chain.sh \
5+
../../../src/goto-cc/goto-cc \
6+
../../../src/goto-harness/goto-harness \
7+
../../../src/cbmc/cbmc"
8+
clean:
9+
find -name '*.out' -execdir $(RM) '{}' \;
10+
$(RM) tests.log
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
set -x
4+
set -e
5+
goto_cc="$1"
6+
goto_harness="$2"
7+
cbmc="$3"
8+
goto_harness_args="${@:4:$#-4}"
9+
10+
source_dir="$(pwd)"
11+
target_dir="$(mktemp -d)"
12+
13+
# Compiling
14+
for file in "$source_dir"/*.c; do
15+
file_name="$(basename "$file")"
16+
"$goto_cc" -c "$file" -o "$target_dir"/"${file_name%.c}.o"
17+
done
18+
19+
# Linking
20+
21+
main_exe="$target_dir/main.gb"
22+
"$goto_cc" "$target_dir"/*.o -o "$main_exe"
23+
24+
harness_out_file="$target_dir/harness.c"
25+
"$goto_harness" "$main_exe" "$harness_out_file" --harness-function-name harness $goto_harness_args
26+
cat "$harness_out_file"
27+
"$cbmc" "$main_exe" "$harness_out_file" --function harness
28+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "service.h"
2+
3+
// this isn't testing any interesting harness
4+
// properties so we just have a main function
5+
// with no parameters
6+
int main(void)
7+
{
8+
service_t *service = get_default_service();
9+
service_serve(service);
10+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "service.h"
2+
#include <assert.h>
3+
4+
// contents of the struct
5+
// (mostly just a vtable)
6+
7+
struct service
8+
{
9+
void (*serve)(void);
10+
};
11+
12+
void service_serve(service_t *service)
13+
{
14+
service->serve();
15+
}
16+
17+
static void default_serve(void)
18+
{
19+
assert(0 && "default serve should fail so we can see it is being called");
20+
}
21+
22+
// this static initialisation should not show up in output
23+
// in fact, there is a bit of a bug with dump-c where this
24+
// initialisation would appear but the default_serve function
25+
// would be omitted in certain cases.
26+
static service_t default_service = {.serve = default_serve};
27+
28+
service_t *get_default_service(void)
29+
{
30+
return &default_service;
31+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stddef.h>
2+
3+
// common pattern:
4+
// Some sort of interface defined over "abstract" type with hidden
5+
// implementation details, effectively C style OOP
6+
//
7+
// This is a straw example of course, but very reminiscent of patterns that
8+
// occur in real programs
9+
10+
typedef struct service service_t;
11+
12+
service_t *get_default_service(void);
13+
void service_serve(service_t *service);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
dummy.c
3+
--function main --harness-type call-function
4+
\[default_serve\.assertion\.1\] line \d+ assertion 0 && \"default serve should fail so we can see it is being called\": FAILURE
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
static void default_serve
9+
--
10+
When running the harness we should run into the assertion failure from the
11+
static default_serve function, but the harness C code should not contain this
12+
or any other static functions or variables.

src/goto-harness/goto_harness_parse_options.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,35 @@ static void filter_goto_model(
5151
goto_modelt &goto_model_with_harness,
5252
const std::unordered_set<irep_idt> &goto_model_without_harness_symbols)
5353
{
54-
for(auto &symbol : goto_model_with_harness.get_symbol_table())
54+
for(auto const &symbol_id : goto_model_without_harness_symbols)
5555
{
56-
if(
57-
goto_model_without_harness_symbols.count(symbol.first) == 1 &&
58-
symbol.second.is_function())
59-
goto_model_with_harness.unload(symbol.first);
56+
auto &symbol =
57+
goto_model_with_harness.symbol_table.get_writeable_ref(symbol_id);
58+
if(symbol.is_function())
59+
{
60+
// We don’t want bodies of functions that already existed in the
61+
// symbol table (i.e. not generated by us)
62+
goto_model_with_harness.unload(symbol_id);
63+
if(symbol.is_file_local)
64+
{
65+
goto_model_with_harness.symbol_table.remove(symbol_id);
66+
}
67+
}
68+
else if(!symbol.is_type && symbol.is_file_local)
69+
{
70+
// We don’t want file local symbols from an existing goto model
71+
// except types / typedefs, which also apparently get marked
72+
// file local sometimes.
73+
goto_model_with_harness.symbol_table.remove(symbol_id);
74+
}
75+
else if(!symbol.is_type && symbol.is_static_lifetime)
76+
{
77+
// if it has static lifetime and is *not* a type it is a global variable
78+
// We keep around other global variables in case we want to initialise
79+
// them, but mark them as extern so we don't duplicate their definitions
80+
symbol.value = nil_exprt{};
81+
symbol.is_extern = true;
82+
}
6083
}
6184
}
6285

0 commit comments

Comments
 (0)