-
Notifications
You must be signed in to change notification settings - Fork 274
numeric_cast_v(expr) now requires constant_expr #4004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,9 +72,13 @@ bool boolbvt::literal( | |
std::size_t element_width=boolbv_width(index_expr.type()); | ||
CHECK_RETURN(element_width != 0); | ||
|
||
mp_integer index = numeric_cast_v<mp_integer>(index_expr.index()); | ||
const auto &index = index_expr.index(); | ||
PRECONDITION(index.id() == ID_constant); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ Or this |
||
mp_integer index_int = | ||
numeric_cast_v<mp_integer>(to_constant_expr(index)); | ||
|
||
std::size_t offset = numeric_cast_v<std::size_t>(index * element_width); | ||
std::size_t offset = | ||
numeric_cast_v<std::size_t>(index_int * element_width); | ||
|
||
return literal(index_expr.array(), bit+offset, dest); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,13 @@ Author: Daniel Kroening, [email protected] | |
literalt boolbvt::convert_extractbit(const extractbit_exprt &expr) | ||
{ | ||
const bvt &src_bv = convert_bv(expr.src()); | ||
const auto &index = expr.index(); | ||
|
||
// constant? | ||
if(expr.index().is_constant()) | ||
if(index.is_constant()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think more idiomatic in this code base to: if(const auto &constant_index = try_expr_dynamic_cast<constant_exprt>(index))
{
...
numeric_cast_v<mp_integer>(constant_index); Since seems plausible the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or shorter using an optional: if(const auto index_as_integer = numeric_cast<mp_integer>(index)) |
||
{ | ||
mp_integer index_as_integer = numeric_cast_v<mp_integer>(expr.index()); | ||
mp_integer index_as_integer = | ||
numeric_cast_v<mp_integer>(to_constant_expr(index)); | ||
|
||
if(index_as_integer < 0 || index_as_integer >= src_bv.size()) | ||
return prop.new_variable(); // out of range! | ||
|
@@ -42,7 +44,7 @@ literalt boolbvt::convert_extractbit(const extractbit_exprt &expr) | |
else | ||
{ | ||
std::size_t src_bv_width = boolbv_width(expr.src().type()); | ||
std::size_t index_bv_width = boolbv_width(expr.index().type()); | ||
std::size_t index_bv_width = boolbv_width(index.type()); | ||
|
||
if(src_bv_width == 0 || index_bv_width == 0) | ||
return SUB::convert_rest(expr); | ||
|
@@ -52,7 +54,7 @@ literalt boolbvt::convert_extractbit(const extractbit_exprt &expr) | |
unsignedbv_typet index_type(index_width); | ||
|
||
equal_exprt equality( | ||
typecast_exprt::conditional_cast(expr.index(), index_type), exprt()); | ||
typecast_exprt::conditional_cast(index, index_type), exprt()); | ||
|
||
if(prop.has_set_to()) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,8 +87,10 @@ get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr) | |
continue; | ||
if(expr_eq(var_expr, x.op0()) && x.op1().id()==ID_constant) | ||
{ | ||
exprt over_expr=x.op1(); | ||
const constant_exprt &over_expr = to_constant_expr(x.op1()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⛏️ While in the area, you might like to tidy the if to not duplicate the checking the id by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or the version of |
||
|
||
mp_integer over_i = numeric_cast_v<mp_integer>(over_expr); | ||
|
||
/** | ||
* Due to the ''simplify'', | ||
* the ''over_i'' value we obtain here is not the exact | ||
|
@@ -115,7 +117,7 @@ get_quantifier_var_max(const exprt &var_expr, const exprt &quantifier_expr) | |
continue; | ||
if(expr_eq(var_expr, y.op0()) && y.op1().id()==ID_constant) | ||
{ | ||
exprt over_expr=y.op1(); | ||
const constant_exprt &over_expr = to_constant_expr(y.op1()); | ||
mp_integer over_i = numeric_cast_v<mp_integer>(over_expr); | ||
over_i-=1; | ||
res=from_integer(over_i, y.op1().type()); | ||
|
@@ -149,8 +151,8 @@ instantiate_quantifier(const quantifier_exprt &expr, const namespacet &ns) | |
if(min_i.is_false() || max_i.is_false()) | ||
return nullopt; | ||
|
||
mp_integer lb = numeric_cast_v<mp_integer>(min_i); | ||
mp_integer ub = numeric_cast_v<mp_integer>(max_i); | ||
mp_integer lb = numeric_cast_v<mp_integer>(to_constant_expr(min_i)); | ||
mp_integer ub = numeric_cast_v<mp_integer>(to_constant_expr(max_i)); | ||
|
||
if(lb>ub) | ||
return nullopt; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant with
to_constant_expr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Just noting this never got addressed.