-
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
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 |
---|---|---|
|
@@ -2596,10 +2596,11 @@ exprt c_typecheck_baset::do_special_functions( | |
throw 0; | ||
} | ||
|
||
expr.arguments()[0].make_typecast(bool_typet()); | ||
make_constant(expr.arguments()[0]); | ||
exprt arg0 = | ||
typecast_exprt::conditional_cast(expr.arguments()[0], bool_typet()); | ||
make_constant(arg0); | ||
|
||
if(expr.arguments()[0].is_true()) | ||
if(arg0.is_true()) | ||
return expr.arguments()[1]; | ||
else | ||
return expr.arguments()[2]; | ||
|
@@ -2953,7 +2954,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(op1, o_type0); | ||
expr.type() = o_type0; | ||
return; | ||
} | ||
|
@@ -2962,7 +2963,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(op0, o_type1); | ||
expr.type() = o_type1; | ||
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. Same here. 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. Done. |
||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,8 +210,7 @@ bool cpp_typecheckt::standard_conversion_integral_promotion( | |
std::size_t width=to_signedbv_type(expr.type()).get_width(); | ||
if(width >= config.ansi_c.int_width) | ||
return false; | ||
new_expr=expr; | ||
new_expr.make_typecast(int_type); | ||
new_expr = typecast_exprt(expr, int_type); | ||
return true; | ||
} | ||
|
||
|
@@ -220,24 +219,19 @@ bool cpp_typecheckt::standard_conversion_integral_promotion( | |
std::size_t width=to_unsignedbv_type(expr.type()).get_width(); | ||
if(width >= config.ansi_c.int_width) | ||
return false; | ||
new_expr=expr; | ||
if(width==config.ansi_c.int_width) | ||
int_type.id(ID_unsignedbv); | ||
new_expr.make_typecast(int_type); | ||
new_expr = typecast_exprt(expr, int_type); | ||
return true; | ||
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. Same here -- the cast will always happen. 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 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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, the |
||
} | ||
|
||
if(expr.type().id() == ID_bool || expr.type().id() == ID_c_bool) | ||
{ | ||
new_expr = expr; | ||
new_expr.make_typecast(int_type); | ||
new_expr = typecast_exprt(expr, int_type); | ||
return true; | ||
} | ||
|
||
if(expr.type().id()==ID_c_enum_tag) | ||
{ | ||
new_expr=expr; | ||
new_expr.make_typecast(int_type); | ||
new_expr = typecast_exprt(expr, int_type); | ||
return true; | ||
} | ||
|
||
|
@@ -271,8 +265,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(expr, double_type()); | ||
qual_from.write(new_expr.type()); | ||
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. same here 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. Done. |
||
|
||
return true; | ||
|
@@ -328,8 +321,7 @@ bool cpp_typecheckt::standard_conversion_integral_conversion( | |
|
||
c_qualifierst qual_from; | ||
qual_from.read(expr.type()); | ||
new_expr=expr; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(expr, type); | ||
qual_from.write(new_expr.type()); | ||
|
||
return true; | ||
|
@@ -382,8 +374,7 @@ bool cpp_typecheckt::standard_conversion_floating_integral_conversion( | |
|
||
c_qualifierst qual_from; | ||
qual_from.read(expr.type()); | ||
new_expr=expr; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(expr, type); | ||
qual_from.write(new_expr.type()); | ||
|
||
return true; | ||
|
@@ -425,8 +416,7 @@ bool cpp_typecheckt::standard_conversion_floating_point_conversion( | |
c_qualifierst qual_from; | ||
|
||
qual_from.read(expr.type()); | ||
new_expr=expr; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(expr, type); | ||
qual_from.write(new_expr.type()); | ||
|
||
return true; | ||
|
@@ -508,8 +498,7 @@ bool cpp_typecheckt::standard_conversion_pointer( | |
{ | ||
c_qualifierst qual_from; | ||
qual_from.read(expr.type().subtype()); | ||
new_expr=expr; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(expr, type); | ||
qual_from.write(new_expr.type().subtype()); | ||
return true; | ||
} | ||
|
@@ -614,8 +603,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member( | |
if(expr.id()==ID_constant && | ||
expr.get(ID_value)==ID_NULL) | ||
{ | ||
new_expr=expr; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(expr, type); | ||
return true; | ||
} | ||
|
||
|
@@ -627,8 +615,7 @@ bool cpp_typecheckt::standard_conversion_pointer_to_member( | |
|
||
if(subtype_typecast(to_struct, from_struct)) | ||
{ | ||
new_expr=expr; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(expr, type); | ||
return true; | ||
} | ||
|
||
|
@@ -664,8 +651,7 @@ bool cpp_typecheckt::standard_conversion_boolean( | |
typet Bool = c_bool_type(); | ||
qual_from.write(Bool); | ||
|
||
new_expr=expr; | ||
new_expr.make_typecast(Bool); | ||
new_expr = typecast_exprt::conditional_cast(expr, Bool); | ||
return true; | ||
} | ||
|
||
|
@@ -705,7 +691,7 @@ bool cpp_typecheckt::standard_conversion_sequence( | |
|
||
// we turn bit fields into their underlying type | ||
if(curr_expr.type().id()==ID_c_bit_field) | ||
curr_expr.make_typecast(curr_expr.type().subtype()); | ||
curr_expr = typecast_exprt(curr_expr, curr_expr.type().subtype()); | ||
|
||
if(curr_expr.type().id()==ID_array) | ||
{ | ||
|
@@ -791,7 +777,7 @@ bool cpp_typecheckt::standard_conversion_sequence( | |
if(expr.type().subtype().id()==ID_nullptr) | ||
{ | ||
// std::nullptr_t to _any_ pointer type is ok | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(new_expr, type); | ||
} | ||
else if(!standard_conversion_pointer(curr_expr, type, new_expr)) | ||
{ | ||
|
@@ -1278,7 +1264,7 @@ bool cpp_typecheckt::reference_binding( | |
{ | ||
c_qualifierst qual_from; | ||
qual_from.read(expr.type()); | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(new_expr, type); | ||
qual_from.write(new_expr.type().subtype()); | ||
} | ||
|
||
|
@@ -1805,8 +1791,7 @@ bool cpp_typecheckt::reinterpret_typecast( | |
(type.id()==ID_unsignedbv || type.id()==ID_signedbv)) | ||
{ | ||
// pointer to integer, always ok | ||
new_expr=e; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(e, type); | ||
return true; | ||
} | ||
|
||
|
@@ -1825,8 +1810,7 @@ bool cpp_typecheckt::reinterpret_typecast( | |
} | ||
else | ||
{ | ||
new_expr=e; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(e, type); | ||
} | ||
return true; | ||
} | ||
|
@@ -1837,16 +1821,13 @@ bool cpp_typecheckt::reinterpret_typecast( | |
{ | ||
// pointer to pointer: we ok it all. | ||
// This is more generous than the standard. | ||
new_expr=expr; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(expr, type); | ||
return true; | ||
} | ||
|
||
if(is_reference(type) && e.get_bool(ID_C_lvalue)) | ||
{ | ||
exprt tmp=address_of_exprt(e); | ||
tmp.make_typecast(type); | ||
new_expr.swap(tmp); | ||
new_expr = typecast_exprt::conditional_cast(address_of_exprt(e), type); | ||
return true; | ||
} | ||
|
||
|
@@ -1919,8 +1900,7 @@ bool cpp_typecheckt::static_typecast( | |
|
||
if(type.id()==ID_empty) | ||
{ | ||
new_expr=e; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(e, type); | ||
return true; | ||
} | ||
|
||
|
@@ -1930,8 +1910,7 @@ bool cpp_typecheckt::static_typecast( | |
e.type().id()==ID_unsignedbv || | ||
e.type().id()==ID_c_enum_tag)) | ||
{ | ||
new_expr=e; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(e, type); | ||
new_expr.remove(ID_C_lvalue); | ||
return true; | ||
} | ||
|
@@ -1966,9 +1945,8 @@ bool cpp_typecheckt::static_typecast( | |
|
||
if(from.id()==ID_empty) | ||
{ | ||
e.make_typecast(type); | ||
new_expr.swap(e); | ||
return true; | ||
new_expr = typecast_exprt::conditional_cast(e, type); | ||
return true; | ||
} | ||
|
||
if(to.id()==ID_struct && from.id()==ID_struct) | ||
|
@@ -2007,8 +1985,7 @@ bool cpp_typecheckt::static_typecast( | |
|
||
if(subtype_typecast(from_struct, to_struct)) | ||
{ | ||
new_expr=e; | ||
new_expr.make_typecast(type); | ||
new_expr = typecast_exprt::conditional_cast(e, type); | ||
return true; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,8 +576,7 @@ int linker_script_merget::ls_data2instructions( | |
unsigned_int_type().get_width()), | ||
unsigned_int_type()); | ||
|
||
exprt rhs_tc(rhs); | ||
rhs_tc.make_typecast(pointer_type(char_type())); | ||
typecast_exprt rhs_tc(rhs, pointer_type(char_type())); | ||
|
||
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. Same here 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. Done. |
||
linker_values.emplace( | ||
irep_idt(d["sym"].value), std::make_pair(lhs, rhs_tc)); | ||
|
@@ -640,8 +639,8 @@ int linker_script_merget::ls_data2instructions( | |
string2integer(d["val"].value), unsigned_int_type().get_width())); | ||
rhs.type()=unsigned_int_type(); | ||
|
||
exprt rhs_tc(rhs); | ||
rhs_tc.make_typecast(pointer_type(char_type())); | ||
exprt rhs_tc = | ||
typecast_exprt::conditional_cast(rhs, pointer_type(char_type())); | ||
|
||
linker_values.emplace( | ||
irep_idt(d["sym"].value), std::make_pair(lhs, rhs_tc)); | ||
|
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.