@@ -883,8 +883,9 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
883
883
exprt &op=*it;
884
884
if (op.is_true () || op.is_false ())
885
885
{
886
- bool value=op.is_true ();
887
- op=constant_exprt (value?ID_1:ID_0, unsignedbv_typet (1 ));
886
+ const bool value = op.is_true ();
887
+ op = from_integer (value, unsignedbv_typet (1 ));
888
+ result = true ;
888
889
}
889
890
}
890
891
@@ -902,10 +903,20 @@ bool simplify_exprt::simplify_concatenation(exprt &expr)
902
903
is_bitvector_type (opn.type ()))
903
904
{
904
905
// merge!
905
- const std::string new_value=
906
- opi.get_string (ID_value)+opn.get_string (ID_value);
907
- opi.set (ID_value, new_value);
908
- opi.type ().set (ID_width, new_value.size ());
906
+ const auto &value_i = to_constant_expr (opi).get_value ();
907
+ const auto &value_n = to_constant_expr (opn).get_value ();
908
+ const auto width_i = to_bitvector_type (opi.type ()).get_width ();
909
+ const auto width_n = to_bitvector_type (opn.type ()).get_width ();
910
+ const auto new_width = width_i + width_n;
911
+
912
+ const auto new_value =
913
+ make_bvrep (new_width, [&value_i, &value_n, width_n](std::size_t x) {
914
+ return x < width_n ? get_bitvector_bit (value_n, x)
915
+ : get_bitvector_bit (value_i, x - width_n);
916
+ });
917
+
918
+ to_constant_expr (opi).set_value (new_value);
919
+ opi.type ().set (ID_width, new_width);
909
920
// erase opn
910
921
expr.operands ().erase (expr.operands ().begin ()+i+1 );
911
922
result=true ;
0 commit comments