Skip to content

Commit 2c1a38e

Browse files
authored
Merge pull request #7834 from qinheping/features/array_theory_in_synthesizer
SYNTHESIZER: add array-uf options
2 parents 0c029ea + 1bf2c96 commit 2c1a38e

File tree

6 files changed

+72
-5
lines changed

6 files changed

+72
-5
lines changed

doc/man/goto-synthesizer.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ output smt incremental formula to the given file
121121
.TP
122122
\fB\-\-write\-solver\-stats\-to\fR json\-file
123123
collect the solver query complexity
124+
.TP
125+
\fB\-\-arrays\-uf\-never\fR
126+
never turn arrays into uninterpreted functions
127+
.TP
128+
\fB\-\-arrays\-uf\-always\fR
129+
always turn arrays into uninterpreted functions
124130
.SS "User-interface options:"
125131
.TP
126132
\fB\-\-xml\-ui\fR
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <stdlib.h>
2+
3+
inline int memcmp(const char *s1, const char *s2, unsigned n)
4+
{
5+
int res = 0;
6+
const unsigned char *sc1 = s1, *sc2 = s2;
7+
for(; n != 0; n--)
8+
// clang-format off
9+
__CPROVER_loop_invariant(n <= __CPROVER_loop_entry(n))
10+
__CPROVER_loop_invariant(__CPROVER_same_object(sc1, __CPROVER_loop_entry(sc1)))
11+
__CPROVER_loop_invariant(__CPROVER_same_object(sc2, __CPROVER_loop_entry(sc2)))
12+
__CPROVER_loop_invariant(sc1 <= s1 + __CPROVER_loop_entry(n))
13+
__CPROVER_loop_invariant(sc2 <= s2 + __CPROVER_loop_entry(n))
14+
__CPROVER_loop_invariant(res == 0)
15+
__CPROVER_loop_invariant(sc1 -(const unsigned char*)s1 == sc2 -(const unsigned char*)s2
16+
&& sc1 -(const unsigned char*)s1== __CPROVER_loop_entry(n) - n)
17+
// clang-format on
18+
{
19+
res = (*sc1++) - (*sc2++);
20+
long d1 = sc1 - (const unsigned char *)s1;
21+
long d2 = sc2 - (const unsigned char *)s2;
22+
if(res != 0)
23+
return res;
24+
}
25+
return res;
26+
}
27+
28+
int main()
29+
{
30+
const unsigned SIZE = 4096;
31+
unsigned char *a = malloc(SIZE);
32+
unsigned char *b = malloc(SIZE);
33+
memcpy(b, a, SIZE);
34+
assert(memcmp(a, b, SIZE) == 0);
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--pointer-check _ --arrays-uf-always _ --arrays-uf-always
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check if the flag --array-uf-always is correctly passed from the synthesizer
11+
to the verifier. Note that there is no loop contracts synthesized in this test.

regression/goto-synthesizer/chain.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ name=${*:$#}
1212
name=${name%.c}
1313

1414
args=${*:6:$#-6}
15-
if [[ "$args" != *" _ "* ]]
16-
then
15+
if [[ "$args" != *" _ "* ]]; then
1716
args_inst=$args
1817
args_synthesizer=""
18+
args_cbmc=""
1919
else
2020
args_inst="${args%%" _ "*}"
21-
args_synthesizer="${args#*" _ "}"
21+
args=${args#*" _ "}
22+
if [[ "$args" != *" _ "* ]]; then
23+
args_synthesizer=$args
24+
args_cbmc=""
25+
else
26+
args_synthesizer="${args%%" _ "*}"
27+
args_cbmc="${args#*" _ "}"
28+
fi
2229
fi
2330

2431
if [[ "${is_windows}" == "true" ]]; then
@@ -50,5 +57,5 @@ if echo $args_synthesizer | grep -q -- "--dump-loop-contracts" ; then
5057
else
5158
$goto_synthesizer ${args_synthesizer} "${name}-mod.gb" "${name}-mod-2.gb"
5259
echo "Running CBMC: "
53-
$cbmc "${name}-mod-2.gb"
60+
$cbmc ${args_cbmc} "${name}-mod-2.gb"
5461
fi

src/goto-synthesizer/goto_synthesizer_parse_options.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,18 @@ optionst goto_synthesizer_parse_optionst::get_options()
195195
options.set_option("built-in-assertions", true);
196196
options.set_option("assertions", true);
197197
options.set_option("assumptions", true);
198-
options.set_option("arrays-uf", "auto");
199198
options.set_option("depth", UINT32_MAX);
200199
options.set_option("exploration-strategy", "lifo");
201200
options.set_option("symex-cache-dereferences", false);
202201
options.set_option("rewrite-union", true);
203202
options.set_option("self-loops-to-assumptions", true);
204203

204+
options.set_option("arrays-uf", "auto");
205+
if(cmdline.isset("arrays-uf-always"))
206+
options.set_option("arrays-uf", "always");
207+
else if(cmdline.isset("arrays-uf-never"))
208+
options.set_option("arrays-uf", "never");
209+
205210
// Generating trace for counterexamples.
206211
options.set_option("trace", true);
207212

@@ -233,6 +238,8 @@ void goto_synthesizer_parse_optionst::help()
233238
HELP_CONFIG_BACKEND
234239
HELP_SOLVER
235240
"\n"
241+
" --arrays-uf-never never turn arrays into uninterpreted functions\n" // NOLINT(*)
242+
" --arrays-uf-always always turn arrays into uninterpreted functions\n" // NOLINT(*)
236243
"Other options:\n"
237244
" --version show version and exit\n"
238245
" --xml-ui use XML-formatted output\n"

src/goto-synthesizer/goto_synthesizer_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Qinheping Hu
2626
"(" FLAG_LOOP_CONTRACTS_NO_UNWIND ")" \
2727
OPT_CONFIG_BACKEND \
2828
OPT_SOLVER \
29+
"(arrays-uf-always)(arrays-uf-never)" \
2930
"(verbosity):(version)(xml-ui)(json-ui)" \
3031
// empty last line
3132

0 commit comments

Comments
 (0)