Skip to content

Commit d810eb8

Browse files
Hannes SteffenhagenHannes Steffenhagen
Hannes Steffenhagen
authored and
Hannes Steffenhagen
committed
Add --symex-cache-dereferences flag
This makes the dereference caching behaviour configurable
1 parent 65d36c2 commit d810eb8

File tree

13 files changed

+91
-13
lines changed

13 files changed

+91
-13
lines changed

jbmc/regression/jbmc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_test_pl_tests(
2-
"$<TARGET_FILE:jbmc> --validate-goto-model --validate-ssa-equation --validate-trace"
2+
"$<TARGET_FILE:jbmc> --validate-goto-model --validate-ssa-equation --validate-trace --symex-cache-dereferences"
33
)
44

55
if(DEFINED BDD_GUARDS)

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ void jbmc_parse_optionst::get_command_line_options(optionst &options)
425425
options.set_option("validate-goto-model", true);
426426
}
427427

428+
options.set_option(
429+
"symex-cache-dereferences", cmdline.isset("symex-cache-dereferences"));
430+
428431
PARSE_OPTIONS_GOTO_TRACE(cmdline, options);
429432

430433
if(cmdline.isset("no-lazy-methods"))

regression/cbmc/CMakeLists.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,32 @@ else()
66
set(gcc_only_string "")
77
endif()
88

9+
# We run cbmc tests with dereference cache on by default. There are a handful
10+
# of tests (mostly tests that check SSA output) which that'd interefere with,
11+
# so we just exclude those here and run those few tests without dereference
12+
# caching.
913
add_test_pl_tests(
10-
"$<TARGET_FILE:cbmc> --validate-goto-model --validate-ssa-equation" -X smt-backend ${gcc_only}
14+
"$<TARGET_FILE:cbmc> --validate-goto-model --validate-ssa-equation --symex-cache-dereferences" -X smt-backend -X no-dereference-cache ${gcc_only}
15+
)
16+
17+
add_test_pl_profile(
18+
"cbmc-no-dereference-cache"
19+
"$<TARGET_FILE:cbmc> --validate-goto-model --validate-ssa-equation"
20+
"-C;-X;smt-backend;-I;no-dereference-cache;${gcc_only_string}"
21+
"CORE"
1122
)
1223

1324
add_test_pl_profile(
1425
"cbmc-paths-lifo"
15-
"$<TARGET_FILE:cbmc> --paths lifo"
16-
"-C;-X;thorough-paths;-X;smt-backend;-X;paths-lifo-expected-failure;${gcc_only_string}-s;paths-lifo"
26+
"$<TARGET_FILE:cbmc> --paths lifo --symex-cache-dereferences"
27+
"-C;-X;thorough-paths;-X;smt-backend;-X;paths-lifo-expected-failure;${gcc_only_string}-s;paths-lifo;-X;no-dereference-cache"
1728
"CORE"
1829
)
1930

2031
add_test_pl_profile(
2132
"cbmc-cprover-smt2"
22-
"$<TARGET_FILE:cbmc> --cprover-smt2"
23-
"-C;-X;broken-smt-backend;-X;thorough-smt-backend;${gcc_only_string}-s;cprover-smt2"
33+
"$<TARGET_FILE:cbmc> --cprover-smt2 --symex-cache-dereferences"
34+
"-C;-X;broken-smt-backend;-X;thorough-smt-backend;${gcc_only_string}-s;cprover-smt2;-X;no-dereference-cache"
2435
"CORE"
2536
)
2637

regression/cbmc/Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,31 @@ GCC_ONLY =
1010
endif
1111

1212
test:
13-
@../test.pl -e -p -c "../../../src/cbmc/cbmc --validate-goto-model --validate-ssa-equation" -X smt-backend $(GCC_ONLY)
13+
@../test.pl -e -p -c "../../../src/cbmc/cbmc --validate-goto-model --validate-ssa-equation --symex-cache-dereferences" \
14+
-X smt-backend \
15+
-X no-dereference-cache \
16+
$(GCC_ONLY)
17+
18+
test-no-dereference-cache:
19+
@../test.pl -e -p -c "../../../src/cbmc/cbmc --validate-goto-model --validate-ssa-equation" \
20+
-X smt-backend \
21+
-I no-dereference-cache \
22+
$(GCC_ONLY)
1423

1524
test-cprover-smt2:
16-
@../test.pl -e -p -c "../../../src/cbmc/cbmc --cprover-smt2" -X broken-smt-backend -X thorough-smt-backend $(GCC_ONLY)
25+
@../test.pl -e -p -c "../../../src/cbmc/cbmc --cprover-smt2 --symex-cache-dereferences" \
26+
-X broken-smt-backend \
27+
-X thorough-smt-backend \
28+
-X no-dereference-cache \
29+
$(GCC_ONLY)
1730

