Skip to content

Commit 61f07f6

Browse files
author
Daniel Kroening
authored
Merge pull request #3548 from diffblue/smt2_sign_extend
smt2 parser: fix sign extension
2 parents 4388a69 + a0164a8 commit 61f07f6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

scripts/delete_failing_smt2_solver_tests

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ rm Empty_struct1/test.desc
99
rm Endianness4/test.desc
1010
rm Endianness6/test.desc
1111
rm Endianness7/test.desc
12-
rm Fixedbv8/test.desc
1312
rm Float-div2/test.desc
1413
rm Float-div3/test.desc
1514
rm Float-no-simp1/test.desc
@@ -67,7 +66,6 @@ rm Quantifiers-not-exists/test.desc
6766
rm Quantifiers-two-dimension-array/test.desc
6867
rm Quantifiers-type/test.desc
6968
rm Struct_Bytewise2/test.desc
70-
rm Typecast1/test.desc
7169
rm Union_Initialization1/test.desc
7270
rm address_space_size_limit1/test.desc
7371
rm address_space_size_limit3/test.desc

src/solvers/smt2/smt2_parser.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,12 +780,17 @@ exprt smt2_parsert::function_application()
780780
}
781781
else if(id=="sign_extend")
782782
{
783-
auto width=to_unsignedbv_type(op[0].type()).get_width();
784-
signedbv_typet signed_type(width+index);
785-
unsignedbv_typet unsigned_type(width+index);
783+
// we first convert to a signed type of the original width,
784+
// then extend to the new width, and then go to unsigned
785+
const auto width = to_unsignedbv_type(op[0].type()).get_width();
786+
const signedbv_typet small_signed_type(width);
787+
const signedbv_typet large_signed_type(width + index);
788+
const unsignedbv_typet unsigned_type(width + index);
786789

787790
return typecast_exprt(
788-
typecast_exprt(op[0], signed_type), unsigned_type);
791+
typecast_exprt(
792+
typecast_exprt(op[0], small_signed_type), large_signed_type),
793+
unsigned_type);
789794
}
790795
else if(id=="zero_extend")
791796
{

0 commit comments

Comments
 (0)