Skip to content

Commit 1ccd1a2

Browse files
author
thk123
committed
Add support for using the --function flag to goto-analyze and symex
symex and goto-analyze (through the goto_modelt class) now support setting the --function flag on precompiled .gb files. Refactored out the function flag and its help function to rebuild_goto_start_functions. Used this extracted flag in goto-analyze, symex and CBMC. Added tests that check both goto-analyze and symex when ran with the --function flag actually generate the correct _start function. Also added tests for when it isn't a precompiled binary. Added these new folders to the overal test suite
1 parent 0732580 commit 1ccd1a2

File tree

22 files changed

+203
-7
lines changed

22 files changed

+203
-7
lines changed

regression/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ DIRS = ansi-c \
66
cpp \
77
goto-analyzer \
88
goto-cc-cbmc \
9+
goto-cc-goto-analyzer \
10+
goto-cc-goto-symex \
911
goto-diff \
1012
goto-gcc \
1113
goto-instrument \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
int fun(int x)
4+
{
5+
int i;
6+
if(i>=20)
7+
assert(i>=10);
8+
}
9+
10+
int main(int argc, char** argv)
11+
{
12+
int i;
13+
14+
if(i>=5)
15+
assert(i>=10);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function fun --show-goto-functions
4+
^\s*fun\(x\);$
5+
^EXIT=6$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

regression/goto-cc-cbmc/regenerate-entry-function/test.desc

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
CORE
22
main.c
33
"--function fun --cover branch"
4-
54
^EXIT=0$
65
^SIGNAL=0$
76
^x=
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
default: tests.log
3+
4+
test:
5+
@if ! ../test.pl -c ../chain.sh ; then \
6+
../failed-tests-printer.pl ; \
7+
exit 1; \
8+
fi
9+
10+
tests.log:
11+
pwd
12+
@if ! ../test.pl -c ../chain.sh ; then \
13+
../failed-tests-printer.pl ; \
14+
exit 1; \
15+
fi
16+
17+
show:
18+
@for dir in *; do \
19+
if [ -d "$$dir" ]; then \
20+
vim -o "$$dir/*.c" "$$dir/*.out"; \
21+
fi; \
22+
done;
23+
24+
clean:
25+
@for dir in *; do \
26+
rm -f tests.log; \
27+
if [ -d "$$dir" ]; then \
28+
cd "$$dir"; \
29+
rm -f *.out *.gb; \
30+
cd ..; \
31+
fi \
32+
done
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
src=../../../src
4+
5+
gc=$src/goto-cc/goto-cc
6+
goto_analyzer=$src/goto-analyzer/goto-analyzer
7+
8+
options=$1
9+
name=${2%.c}
10+
11+
$gc $name.c -o $name.gb
12+
$goto_analyzer $name.gb $options
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
int fun(int x)
4+
{
5+
int i;
6+
if(i>=20)
7+
assert(i>=10);
8+
}
9+
10+
int main(int argc, char** argv)
11+
{
12+
int i;
13+
14+
if(i>=5)
15+
assert(i>=10);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
"--function fun --show-goto-functions"
4+
^\s*fun\(x\);$
5+
^EXIT=6$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

regression/goto-cc-symex/Makefile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
default: tests.log
3+
4+
test:
5+
@if ! ../test.pl -c ../chain.sh ; then \
6+
../failed-tests-printer.pl ; \
7+
exit 1; \
8+
fi
9+
10+
tests.log:
11+
pwd
12+
@if ! ../test.pl -c ../chain.sh ; then \
13+
../failed-tests-printer.pl ; \
14+
exit 1; \
15+
fi
16+
17+
show:
18+
@for dir in *; do \
19+
if [ -d "$$dir" ]; then \
20+
vim -o "$$dir/*.c" "$$dir/*.out"; \
21+
fi; \
22+
done;
23+
24+
clean:
25+
@for dir in *; do \
26+
rm -f tests.log; \
27+
if [ -d "$$dir" ]; then \
28+
cd "$$dir"; \
29+
rm -f *.out *.gb; \
30+
cd ..; \
31+
fi \
32+
done

regression/goto-cc-symex/chain.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
src=../../../src
4+
5+
gc=$src/goto-cc/goto-cc
6+
symex=$src/symex/symex
7+
8+
options=$1
9+
name=${2%.c}
10+
11+
$gc $name.c -o $name.gb
12+
$symex $name.gb $options
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
int fun(int x)
4+
{
5+
int i;
6+
if(i>=20)
7+
assert(i>=10);
8+
}
9+
10+
int main(int argc, char** argv)
11+
{
12+
int i;
13+
14+
if(i>=5)
15+
assert(i>=10);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
"--function fun --show-goto-functions"
4+
^\s*return.=fun\(x\);$
5+
^EXIT=6$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
int fun(int x)
4+
{
5+
int i;
6+
if(i>=20)
7+
assert(i>=10);
8+
}
9+
10+
int main(int argc, char** argv)
11+
{
12+
int i;
13+
14+
if(i>=5)
15+
assert(i>=10);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function fun --show-goto-functions
4+
fun\(x\);$
5+
^EXIT=6$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

src/cbmc/cbmc_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ void cbmc_parse_optionst::help()
10091009
" --round-to-plus-inf rounding towards plus infinity\n"
10101010
" --round-to-minus-inf rounding towards minus infinity\n"
10111011
" --round-to-zero rounding towards zero\n"
1012-
" --function name set main function name\n"
1012+
HELP_FUNCTIONS
10131013
"\n"
10141014
"Program representations:\n"
10151015
" --show-parse-tree show parse tree\n"

src/cbmc/cbmc_parse_options.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <util/ui_message.h>
1616
#include <util/parse_options.h>
17+
#include <goto-programs/rebuild_goto_start_function.h>
1718

1819
#include <analyses/goto_check.h>
1920

@@ -26,7 +27,8 @@ class goto_functionst;
2627
class optionst;
2728

2829
#define CBMC_OPTIONS \
29-
"(program-only)(function):(preprocess)(slice-by-trace):" \
30+
"(program-only)(preprocess)(slice-by-trace):" \
31+
OPT_FUNCTIONS \
3032
"(no-simplify)(unwind):(unwindset):(slice-formula)(full-slice)" \
3133
"(debug-level):(no-propagation)(no-simplify-if)" \
3234
"(document-subgoals)(outfile):(test-preprocessor)" \

src/goto-analyzer/goto_analyzer_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ void goto_analyzer_parse_optionst::help()
494494
" --classpath dir/jar set the classpath\n"
495495
" --main-class class-name set the name of the main class\n"
496496
JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP
497+
HELP_FUNCTIONS
497498
"\n"
498499
"Program representations:\n"
499500
" --show-parse-tree show parse tree\n"

src/goto-analyzer/goto_analyzer_parse_options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include <goto-programs/goto_model.h>
1919
#include <goto-programs/show_goto_functions.h>
20+
#include <goto-programs/rebuild_goto_start_function.h>
2021

2122
#include <analyses/goto_check.h>
2223

@@ -27,7 +28,7 @@ class goto_functionst;
2728
class optionst;
2829

2930
#define GOTO_ANALYSER_OPTIONS \
30-
"(function):" \
31+
OPT_FUNCTIONS \
3132
"D:I:(std89)(std99)(std11)" \
3233
"(classpath):(cp):(main-class):" \
3334
"(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \

src/goto-programs/rebuild_goto_start_function.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool rebuild_goto_start_functiont::operator()(
6969
symbol_table);
7070

7171
// Remove the function from the goto_functions so it is copied back in
72-
// from the symbol table
72+
// from the symbol table during goto_convert
7373
if(!return_code)
7474
{
7575
const auto &start_function=

src/goto-programs/rebuild_goto_start_function.h

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
class symbol_tablet;
1515
class goto_functionst;
1616

17+
#define OPT_FUNCTIONS \
18+
"(function):"
19+
20+
#define HELP_FUNCTIONS \
21+
" --function name set main function name\n"
22+
1723
class rebuild_goto_start_functiont: public messaget
1824
{
1925
public:

src/symex/symex_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ void symex_parse_optionst::help()
587587
" --round-to-plus-inf IEEE floating point rounding mode\n"
588588
" --round-to-minus-inf IEEE floating point rounding mode\n"
589589
" --round-to-zero IEEE floating point rounding mode\n"
590-
" --function name set main function name\n"
590+
HELP_FUNCTIONS
591591
"\n"
592592
"Java Bytecode frontend options:\n"
593593
JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP

src/symex/symex_parse_options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include <goto-programs/goto_model.h>
1919
#include <goto-programs/show_goto_functions.h>
20+
#include <goto-programs/rebuild_goto_start_function.h>
2021

2122
#include <analyses/goto_check.h>
2223

@@ -28,7 +29,7 @@ class goto_functionst;
2829
class optionst;
2930

3031
#define SYMEX_OPTIONS \
31-
"(function):" \
32+
OPT_FUNCTIONS \
3233
"D:I:" \
3334
"(depth):(context-bound):(branch-bound):(unwind):(max-search-time):" \
3435
OPT_GOTO_CHECK \

0 commit comments

Comments
 (0)