ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
slice.h
Go to the documentation of this file.
1#ifndef CPROVER_GOTO_SYMEX_SLICE_H
2#define CPROVER_GOTO_SYMEX_SLICE_H
3
9#include <boost/range/adaptor/reversed.hpp>
11
12/* Base interface */
14{
15public:
19 BigInt ignored() const override
20 {
21 return sliced;
22 }
23
24protected:
27};
28
33class simple_slice : public slicer
34{
35public:
36 simple_slice() = default;
38};
39
44class claim_slicer : public slicer
45{
46public:
47 explicit claim_slicer(
48 const size_t claim_to_keep,
49 bool show_slice_info,
50 bool is_goto_cov,
55 ns(ns)
56 {
57 if (!claim_to_keep)
58 {
59 log_error("All the claims start from 1 (use --show-claims)");
60 abort();
61 }
62 };
65 std::string claim_msg;
66 std::string claim_loc;
67 std::string claim_cstr;
70 std::string claim_key;
74 std::string claim_property;
77 std::string claim_comment;
86};
87
97class symex_slicet : public slicer
98{
99public:
100 explicit symex_slicet(const optionst &options)
101 : slice_assumes(options.get_bool_option("slice-assumes")),
103 !options.get_bool_option("generate-testcase") &&
104 !options.get_bool_option("generate-ctest-testcase"))
105 {
106 }
107
117 {
118 // The slicer object is reused across equations (e.g. incremental-bmc /
119 // k-induction run it once per produced formula). Each formula must be
120 // sliced independently, so clear all per-equation state up front.
121 // (Previously only `sliced` was reset, leaking `depends` across equations.)
122 sliced = 0;
123 depends.clear();
124 collected_cache.clear();
125 index_reads.clear();
126 array_disqualified.clear();
127 scanned_cache.clear();
128
129 fine_timet algorithm_start = current_time();
130 for (auto &step : boost::adaptors::reverse(eq))
131 {
132 if (step.ignore)
133 continue;
134 run_on_step(step);
135 }
136 fine_timet algorithm_stop = current_time();
138 "Slicing time: {}s (removed {} assignments)",
139 time2string(algorithm_stop - algorithm_start),
140 sliced);
141 return true;
142 }
143
147 std::unordered_set<std::string> depends;
148
153 std::unordered_set<const expr2t *> collected_cache;
154
162 std::unordered_map<std::string, std::unordered_set<size_t>> index_reads;
163
167 std::unordered_set<std::string> array_disqualified;
168
173 std::unordered_set<const expr2t *> scanned_cache;
174
175 static expr2tc get_nondet_symbol(const expr2tc &expr);
176
177protected:
179 const bool slice_assumes;
181 const bool slice_nondet;
182
191 void collect_dependencies(const expr2tc &expr);
192
206 void scan_array_uses(const expr2tc &expr);
207
217 bool depends_on_tracked(const expr2tc &expr);
218
225 void run_on_assert(symex_target_equationt::SSA_stept &SSA_step) override;
226
244 void run_on_assume(symex_target_equationt::SSA_stept &SSA_step) override;
245
258
268 void run_on_renumber(symex_target_equationt::SSA_stept &SSA_step) override;
269};
270
271#endif
Definition bigint.hh:58
bool claim_after_invariant_havoc
Whether a –loop-invariant-check havoc step precedes the kept claim on this trace, so the claim is che...
Definition slice.h:82
std::string claim_cstr
Definition slice.h:67
std::string claim_msg
Definition slice.h:65
size_t claim_to_keep
Definition slice.h:64
const goto_programt::instructiont * claim_instruction
The instruction the kept claim was raised at.
Definition slice.h:72
property_locationt claim_ploc
Definition slice.h:73
locationt claim_location
Definition slice.h:78
bool is_goto_cov
Definition slice.h:84
bool run(symex_target_equationt::SSA_stepst &) override
Executes the algorithm over a T object.
Definition slice.cpp:379
std::string claim_loc
Definition slice.h:66
std::string claim_comment
The kept claim's description and source position, for the property report.
Definition slice.h:77
bool show_slice_info
Definition slice.h:83
namespacet ns
Definition slice.h:85
claim_slicer(const size_t claim_to_keep, bool show_slice_info, bool is_goto_cov, namespacet &ns)
Definition slice.h:47
std::string claim_key
The kept claim's key in the verdict table and skip set, and its row.
Definition slice.h:70
std::string claim_property
Definition slice.h:74
Container for an instruction of the goto-program.
Definition goto_program.h:95
Definition location.h:7
Definition namespace.h:10
Definition options.h:11
simple_slice()=default
bool run(symex_target_equationt::SSA_stepst &) override
Naive slicer: slice every step after the last assertion.
Definition slice.cpp:347
slicer()
Definition slice.h:16
BigInt sliced
tracks how many steps were sliced
Definition slice.h:26
BigInt ignored() const override
How many steps were ignored after this algorithm.
Definition slice.h:19
ssa_step_algorithm(bool sideffect)
Definition ssa_step_algorithm.h:12
void run_on_step(symex_target_equationt::SSA_stept &)
Definition ssa_step_algorithm.cpp:4
bool run(symex_target_equationt::SSA_stepst &eq) override
Iterate over all steps of the \eq in REVERSE order, getting symbol dependencies.
Definition slice.h:116
void scan_array_uses(const expr2tc &expr)
Record the array-element reads in \expr into index_reads, and disqualify (array_disqualified) any arr...
Definition slice.cpp:82
std::unordered_set< std::string > depends
Holds the symbols the current equation depends on.
Definition slice.h:147
void run_on_assert(symex_target_equationt::SSA_stept &SSA_step) override
Asserts are never sliced: collect the step's guard/cond symbols into depends and record their array r...
Definition slice.cpp:170
std::unordered_set< std::string > array_disqualified
Array versions whose element reads cannot be reasoned about per-index (whole-array use,...
Definition slice.h:167
bool depends_on_tracked(const expr2tc &expr)
Read-only: does \expr reference a tracked dependency (a symbol in depends or a no_slice symbol)?
Definition slice.cpp:149
void run_on_renumber(symex_target_equationt::SSA_stept &SSA_step) override
Remove unneeded renumbers from the formula.
Definition slice.cpp:324
static expr2tc get_nondet_symbol(const expr2tc &expr)
Definition slice.cpp:443
std::unordered_set< const expr2t * > collected_cache
BLACK set (two-color DFS in collect_dependencies): nodes already fully collected into depends.
Definition slice.h:153
void run_on_assignment(symex_target_equationt::SSA_stept &SSA_step) override
Remove unneeded assignments from the formula.
Definition slice.cpp:212
symex_slicet(const optionst &options)
Definition slice.h:100
void collect_dependencies(const expr2tc &expr)
Collect every symbol of \expr into depends (mutating "reverse-taint" accumulation).
Definition slice.cpp:10
std::unordered_set< const expr2t * > scanned_cache
BLACK set for the scan_array_uses two-color DFS — independent of collected_cache.
Definition slice.h:173
void run_on_assume(symex_target_equationt::SSA_stept &SSA_step) override
Remove unneeded assumes from the formula.
Definition slice.cpp:178
std::unordered_map< std::string, std::unordered_set< size_t > > index_reads
Per-array-version read map: versioned array-symbol name -> set of constant indices that are actually ...
Definition slice.h:162
const bool slice_nondet
Whether we should slice nondet symbols.
Definition slice.h:181
const bool slice_assumes
whether assumes should be sliced
Definition slice.h:179
Definition symex_target_equation.h:107
std::list< SSA_stept > SSA_stepst
Definition symex_target_equation.h:273
irep_container< expr2t > expr2tc
Definition irep2.h:431
#define log_status(fmt,...)
Definition message.h:101
#define log_error(fmt,...)
Definition message.h:83
#define true
Definition stdbool.h:11
void abort(void)
Definition stdlib.c:77
Where a property lives, kept apart from the table key so the report can sort by source position and p...
Definition property_verdict.h:35
fine_timet current_time()
Definition time_stopping.cpp:33
std::string time2string(const fine_timet &fine_time)
Definition time_stopping.cpp:49
unsigned long long fine_timet
Definition time_stopping.h:4