Skip to content

Commit 2f7717a

Browse files
author
Remi Delmas
committed
CONTRACTS: Add --dfcc switch to the goto-instrument CLI interface
parse_options fix format
1 parent f7c91d9 commit 2f7717a

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

doc/man/goto-instrument.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,12 @@ replace calls to \fIfun\fR with \fIfun\fR's contract
10031003
.TP
10041004
\fB\-\-enforce\-contract\fR \fIfun\fR
10051005
wrap \fIfun\fR with an assertion of its contract
1006+
.TP
1007+
\fB\-\-enforce\-contract\-rec\fR \fIfun\fR
1008+
wrap \fIfun\fR with an assertion of its contract that can handle recursive calls
1009+
.TP
1010+
\fB\-\-dfcc\fR \fIfun\fR
1011+
instrument dynamic frame condition checks method using \fIfun\fR as entry point
10061012
.SS "User-interface options:"
10071013
.TP
10081014
\fB\-\-flush\fR

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,9 +1157,71 @@ void goto_instrument_parse_optionst::instrument_goto_program()
11571157
annotate_invariants(synthesizer.synthesize_all(), goto_model, log);
11581158
}
11591159

1160+
bool use_dfcc = false;
1161+
if(cmdline.isset(FLAG_DFCC))
1162+
{
1163+
use_dfcc = true;
1164+
1165+
if(cmdline.get_values(FLAG_DFCC).size() != 1)
1166+
{
1167+
log.error() << "Only a single --" << FLAG_DFCC << " is allowed"
1168+
<< messaget::eom;
1169+
throw 0;
1170+
}
1171+
1172+
if(cmdline.isset(FLAG_LOOP_CONTRACTS))
1173+
{
1174+
log.error() << " The combination of " << FLAG_DFCC << " and "
1175+
<< FLAG_LOOP_CONTRACTS << " is not yet supported"
1176+
<< messaget::eom;
1177+
throw 0;
1178+
}
1179+
1180+
do_indirect_call_and_rtti_removal();
1181+
1182+
const std::string &harness_id = *cmdline.get_values(FLAG_DFCC).begin();
1183+
1184+
std::set<std::string> to_replace(
1185+
cmdline.get_values(FLAG_REPLACE_CALL).begin(),
1186+
cmdline.get_values(FLAG_REPLACE_CALL).end());
1187+
1188+
if(
1189+
!cmdline.get_values(FLAG_ENFORCE_CONTRACT).empty() &&
1190+
!cmdline.get_values(FLAG_ENFORCE_CONTRACT_REC).empty())
1191+
{
1192+
log.error() << "--" << FLAG_ENFORCE_CONTRACT << " and --"
1193+
<< FLAG_ENFORCE_CONTRACT_REC << " are mutually exclusive"
1194+
<< messaget::eom;
1195+
throw 0;
1196+
}
1197+
1198+
auto &to_enforce = !cmdline.get_values(FLAG_ENFORCE_CONTRACT_REC).empty()
1199+
? cmdline.get_values(FLAG_ENFORCE_CONTRACT_REC)
1200+
: cmdline.get_values(FLAG_ENFORCE_CONTRACT);
1201+
1202+
bool allow_recursive_calls =
1203+
!cmdline.get_values(FLAG_ENFORCE_CONTRACT_REC).empty();
1204+
std::set<std::string> to_check(to_enforce.begin(), to_enforce.end());
1205+
1206+
std::set<std::string> to_exclude_from_nondet_static(
1207+
cmdline.get_values("nondet-static-exclude").begin(),
1208+
cmdline.get_values("nondet-static-exclude").end());
1209+
1210+
dfcc(
1211+
goto_model,
1212+
harness_id,
1213+
to_check,
1214+
allow_recursive_calls,
1215+
to_replace,
1216+
false,
1217+
to_exclude_from_nondet_static,
1218+
log);
1219+
}
1220+
11601221
if(
1161-
cmdline.isset(FLAG_LOOP_CONTRACTS) || cmdline.isset(FLAG_REPLACE_CALL) ||
1162-
cmdline.isset(FLAG_ENFORCE_CONTRACT))
1222+
!use_dfcc &&
1223+
(cmdline.isset(FLAG_LOOP_CONTRACTS) || cmdline.isset(FLAG_REPLACE_CALL) ||
1224+
cmdline.isset(FLAG_ENFORCE_CONTRACT)))
11631225
{
11641226
do_indirect_call_and_rtti_removal();
11651227
code_contractst contracts(goto_model, log);
@@ -1911,10 +1973,12 @@ void goto_instrument_parse_optionst::help()
19111973
" force aggressive slicer to preserve all direct paths\n" // NOLINT(*)
19121974
"\n"
19131975
"Code contracts:\n"
1976+
HELP_DFCC
19141977
HELP_LOOP_CONTRACTS
19151978
HELP_LOOP_INVARIANT_SYNTHESIZER
19161979
HELP_REPLACE_CALL
19171980
HELP_ENFORCE_CONTRACT
1981+
HELP_ENFORCE_CONTRACT_REC
19181982
"\n"
19191983
"User-interface options:\n"
19201984
HELP_FLUSH

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Author: Daniel Kroening, [email protected]
4141
#include "unwindset.h"
4242

4343
#include "contracts/contracts.h"
44+
#include "contracts/dynamic-frames/dfcc.h"
4445
#include "synthesizer/enumerative_loop_invariant_synthesizer.h"
4546
#include "wmm/weak_memory.h"
4647

@@ -95,9 +96,11 @@ Author: Daniel Kroening, [email protected]
9596
"(list-symbols)(list-undefined-functions)" \
9697
"(z3)(add-library)(show-dependence-graph)" \
9798
"(horn)(skip-loops):(model-argc-argv):" \
99+
OPT_DFCC \
98100
"(" FLAG_LOOP_CONTRACTS ")" \
99101
"(" FLAG_REPLACE_CALL "):" \
100102
"(" FLAG_ENFORCE_CONTRACT "):" \
103+
OPT_ENFORCE_CONTRACT_REC \
101104
"(show-threaded)(list-calls-args)" \
102105
"(undefined-function-is-assume-false)" \
103106
"(remove-function-body):"\

0 commit comments

Comments
 (0)