Skip to content

Commit 6f40463

Browse files
authored
Merge pull request #7429 from qinheping/goto-synthesizer-migration
SYNTHESIZER: Migrate loop-contracts synthesizer from goto-instrument to goto-synthesizer
2 parents 5d603e4 + 2a745f8 commit 6f40463

28 files changed

+240
-71
lines changed

CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
/src/goto-harness/ @martin-cs @chris-ryder @peterschrammel
5353
/src/goto-instrument/ @martin-cs @chris-ryder @peterschrammel @tautschnig @kroening
5454
/src/goto-instrument/contracts/ @tautschnig @feliperodri @remi-delmas-3000
55-
/src/goto-instrument/synthesizer/ @qinheping @tautschnig @feliperodri @remi-delmas-3000
5655
/src/goto-synthesizer/ @qinheping @tautschnig @feliperodri @remi-delmas-3000
5756
/src/goto-diff/ @tautschnig @peterschrammel
5857
/src/jsil/ @kroening @tautschnig

doc/man/goto-instrument.1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,6 @@ force aggressive slicer to preserve all direct paths
999999
\fB\-\-apply\-loop\-contracts\fR
10001000
check and use loop contracts when provided
10011001
.TP
1002-
\fB\-\-synthesize\-loop\-invariants\fR
1003-
synthesize and apply loop invariants
1004-
.TP
10051002
\fB\-\-replace\-call\-with\-contract\fR \fIfun\fR
10061003
replace calls to \fIfun\fR with \fIfun\fR's contract
10071004
.TP

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ add_subdirectory(statement-list)
6666
add_subdirectory(systemc)
6767
add_subdirectory(contracts)
6868
add_subdirectory(contracts-dfcc)
69+
add_subdirectory(goto-synthesizer)
6970
add_subdirectory(acceleration)
7071
add_subdirectory(k-induction)
7172
add_subdirectory(goto-harness)

regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ DIRS = cbmc \
3939
systemc \
4040
contracts \
4141
contracts-dfcc \
42+
goto-synthesizer \
4243
acceleration \
4344
k-induction \
4445
goto-harness \
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
8+
set(gcc_only -X gcc-only)
9+
set(gcc_only_string "-X;gcc-only;")
10+
else()
11+
set(gcc_only "")
12+
set(gcc_only_string "")
13+
endif()
14+
15+
16+
add_test_pl_tests(
17+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-synthesizer> $<TARGET_FILE:cbmc> ${is_windows}"
18+
)
19+
20+
## Enabling these causes a very significant increase in the time taken to run the regressions
21+
22+
#add_test_pl_profile(
23+
# "cbmc-z3"
24+
# "${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-synthesizer> '$<TARGET_FILE:cbmc> --z3' ${is_windows}"
25+
# "-C;-X;broken-smt-backend;-X;thorough-smt-backend;-X;broken-z3-backend;-X;thorough-z3-backend;${gcc_only_string}-s;z3"
26+
# "CORE"
27+
#)
28+
29+
#add_test_pl_profile(
30+
# "cbmc-cprover-smt2"
31+
# "${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-synthesizer> '$<TARGET_FILE:cbmc> --cprover-smt2' ${is_windows}"
32+
# "-C;-X;broken-smt-backend;-X;thorough-smt-backend;-X;broken-cprover-smt2-backend;-X;thorough-cprover-smt2-backend;${gcc_only_string}-s;cprover-smt2"
33+
# "CORE"
34+
#)
35+
36+
# solver appears on the PATH in Windows already
37+
#if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
38+
# set_property(
39+
# TEST "cbmc-cprover-smt2-CORE"
40+
# PROPERTY ENVIRONMENT
41+
# "PATH=$ENV{PATH}:$<TARGET_FILE_DIR:smt2_solver>"
42+
# )
43+
#endif()

