@@ -17,13 +17,6 @@ bvt boolbvt::convert_extractbits(const extractbits_exprt &expr)
17
17
if (bv_width == 0 )
18
18
return conversion_failed (expr);
19
19
20
- if (expr.operands ().size ()!=3 )
21
- {
22
- error ().source_location =expr.find_source_location ();
23
- error () << " extractbits takes three operands" << eom;
24
- throw 0 ;
25
- }
26
-
27
20
auto const &src_bv = convert_bv (expr.src ());
28
21
29
22
auto const maybe_upper_as_int = numeric_cast<mp_integer>(expr.upper ());
@@ -37,34 +30,29 @@ bvt boolbvt::convert_extractbits(const extractbits_exprt &expr)
37
30
auto upper_as_int = maybe_upper_as_int.value ();
38
31
auto lower_as_int = maybe_lower_as_int.value ();
39
32
40
- if (upper_as_int < 0 || upper_as_int >= src_bv.size ())
41
- {
42
- error ().source_location =expr.find_source_location ();
43
- error () << " extractbits: second operand out of range: "
44
- << expr.pretty () << eom;
45
- }
46
-
47
- if (lower_as_int < 0 || lower_as_int >= src_bv.size ())
48
- {
49
- error ().source_location =expr.find_source_location ();
50
- error () << " extractbits: third operand out of range: "
51
- << expr.pretty () << eom;
52
- throw 0 ;
53
- }
33
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
34
+ upper_as_int >= 0 && upper_as_int < src_bv.size (),
35
+ " upper end of extracted bits must be within the bitvector" ,
36
+ expr.find_source_location (),
37
+ irep_pretty_diagnosticst{expr});
38
+
39
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
40
+ lower_as_int >= 0 && lower_as_int < src_bv.size (),
41
+ " lower end of extracted bits must be within the bitvector" ,
42
+ expr.find_source_location (),
43
+ irep_pretty_diagnosticst{expr});
54
44
55
45
if (lower_as_int > upper_as_int)
56
46
std::swap (upper_as_int, lower_as_int);
57
47
58
48
// now lower_as_int <= upper_as_int
59
49
60
- if ((upper_as_int - lower_as_int + 1 ) != bv_width)
61
- {
62
- error ().source_location =expr.find_source_location ();
63
- error () << " extractbits: wrong width (expected "
64
- << (upper_as_int - lower_as_int + 1 ) << " but got " << bv_width
65
- << " ): " << expr.pretty () << eom;
66
- throw 0 ;
67
- }
50
+ DATA_INVARIANT_WITH_DIAGNOSTICS (
51
+ (upper_as_int - lower_as_int + 1 ) == bv_width,
52
+ " the difference between upper and lower end of the range must have the "
53
+ " same width as the resulting bitvector type" ,
54
+ expr.find_source_location (),
55
+ irep_pretty_diagnosticst{expr});
68
56
69
57
const std::size_t offset = integer2unsigned (lower_as_int);
70
58
0 commit comments