Skip to content

Commit 79ce175

Browse files
committed
Add --keep-implementations switch to goto-cc
The --keep-implementations switch takes a comma-separated list of identifiers. When this switch is passed to goto-cc, the compiler will not remove the symbols and definitions for the named functions, even when they appear to be unused. This patch is to support running CBMC on projects that define many of their functions as static. Prior to this commit, users could not test the correctness of functions marked as static because the function definitions would not be exported by goto-cc.
1 parent 486cfcb commit 79ce175

File tree

19 files changed

+210
-15
lines changed

19 files changed

+210
-15
lines changed

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ add_subdirectory(goto-cc-goto-analyzer)
5050
add_subdirectory(systemc)
5151
add_subdirectory(contracts)
5252
add_subdirectory(goto-harness)
53+
add_subdirectory(goto-cc-static)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
add_test_pl_tests(
8+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:cbmc> ${is_windows}"
9+
)

regression/goto-cc-static/chain.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
goto_cc=$1
4+
cbmc=$2
5+
is_windows=$3
6+
7+
to_keep=""
8+
if [ $# -gt 3 ]; then
9+
if [ $4!='' ]; then
10+
to_keep="--keep-implementations $4"
11+
fi
12+
fi
13+
14+
cbmc_options=""
15+
if [ $# -gt 4 ]; then
16+
cbmc_options=${*:5:$#-5}
17+
fi
18+
19+
name=${*:$#}
20+
name=${name%.c}
21+
22+
if [[ "${is_windows}" == "true" ]]; then
23+
"${goto_cc}" ${to_keep} "${name}.c"
24+
mv "${name}.exe" "${name}.gb"
25+
else
26+
"${goto_cc}" ${to_keep} "${name}.c" -o "${name}.gb"
27+
fi
28+
29+
"${cbmc}" ${cbmc_options} "${name}.gb" ${cbmc_options}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
static int foo()
2+
{
3+
return 3;
4+
}
5+
6+
int main()
7+
{
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
foo --show-symbol-table
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^Symbol......: foo$
8+
--
9+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
static int foo()
2+
{
3+
return 3;
4+
}
5+
6+
int main()
7+
{
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
main --show-symbol-table
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^Symbol......: main$
8+
--
9+
^Symbol......: foo$
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
static int baz()
2+
{
3+
return 3;
4+
}
5+
6+
static int bar()
7+
{
8+
return 3;
9+
}
10+
11+
static int foo()
12+
{
13+
return 3;
14+
}
15+
16+
int main()
17+
{
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
foo,bar --show-symbol-table
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^Symbol......: foo$
8+
^Symbol......: bar$
9+
--
10+
^Symbol......: baz$

src/ansi-c/ansi_c_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool ansi_c_languaget::prv_typecheck(
119119
return true;
120120
}
121121

122-
if(remove_internal_symbols(new_symbol_table, *this))
122+
if(remove_internal_symbols(new_symbol_table, symbols_to_keep, *this))
123123
return true;
124124

125125
if(linking(symbol_table, new_symbol_table, get_message_handler()))

0 commit comments

Comments
 (0)