regression/goto-synthesizer/Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
default: test
2+
3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
is_windows=true
9+
GCC_ONLY = -X gcc-only
10+
else
11+
exe=../../../src/goto-cc/goto-cc
12+
is_windows=false
13+
GCC_ONLY =
14+
endif
15+
16+
test:
17+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-synthesizer/goto-synthesizer ../../../src/cbmc/cbmc $(is_windows)' -X smt-backend $(GCC_ONLY)
18+
19+
test-cprover-smt2:
20+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-synthesizer/goto-synthesizer "../../../src/cbmc/cbmc --cprover-smt2" $(is_windows)' \
21+
-X broken-smt-backend -X thorough-smt-backend \
22+
-X broken-cprover-smt-backend -X thorough-cprover-smt-backend \
23+
-s cprover-smt2 $(GCC_ONLY)
24+
25+
test-z3:
26+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-synthesizer/goto-synthesizer "../../../src/cbmc/cbmc --z3" $(is_windows)' \
27+
-X broken-smt-backend -X thorough-smt-backend \
28+
-X broken-z3-smt-backend -X thorough-z3-smt-backend \
29+
-s z3 $(GCC_ONLY)
30+
31+
tests.log: ../test.pl test
32+
33+
34+
clean:
35+
@for dir in *; do \
36+
$(RM) tests.log; \
37+
if [ -d "$$dir" ]; then \
38+
cd "$$dir"; \
39+
$(RM) *.out *.gb *.smt2; \
40+
cd ..; \
41+
fi \
42+
done

