Skip to content

Commit 38b47b5

Browse files
committed
BMC: word-level property instantiation now uses mp_integer
This changes the time frame index type from std::size_t by mp_integer, which avoids having to deal with possible overflow when adding.
1 parent 3e51bdb commit 38b47b5

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

src/trans-word-level/instantiate_word_level.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Function: timeframe_identifier
2929
\*******************************************************************/
3030

3131
std::string
32-
timeframe_identifier(std::size_t timeframe, const irep_idt &identifier)
32+
timeframe_identifier(const mp_integer &timeframe, const irep_idt &identifier)
3333
{
34-
return id2string(identifier)+"@"+std::to_string(timeframe);
34+
return id2string(identifier) + "@" + integer2string(timeframe);
3535
}
3636

3737
/*******************************************************************\
@@ -46,7 +46,7 @@ Function: timeframe_symbol
4646
4747
\*******************************************************************/
4848

49-
symbol_exprt timeframe_symbol(std::size_t timeframe, symbol_exprt src)
49+
symbol_exprt timeframe_symbol(const mp_integer &timeframe, symbol_exprt src)
5050
{
5151
auto result = std::move(src);
5252
result.set_identifier(
@@ -69,23 +69,23 @@ symbol_exprt timeframe_symbol(std::size_t timeframe, symbol_exprt src)
6969
class wl_instantiatet
7070
{
7171
public:
72-
wl_instantiatet(std::size_t _no_timeframes, const namespacet &_ns)
72+
wl_instantiatet(const mp_integer &_no_timeframes, const namespacet &_ns)
7373
: no_timeframes(_no_timeframes), ns(_ns)
7474
{
7575
}
7676

7777
/// Instantiate the given expression for timeframe t
78-
[[nodiscard]] exprt operator()(exprt expr, std::size_t t) const
78+
[[nodiscard]] exprt operator()(exprt expr, const mp_integer &t) const
7979
{
8080
return instantiate_rec(std::move(expr), t);
8181
}
8282

8383
protected:
84-
std::size_t no_timeframes;
84+
const mp_integer &no_timeframes;
8585
const namespacet &ns;
8686

87-
[[nodiscard]] exprt instantiate_rec(exprt, std::size_t t) const;
88-
[[nodiscard]] typet instantiate_rec(typet, std::size_t t) const;
87+
[[nodiscard]] exprt instantiate_rec(exprt, const mp_integer &t) const;
88+
[[nodiscard]] typet instantiate_rec(typet, const mp_integer &t) const;
8989
};
9090

9191
/*******************************************************************\
@@ -100,7 +100,7 @@ Function: wl_instantiatet::instantiate_rec
100100
101101
\*******************************************************************/
102102

103-
exprt wl_instantiatet::instantiate_rec(exprt expr, const std::size_t t) const
103+
exprt wl_instantiatet::instantiate_rec(exprt expr, const mp_integer &t) const
104104
{
105105
expr.type() = instantiate_rec(expr.type(), t);
106106

@@ -158,7 +158,7 @@ exprt wl_instantiatet::instantiate_rec(exprt expr, const std::size_t t) const
158158
if(to_integer_non_constant(ternary_expr.op0(), offset))
159159
throw "failed to convert sva_cycle_delay offset";
160160

161-
const auto u = t + offset.to_ulong();
161+
const auto u = t + offset;
162162

163163
// Do we exceed the bound? Make it 'true'
164164
if(u >= no_timeframes)
@@ -186,7 +186,7 @@ exprt wl_instantiatet::instantiate_rec(exprt expr, const std::size_t t) const
186186

187187
for(mp_integer offset=from; offset<to; ++offset)
188188
{
189-
auto u = t + offset.to_ulong();
189+
auto u = t + offset;
190190

191191
if(u >= no_timeframes)
192192
{
@@ -219,7 +219,7 @@ exprt wl_instantiatet::instantiate_rec(exprt expr, const std::size_t t) const
219219

220220
exprt::operandst conjuncts;
221221

222-
for(auto u = t; u < no_timeframes; u++)
222+
for(auto u = t; u < no_timeframes; ++u)
223223
{
224224
conjuncts.push_back(instantiate_rec(op, u));
225225
}
@@ -261,11 +261,11 @@ exprt wl_instantiatet::instantiate_rec(exprt expr, const std::size_t t) const
261261
exprt::operandst conjuncts = {};
262262
const auto i = t;
263263

264-
for(std::size_t k = 0; k < i; k++)
264+
for(mp_integer k = 0; k < i; ++k)
265265
{
266266
exprt::operandst disjuncts = {not_exprt(lasso_symbol(k, i))};
267267

268-
for(std::size_t j = k; j <= i; j++)
268+
for(mp_integer j = k; j <= i; ++j)
269269
{
270270
disjuncts.push_back(instantiate_rec(p, j));
271271
}
@@ -338,7 +338,7 @@ Function: wl_instantiatet::instantiate_rec
338338
339339
\*******************************************************************/
340340

341-
typet wl_instantiatet::instantiate_rec(typet type, std::size_t) const
341+
typet wl_instantiatet::instantiate_rec(typet type, const mp_integer &) const
342342
{
343343
return type;
344344
}
@@ -357,8 +357,8 @@ Function: instantiate
357357

358358
exprt instantiate(
359359
const exprt &expr,
360-
std::size_t t,
361-
std::size_t no_timeframes,
360+
const mp_integer &t,
361+
const mp_integer &no_timeframes,
362362
const namespacet &ns)
363363
{
364364
wl_instantiatet wl_instantiate(no_timeframes, ns);

src/trans-word-level/instantiate_word_level.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_BMC_INSTANTIATE_WORD_LEVEL_H
1010
#define CPROVER_BMC_INSTANTIATE_WORD_LEVEL_H
1111

12-
#include <solvers/prop/prop_conv.h>
13-
12+
#include <util/mp_arith.h>
1413
#include <util/namespace.h>
1514

15+
#include <solvers/prop/prop_conv.h>
16+
1617
exprt instantiate(
1718
const exprt &expr,
18-
std::size_t current,
19-
std::size_t no_timeframes,
19+
const mp_integer &current,
20+
const mp_integer &no_timeframes,
2021
const namespacet &);
2122

2223
std::string
23-
timeframe_identifier(std::size_t timeframe, const irep_idt &identifier);
24+
timeframe_identifier(const mp_integer &timeframe, const irep_idt &identifier);
2425

25-
symbol_exprt timeframe_symbol(std::size_t timeframe, symbol_exprt);
26+
symbol_exprt timeframe_symbol(const mp_integer &timeframe, symbol_exprt);
2627

2728
#endif

src/trans-word-level/property.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ Function: states_equal
109109
\*******************************************************************/
110110

111111
exprt states_equal(
112-
std::size_t k,
113-
std::size_t i,
112+
const mp_integer &k,
113+
const mp_integer &i,
114114
const std::vector<symbol_exprt> &variables_to_compare)
115115
{
116116
// We require k<i to avoid the symmetric constraints.
@@ -141,13 +141,13 @@ Function: lasso_symbol
141141
142142
\*******************************************************************/
143143

144-
symbol_exprt lasso_symbol(std::size_t k, std::size_t i)
144+
symbol_exprt lasso_symbol(const mp_integer &k, const mp_integer &i)
145145
{
146146
// True when states i and k are equal.
147147
// We require k<i to avoid the symmetric constraints.
148148
PRECONDITION(k < i);
149149
irep_idt lasso_identifier =
150-
"lasso::" + std::to_string(i) + "-back-to-" + std::to_string(k);
150+
"lasso::" + integer2string(i) + "-back-to-" + integer2string(k);
151151
return symbol_exprt(lasso_identifier, bool_typet());
152152
}
153153

@@ -165,7 +165,7 @@ Function: lasso_constraints
165165

166166
void lasso_constraints(
167167
decision_proceduret &solver,
168-
std::size_t no_timeframes,
168+
const mp_integer &no_timeframes,
169169
const namespacet &ns,
170170
const irep_idt &module_identifier)
171171
{
@@ -204,9 +204,9 @@ void lasso_constraints(
204204
}
205205
}
206206

207-
for(std::size_t i = 1; i < no_timeframes; i++)
207+
for(mp_integer i = 1; i < no_timeframes; ++i)
208208
{
209-
for(std::size_t k = 0; k < i; k++)
209+
for(mp_integer k = 0; k < i; ++k)
210210
{
211211
// Is there a loop back from time frame i back to time frame k?
212212
auto lasso_symbol = ::lasso_symbol(k, i);

src/trans-word-level/property.h

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

1212
#include <util/expr.h>
1313
#include <util/message.h>
14+
#include <util/mp_arith.h>
1415
#include <util/namespace.h>
1516

1617
#include <solvers/decision_procedure.h>
@@ -30,13 +31,13 @@ bool bmc_supports_property(const exprt &);
3031
/// given state has already been seen earlier in the trace.
3132
void lasso_constraints(
3233
decision_proceduret &,
33-
std::size_t no_timeframes,
34+
const mp_integer &no_timeframes,
3435
const namespacet &,
3536
const irep_idt &module_identifier);
3637

3738
/// Is there a loop from i back to k?
3839
/// Precondition: k<i
39-
symbol_exprt lasso_symbol(std::size_t k, std::size_t i);
40+
symbol_exprt lasso_symbol(const mp_integer &k, const mp_integer &i);
4041

4142
/// Returns true iff the given property requires lasso constraints for BMC.
4243
bool requires_lasso_constraints(const exprt &);

0 commit comments

Comments
 (0)