Skip to content

Commit 13e3a3d

Browse files
author
Daniel Kroening
authored
Merge pull request #3016 from diffblue/from_integer_negative_natural
API change: from_integer for negative naturals
2 parents 3e8c886 + 92eab68 commit 13e3a3d

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/util/arith_tools.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,7 @@ constant_exprt from_integer(
117117
}
118118
else if(type_id==ID_natural)
119119
{
120-
if(int_value<0)
121-
{
122-
constant_exprt r;
123-
r.make_nil();
124-
return r;
125-
}
126-
120+
PRECONDITION(int_value >= 0);
127121
return constant_exprt(integer2string(int_value), type);
128122
}
129123
else if(type_id==ID_unsignedbv)
@@ -154,15 +148,16 @@ constant_exprt from_integer(
154148
}
155149
else if(type_id==ID_bool)
156150
{
157-
if(int_value==0)
151+
PRECONDITION(int_value == 0 || int_value == 1);
152+
if(int_value == 0)
158153
return false_exprt();
159-
else if(int_value==1)
154+
else
160155
return true_exprt();
161156
}
162157
else if(type_id==ID_pointer)
163158
{
164-
if(int_value==0)
165-
return null_pointer_exprt(to_pointer_type(type));
159+
PRECONDITION(int_value == 0);
160+
return null_pointer_exprt(to_pointer_type(type));
166161
}
167162
else if(type_id==ID_c_bit_field)
168163
{
@@ -182,13 +177,8 @@ constant_exprt from_integer(
182177
ieee_float.from_integer(int_value);
183178
return ieee_float.to_expr();
184179
}
185-
186-
{
180+
else
187181
PRECONDITION(false);
188-
constant_exprt r;
189-
r.make_nil();
190-
return r;
191-
}
192182
}
193183

194184
/// ceil(log2(size))

0 commit comments

Comments
 (0)