-
Notifications
You must be signed in to change notification settings - Fork 273
Replace make_typecast by typecast_exprt or typecast_exprt::conditional_cast [blocks: #3800] #3991
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
Replace make_typecast by typecast_exprt or typecast_exprt::conditional_cast [blocks: #3800] #3991
Conversation
5eeea41
to
8ce771e
Compare
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.
Few places where there's now a multi-line statement after an if
or for
which I'd prefer to be braced, otherwise lgtm
src/goto-programs/goto_convert.cpp
Outdated
DATA_INVARIANT( | ||
lhs.operands().size() == 1, "Typecast must have one operand"); | ||
UNREACHABLE; // the original code here was broken, presumably it's never used | ||
typecast_exprt tc = to_typecast_expr(lhs); |
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.
I think some compilers will give you a hard time for this unreachable code
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.
I have no idea how we would generate an expression that has a typecast on the left-hand side, but even if and when we do: at least goto-symex does handle that case, so we could safely leave it in the goto program. I am going to add a commit that simply removes this code.
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.
We definitely do sometimes produce void** data = new void*[10]; ((Object**)data)[0] = new Object
in the Java frontend. Whether we should is another question!
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.
Sure, and you can make something similar happen in C (*(char*)&x = 42;
) - but there's an index_exprt
on the left-hand side in your example and a dereference_exprt
in my case. Neither has a typecast at the top level on the left-hand side.
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.
True. In the past we would sometimes do (Object*)var = new Object
, but AFAIK that's no longer generated by the frontend
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.
I think even if that were still the case, goto-symex would happily take care of that.
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 for the record, those changes have now been moved to #3770, this PR now exclusively deals with replacing make_typecast
.
8ce771e
to
bc7f7d6
Compare
bc7f7d6
to
9ee63c4
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 9ee63c4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/99188565
9ee63c4
to
8685209
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 8685209).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/99534366
@@ -2955,7 +2956,7 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr) | |||
is_number(o_type1)) | |||
{ | |||
// convert op1 to the vector type | |||
op1.make_typecast(o_type0); | |||
op1 = typecast_exprt::conditional_cast(op1, o_type0); | |||
expr.type() = o_type0; |
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.
A conditional_cast appears to be wrong here. When we are in this branch, the cast is always needed. Simply use the constructor.
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.
Done.
@@ -2964,7 +2965,7 @@ void c_typecheck_baset::typecheck_expr_binary_arithmetic(exprt &expr) | |||
is_number(o_type0)) | |||
{ | |||
// convert op0 to the vector type | |||
op0.make_typecast(o_type1); | |||
op0 = typecast_exprt::conditional_cast(op0, o_type1); | |||
expr.type() = o_type1; |
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.
Same here.
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.
Done.
if(width==config.ansi_c.int_width) | ||
int_type.id(ID_unsignedbv); | ||
new_expr.make_typecast(int_type); | ||
new_expr = typecast_exprt::conditional_cast(expr, int_type); | ||
return true; |
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.
Same here -- the cast will always happen.
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.
I don't think so - the line above the change would make the typecast a no-op.
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.
Unrelated to PR: the two lines above the change are dead code (note the branch directly before). There's probably a bug there.
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.
Oh, indeed. Aren't those two lines really just unnecessary, and we should do an unconditional cast as you suggested? To me it seems there no bug other than it being dead code.
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.
The bug is that an "unsigned int" will be promoted to "signed int", which is wrong.
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.
I don't think so, the width >= config.ansi_c.int_width
would catch that?
@@ -271,8 +267,7 @@ bool cpp_typecheckt::standard_conversion_floating_point_promotion( | |||
c_qualifierst qual_from; | |||
qual_from.read(expr.type()); | |||
|
|||
new_expr=expr; | |||
new_expr.make_typecast(double_type()); | |||
new_expr = typecast_exprt::conditional_cast(expr, double_type()); | |||
qual_from.write(new_expr.type()); |
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.
same here
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.
Done.
exprt rhs_tc(rhs); | ||
rhs_tc.make_typecast(pointer_type(char_type())); | ||
exprt rhs_tc = | ||
typecast_exprt::conditional_cast(rhs, pointer_type(char_type())); | ||
|
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.
Same here
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.
Done.
if(count.type()!=object_size.type()) | ||
count.make_typecast(object_size.type()); | ||
count = typecast_exprt( | ||
static_cast<const exprt &>(rhs.find(ID_size)), object_size.type()); | ||
|
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.
But here it's the conditional_cast
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.
Done.
@@ -382,7 +382,7 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to( | |||
equal_exprt equality(pointer_expr, object_pointer); | |||
|
|||
if(ns.follow(equality.lhs().type())!=ns.follow(equality.rhs().type())) | |||
equality.lhs().make_typecast(equality.rhs().type()); | |||
equality.lhs() = typecast_exprt(equality.lhs(), equality.rhs().type()); | |||
|
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.
Conditional cast!
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.
Done (killing the ns.follow)
@@ -452,7 +452,7 @@ value_set_dereferencet::valuet value_set_dereferencet::build_reference_to( | |||
result.value=index_expr; | |||
|
|||
if(ns.follow(result.value.type())!=ns.follow(dereference_type)) | |||
result.value.make_typecast(dereference_type); | |||
result.value = typecast_exprt(result.value, dereference_type); | |||
} |
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.
Same here
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.
Done (killing ns.follow)
@@ -594,7 +594,7 @@ bool value_set_dereferencet::memory_model_bytes( | |||
|
|||
// possibly need to convert | |||
if(!base_type_eq(result.type(), to_type, ns)) | |||
result.make_typecast(to_type); | |||
result = typecast_exprt(result, to_type); | |||
} |
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.
Same here
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.
Done (killing this instance of base_type_eq
)
8685209
to
76b2c26
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: 76b2c26).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100052504
9ece3a7
to
f6948db
Compare
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.
🚫
This PR failed Diffblue compatibility checks (cbmc commit: 9ece3a7).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100077874
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.
Common spurious failures:
- the cbmc commit has disappeared in the mean time (e.g. in a force-push)
- the author is not in the list of contributors (e.g. first-time contributors).
The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: f6948db).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100080400
…l_cast make_typecast is deprecated.
f6948db
to
ebaacea
Compare
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: ebaacea).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100100359
make_typecast is deprecated.