regression/goto-synthesizer/chain.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
goto_cc=$1
6+
goto_synthesizer=$2
7+
cbmc=$3
8+
is_windows=$4
9+
10+
name=${*:$#}
11+
name=${name%.c}
12+
13+
args=${*:5:$#-5}
14+
if [[ "$args" != *" _ "* ]]
15+
then
16+
args_inst=$args
17+
args_cbmc=""
18+
else
19+
args_inst="${args%%" _ "*}"
20+
args_cbmc="${args#*" _ "}"
21+
fi
22+
23+
if [[ "${is_windows}" == "true" ]]; then
24+
$goto_cc "${name}.c" "/Fe${name}.gb"
25+
else
26+
$goto_cc -o "${name}.gb" "${name}.c"
27+
fi
28+
29+
rm -f "${name}-mod.gb"
30+
$goto_synthesizer ${args_inst} "${name}.gb" "${name}-mod.gb"
31+
if [ ! -e "${name}-mod.gb" ] ; then
32+
cp "$name.gb" "${name}-mod.gb"
33+
elif echo $args_inst | grep -q -- "--dump-c" ; then
34+
mv "${name}-mod.gb" "${name}-mod.c"
35+
36+
if [[ "${is_windows}" == "true" ]]; then
37+
$goto_cc "${name}-mod.c" "/Fe${name}-mod.gb"
38+
else
39+
$goto_cc -o "${name}-mod.gb" "${name}-mod.c"
40+
fi
41+
42+
rm "${name}-mod.c"
43+
fi
44+
$cbmc "${name}-mod.gb" ${args_cbmc}

regression/contracts/loop_invariant_synthesis_01/test.desc renamed to regression/goto-synthesizer/loop_contracts_synthesis_01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--synthesize-loop-invariants --apply-loop-contracts
3+
44
^EXIT=0$
55
^SIGNAL=0$
66
^\[main\.\d+\] line 10 Check loop invariant before entry: SUCCESS$

src/goto-instrument/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ SRC = accelerate/accelerate.cpp \
8383
source_lines.cpp \
8484
splice_call.cpp \
8585
stack_depth.cpp \
86-
synthesizer/enumerative_loop_invariant_synthesizer.cpp \
87-
synthesizer/expr_enumerator.cpp \
88-
synthesizer/synthesizer_utils.cpp \
8986
thread_instrumentation.cpp \
9087
undefined_functions.cpp \
9188
uninitialized.cpp \

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ Author: Daniel Kroening, [email protected]
108108
#include "value_set_fi_fp_removal.h"
109109

110110
#include "accelerate/accelerate.h"
111-
#include "synthesizer/enumerative_loop_invariant_synthesizer.h"
112111

113112
/// invoke main modules
114113
int goto_instrument_parse_optionst::doit()
@@ -1148,17 +1147,6 @@ void goto_instrument_parse_optionst::instrument_goto_program()
11481147
goto_model.goto_functions.update();
11491148
}
11501149

1151-
if(cmdline.isset("synthesize-loop-invariants"))
1152-
{
1153-
log.warning() << "Loop invariant synthesizer is still work in progress. "
1154-
"It only generates TRUE as invariants."
1155-
<< messaget::eom;
1156-
1157-
// Synthesize loop invariants and annotate them into `goto_model`
1158-
enumerative_loop_invariant_synthesizert synthesizer(goto_model, log);
1159-
annotate_invariants(synthesizer.synthesize_all(), goto_model, log);
1160-
}
1161-
11621150
bool use_dfcc = cmdline.isset(FLAG_DFCC);
11631151
if(use_dfcc)
11641152
{
@@ -1978,7 +1966,6 @@ void goto_instrument_parse_optionst::help()
19781966
"Code contracts:\n"
19791967
HELP_DFCC
19801968
HELP_LOOP_CONTRACTS
1981-
HELP_LOOP_INVARIANT_SYNTHESIZER
19821969
HELP_REPLACE_CALL
19831970
HELP_ENFORCE_CONTRACT
19841971
HELP_ENFORCE_CONTRACT_REC

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Author: Daniel Kroening, [email protected]
4242

4343
#include "contracts/contracts.h"
4444
#include "contracts/dynamic-frames/dfcc.h"
45-
#include "synthesizer/loop_invariant_synthesizer_base.h"
4645
#include "wmm/weak_memory.h"
4746

4847
// clang-format off
@@ -120,7 +119,6 @@ Author: Daniel Kroening, [email protected]
120119
OPT_NONDET_VOLATILE \
121120
"(ensure-one-backedge-per-target)" \
122121
OPT_CONFIG_LIBRARY \
123-
OPT_SYNTHESIZE_LOOP_INVARIANTS \
124122
// empty last line
125123

126124
// clang-format on

src/goto-instrument/module_dependencies.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ langapi # should go away
1010
linking
1111
pointer-analysis
1212
solvers
13-
synthesizer
1413
util
1514
wmm

src/goto-instrument/synthesizer/module_dependencies.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/goto-synthesizer/Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
SRC = goto_synthesizer_languages.cpp \
1+
SRC = enumerative_loop_contracts_synthesizer.cpp \
2+
expr_enumerator.cpp \
3+
goto_synthesizer_languages.cpp \
24
goto_synthesizer_main.cpp \
35
goto_synthesizer_parse_options.cpp \
6+
synthesizer_utils.cpp \
47
# Empty last line
58

69
OBJ += ../ansi-c/ansi-c$(LIBEXT) \
10+
../analyses/analyses$(LIBEXT) \
711
../cpp/cpp$(LIBEXT) \
812
../linking/linking$(LIBEXT) \
913
../big-int/big-int$(LIBEXT) \
1014
../goto-checker/goto-checker$(LIBEXT) \
1115
../goto-programs/goto-programs$(LIBEXT) \
16+
../goto-instrument/contracts/contracts$(OBJEXT) \
17+
../goto-instrument/contracts/utils$(OBJEXT) \
18+
../goto-instrument/contracts/instrument_spec_assigns$(OBJEXT) \
19+
../goto-instrument/contracts/memory_predicates$(OBJEXT) \
20+
../goto-instrument/contracts/inlining_decorator$(OBJEXT) \
21+
../goto-instrument/contracts/havoc_assigns_clause_targets$(OBJEXT) \
22+
../goto-instrument/havoc_utils$(OBJEXT) \
23+
../goto-instrument/loop_utils$(OBJEXT) \
24+
../goto-instrument/unwindset$(OBJEXT) \
25+
../goto-instrument/unwind$(OBJEXT) \
26+
../goto-instrument/nondet_static$(OBJEXT) \
1227
../langapi/langapi$(LIBEXT) \
1328
../util/util$(LIBEXT) \
1429
../json/json$(LIBEXT) \

src/goto-instrument/synthesizer/enumerative_loop_invariant_synthesizer.cpp renamed to src/goto-synthesizer/enumerative_loop_contracts_synthesizer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/*******************************************************************\
22
3-
Module: Enumerative Loop Invariant Synthesizer
3+
Module: Enumerative Loop Contracts Synthesizer
44
55
Author: Qinheping Hu
66
77
\*******************************************************************/
88

99
/// \file
10-
/// Enumerative Loop Invariant Synthesizer
10+
/// Enumerative Loop Contracts Synthesizer
1111

12-
#include "enumerative_loop_invariant_synthesizer.h"
12+
#include "enumerative_loop_contracts_synthesizer.h"
1313

1414
#include <analyses/natural_loops.h>
1515

16-
void enumerative_loop_invariant_synthesizert::init_candidates()
16+
void enumerative_loop_contracts_synthesizert::init_candidates()
1717
{
1818
for(auto &function_p : goto_model.goto_functions.function_map)
1919
{
@@ -38,7 +38,7 @@ void enumerative_loop_invariant_synthesizert::init_candidates()
3838
}
3939
}
4040

41-
invariant_mapt enumerative_loop_invariant_synthesizert::synthesize_all()
41+
invariant_mapt enumerative_loop_contracts_synthesizert::synthesize_all()
4242
{
4343
init_candidates();
4444

@@ -47,7 +47,7 @@ invariant_mapt enumerative_loop_invariant_synthesizert::synthesize_all()
4747
return invariant_candiate_map;
4848
}
4949

50-
exprt enumerative_loop_invariant_synthesizert::synthesize(loop_idt loop_id)
50+
exprt enumerative_loop_contracts_synthesizert::synthesize(loop_idt loop_id)
5151
{
5252
return true_exprt();
5353
}
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
/*******************************************************************\
22
3-
Module: Enumerative Loop Invariant Synthesizer
3+
Module: Enumerative Loop Contracts Synthesizer
44
55
Author: Qinheping Hu
66
77
\*******************************************************************/
88

99
/// \file
10-
/// Enumerative Loop Invariant Synthesizer
10+
/// Enumerative Loop Contracts Synthesizer
1111

1212
// NOLINTNEXTLINE(whitespace/line_length)
13-
#ifndef CPROVER_GOTO_INSTRUMENT_SYNTHESIZER_ENUMERATIVE_LOOP_INVARIANT_SYNTHESIZER_H
13+
#ifndef CPROVER_GOTO_SYNTHESIZER_ENUMERATIVE_LOOP_CONTRACTS_SYNTHESIZER_H
1414
// NOLINTNEXTLINE(whitespace/line_length)
15-
#define CPROVER_GOTO_INSTRUMENT_SYNTHESIZER_ENUMERATIVE_LOOP_INVARIANT_SYNTHESIZER_H
15+
#define CPROVER_GOTO_SYNTHESIZER_ENUMERATIVE_LOOP_CONTRACTS_SYNTHESIZER_H
1616

17-
#include "loop_invariant_synthesizer_base.h"
17+
#include "loop_contracts_synthesizer_base.h"
1818

1919
class messaget;
2020
class goto_modelt;
2121

22-
/// Enumerative loop invariant synthesizers.
22+
/// Enumerative loop contracts synthesizers.
2323
/// It is designed for `goto_model` containing only checks instrumented by
2424
/// `goto-instrument` with the `--pointer-check` flag.
2525
/// When other checks present, it will just enumerate candidates and check
2626
/// if they are valid.
27-
class enumerative_loop_invariant_synthesizert
28-
: public loop_invariant_synthesizer_baset
27+
class enumerative_loop_contracts_synthesizert
28+
: public loop_contracts_synthesizer_baset
2929
{
3030
public:
31-
enumerative_loop_invariant_synthesizert(
31+
enumerative_loop_contracts_synthesizert(
3232
const goto_modelt &goto_model,
3333
messaget &log)
34-
: loop_invariant_synthesizer_baset(goto_model, log)
34+
: loop_contracts_synthesizer_baset(goto_model, log)
3535
{
3636
}
3737

38-
/// This synthesizer guarantees that, with the synthesized loop invariants,
38+
/// This synthesizer guarantees that, with the synthesized loop contracts,
3939
/// all checks in the annotated GOTO program pass.
4040
invariant_mapt synthesize_all() override;
4141
exprt synthesize(loop_idt loop_id) override;
@@ -48,4 +48,4 @@ class enumerative_loop_invariant_synthesizert
4848
};
4949

5050
// NOLINTNEXTLINE(whitespace/line_length)
51-
#endif // CPROVER_GOTO_INSTRUMENT_SYNTHESIZER_ENUMERATIVE_LOOP_INVARIANT_SYNTHESIZER_H
51+
#endif // CPROVER_GOTO_SYNTHESIZER_ENUMERATIVE_LOOP_CONTRACTS_SYNTHESIZER_H

src/goto-instrument/synthesizer/expr_enumerator.h renamed to src/goto-synthesizer/expr_enumerator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Author: Qinheping Hu
66
/// \file
77
/// Enumerator Interface
88

9-
#ifndef CPROVER_GOTO_INSTRUMENT_SYNTHESIZER_EXPR_ENUMERATOR_H
10-
#define CPROVER_GOTO_INSTRUMENT_SYNTHESIZER_EXPR_ENUMERATOR_H
9+
#ifndef CPROVER_GOTO_SYNTHESIZER_EXPR_ENUMERATOR_H
10+
#define CPROVER_GOTO_SYNTHESIZER_EXPR_ENUMERATOR_H
1111

1212
#include <util/expr.h>
1313

@@ -355,4 +355,4 @@ class recursive_enumerator_placeholdert : public enumerator_baset
355355
const enumerator_factoryt &factory;
356356
};
357357

358-
#endif // CPROVER_GOTO_INSTRUMENT_SYNTHESIZER_EXPR_ENUMERATOR_H
358+
#endif // CPROVER_GOTO_SYNTHESIZER_EXPR_ENUMERATOR_H

0 commit comments

Comments
 (0)