Skip to content

Commit 12f25c2

Browse files
author
thk123
committed
Introduce throwing bv_conversion expection
Remove suprisous namespace from bv_conversion_exceptions
1 parent 9bd5222 commit 12f25c2

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ bvt boolbvt::conversion_failed(const exprt &expr)
152152
return prop.new_variables(width);
153153
}
154154

155+
/// TODO
156+
/// \param expr: TODO
157+
/// \return TODO
158+
/// \throws bitvector_conversion_exceptiont raised if converting byte_extraction
159+
/// goes wrong.
160+
/// TODO: extend for other types of conversion exception (diffblue/cbmc#2103).
155161
bvt boolbvt::convert_bitvector(const exprt &expr)
156162
{
157163
if(expr.type().id()==ID_bool)

src/solvers/flattening/boolbv_byte_extract.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ Author: Daniel Kroening, [email protected]
1111
#include <cassert>
1212

1313
#include <util/arith_tools.h>
14-
#include <util/std_expr.h>
1514
#include <util/byte_operators.h>
1615
#include <util/endianness_map.h>
16+
#include <util/std_expr.h>
1717

18+
#include "bv_conversion_exceptions.h"
19+
#include "flatten_byte_extract_exceptions.h"
1820
#include "flatten_byte_operators.h"
1921

2022
bvt map_bv(const endianness_mapt &map, const bvt &src)
@@ -42,8 +44,16 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
4244
// if we extract from an unbounded array, call the flattening code
4345
if(is_unbounded_array(expr.op().type()))
4446
{
45-
exprt tmp=flatten_byte_extract(expr, ns);
46-
return convert_bv(tmp);
47+
try
48+
{
49+
exprt tmp = flatten_byte_extract(expr, ns);
50+
return convert_bv(tmp);
51+
}
52+
catch(const flatten_byte_extract_exceptiont &byte_extract_flatten_exception)
53+
{
54+
std::throw_with_nested(
55+
bitvector_conversion_exceptiont("Can't convert byte_extraction", expr));
56+
}
4757
}
4858

4959
std::size_t width=boolbv_width(expr.type());
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************\
2+
3+
Module: Bit vector conversion
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Exceptions that can be raised in bv_conversion
11+
12+
#ifndef CPROVER_SOLVERS_FLATTENING_BV_CONVERSION_EXCEPTIONS_H
13+
#define CPROVER_SOLVERS_FLATTENING_BV_CONVERSION_EXCEPTIONS_H
14+
15+
#include <stdexcept>
16+
#include <string>
17+
18+
#include <util/expr.h>
19+
20+
class bitvector_conversion_exceptiont : public std::runtime_error
21+
{
22+
public:
23+
bitvector_conversion_exceptiont(
24+
const std::string &exception_message,
25+
const exprt &bv_expr)
26+
: runtime_error(exception_message), bv_expr(bv_expr)
27+
{
28+
}
29+
30+
private:
31+
exprt bv_expr;
32+
};
33+
34+
#endif // CPROVER_SOLVERS_FLATTENING_BV_CONVERSION_EXCEPTIONS_H

0 commit comments

Comments
 (0)