1831
test-paths-lifo:
19-
@../test.pl -e -p -c "../../../src/cbmc/cbmc --paths lifo" -X thorough-paths -X smt-backend -X paths-lifo-expected-failure $(GCC_ONLY)
32+
@../test.pl -e -p -c "../../../src/cbmc/cbmc --paths lifo --symex-cache-dereferences" \
33+
-X thorough-paths \
34+
-X smt-backend \
35+
-X paths-lifo-expected-failure \
36+
-X no-dereference-cache \
37+
$(GCC_ONLY)
2038

2139
tests.log: ../test.pl test
2240

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is just checking that the --symex-cache-dereferences flag actually turns dereference caching on
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE no-dereference-cache
2+
test.c
3+
--show-vcc
4+
\(main::1::p!0@1#2 = address_of
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Note that dereference caching is turned ON by default
10+
in tests just to make sure that it doesn't break
11+
anything.
12+
13+
I would like to match the expression more precisely, but the order of
14+
comparisons for address of depends on platform-specific logic (unordered_xxx),
15+
and the corresponding regex would look ridiculous.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--show-vcc
4+
symex::dereference_cache!0#1 = 0
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Note that dereference caching is turned ON by default in
10+
tests just to make sure that it doesn't break anything.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <assert.h>
2+
3+
int main(void)
4+
{
5+
int cond, x, y, *p = cond ? &x : &y;
6+
assert(*p == 0);
7+
}

src/cbmc/cbmc_parse_options.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
342342
"max-node-refinement",
343343
cmdline.get_value("max-node-refinement"));
344344

345+
options.set_option(
346+
"symex-cache-dereferences", cmdline.isset("symex-cache-dereferences"));
347+
345348
if(cmdline.isset("incremental-loop"))
346349
{
347350
options.set_option(

src/goto-checker/bmc_util.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ void run_property_decider(
197197
"(incremental-loop):" \
198198
"(unwind-min):" \
199199
"(unwind-max):" \
200-
"(ignore-properties-before-unwind-min)"
200+
"(ignore-properties-before-unwind-min)" \
201+
"(symex-cache-dereferences)"
201202

202203
#define HELP_BMC \
203204
" --paths [strategy] explore paths one at a time\n" \
@@ -251,7 +252,8 @@ void run_property_decider(
251252
" iteration are allowed to fail due to\n" \
252253
" complexity violations before the loop\n" \
253254
" gets blacklisted\n" \
254-
" --graphml-witness filename write the witness in GraphML format to filename\n" // NOLINT(*)
255+
" --graphml-witness filename write the witness in GraphML format to filename\n" /* NOLINT(*) */ \
256+
" --symex-cache-dereferences enable caching of repeated dereferences"
255257
// clang-format on
256258

257259
#endif // CPROVER_GOTO_CHECKER_BMC_UTIL_H

src/goto-symex/symex_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ struct symex_configt final
5555
/// enables certain analyses that otherwise aren't run.
5656
bool complexity_limits_active;
5757

58+
/// \brief Whether or not to replace multiple occurrences of the same
59+
/// dereference with a single symbol that contains the result of that
60+
/// dereference. Can sometimes lead to a significant performance
61+
/// improvement, but sometimes also makes things worse.
62+
/// Used in goto_symext::dereference_rec
63+
bool cache_dereferences;
64+
5865
/// \brief Construct a symex_configt using options specified in an
5966
/// \ref optionst
6067
explicit symex_configt(const optionst &options);

src/goto-symex/symex_dereference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void goto_symext::dereference_rec(
342342
// would result in us referencing quantifier variables outside the scope of
343343
// the quantifier.
344344
if(
345-
!write && !is_in_quantifier &&
345+
symex_config.cache_dereferences && !write && !is_in_quantifier &&
346346
(tmp2.id() == ID_if || tmp2.id() == ID_let))
347347
{
348348
expr = cache_dereference(tmp2, state);

src/goto-symex/symex_main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ symex_configt::symex_configt(const optionst &options)
5656
"max-field-sensitivity-array-size")
5757
: DEFAULT_MAX_FIELD_SENSITIVITY_ARRAY_SIZE),
5858
complexity_limits_active(
59-
options.get_signed_int_option("symex-complexity-limit") > 0)
59+
options.get_signed_int_option("symex-complexity-limit") > 0),
60+
cache_dereferences{options.get_bool_option("symex-cache-dereferences")}
6061
{
6162
}
6263

0 commit comments

Comments
 (0)