Skip to content

Remove unnecessary use of ns.follow in goto-programs/ #3761

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

Merged
merged 1 commit into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ exprt goto_convertt::get_array_argument(const exprt &src)

assert(src.op0().operands().size()==2);

if(ns.follow(src.op0().op0().type()).id()!=ID_array)
if(src.op0().op0().type().id() != ID_array)
{
error().source_location=src.find_source_location();
error() << "expected array as argument" << eom;
Expand Down Expand Up @@ -1188,7 +1188,7 @@ void goto_convertt::do_function_call_symbol(
}

// our __builtin_va_list is a pointer
if(ns.follow(dest_expr.type()).id()==ID_pointer)
if(dest_expr.type().id() == ID_pointer)
{
goto_programt::targett t=dest.add_instruction(ASSIGN);
t->source_location=function.source_location();
Expand Down
6 changes: 3 additions & 3 deletions src/goto-programs/goto_convert_side_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void goto_convertt::remove_assignment(

exprt rhs;

const typet &op0_type=ns.follow(expr.op0().type());
const typet &op0_type = expr.op0().type();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the test at line 108 would therefore have been unreachable prior to this change -- but evidently our tests did not reveal that. Add a test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not only was dead code, it actually still is dead code: the front-end already introduces type casts (both the C and C++ front-ends take care of this). I have, in a second commit, removed the dead code and added a PRECONDITION in the else case.


if(op0_type.id()==ID_c_bool)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ void goto_convertt::remove_pre(
else
rhs.id(ID_minus);

const typet &op_type=ns.follow(expr.op0().type());
const typet &op_type = expr.op0().type();

if(op_type.id()==ID_bool)
{
Expand Down Expand Up @@ -257,7 +257,7 @@ void goto_convertt::remove_post(
else
rhs.id(ID_minus);

const typet &op_type=ns.follow(expr.op0().type());
const typet &op_type = expr.op0().type();

if(op_type.id()==ID_bool)
{
Expand Down
6 changes: 3 additions & 3 deletions src/goto-programs/goto_inline_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void goto_inlinet::parameter_assignments(
for(const auto &parameter : parameter_types)
{
// this is the type the n-th argument should be
const typet &par_type=ns.follow(parameter.type());
const typet &par_type = parameter.type();

const irep_idt &identifier=parameter.get_identifier();

Expand Down Expand Up @@ -95,8 +95,8 @@ void goto_inlinet::parameter_assignments(
// subject to some exceptions
if(!base_type_eq(par_type, actual.type(), ns))
{
const typet &f_partype=ns.follow(par_type);
const typet &f_acttype=ns.follow(actual.type());
const typet &f_partype = par_type;
const typet &f_acttype = actual.type();

// we are willing to do some conversion
if((f_partype.id()==ID_pointer &&
Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/goto_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ std::string trace_numeric_value(
const namespacet &ns,
const trace_optionst &options)
{
const typet &type=ns.follow(expr.type());
const typet &type = expr.type();

if(expr.id()==ID_constant)
{
Expand Down
3 changes: 1 addition & 2 deletions src/goto-programs/graphml_witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ std::string graphml_witnesst::convert_assign_rec(

if(assign.rhs().id()==ID_array)
{
const array_typet &type=
to_array_type(ns.follow(assign.rhs().type()));
const array_typet &type = to_array_type(assign.rhs().type());

unsigned i=0;
forall_operands(it, assign.rhs())
Expand Down
4 changes: 3 additions & 1 deletion src/goto-programs/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,9 @@ exprt interpretert::get_value(
if(offset_from_address == 0)
return address_of_exprt(symbol_expr);

if(ns.follow(type_from_identifier).id() == ID_struct)
if(
type_from_identifier.id() == ID_struct ||
type_from_identifier.id() == ID_struct_tag)
{
const auto c = get_component(identifier, offset_from_address);
member_exprt member_expr(symbol_expr, c);
Expand Down
6 changes: 2 additions & 4 deletions src/goto-programs/remove_function_pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ bool remove_function_pointerst::is_type_compatible(
void remove_function_pointerst::fix_argument_types(
code_function_callt &function_call)
{
const code_typet &code_type=
to_code_type(ns.follow(function_call.function().type()));
const code_typet &code_type = to_code_type(function_call.function().type());

const code_typet::parameterst &function_parameters=
code_type.parameters();
Expand Down Expand Up @@ -232,8 +231,7 @@ void remove_function_pointerst::fix_return_type(
if(function_call.lhs().is_nil())
return;

const code_typet &code_type=
to_code_type(ns.follow(function_call.function().type()));
const code_typet &code_type = to_code_type(function_call.function().type());

// type already ok?
if(type_eq(
Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/string_abstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ goto_programt::targett string_abstractiont::abstract_assign(
if(has_string_macros(rhs))
replace_string_macros(rhs, false, target->source_location);

const typet &type=ns.follow(lhs.type());
const typet &type = lhs.type();
if(type.id()==ID_pointer || type.id()==ID_array)
return abstract_pointer_assign(dest, target);
else if(is_char_type(type))
Expand Down
3 changes: 0 additions & 3 deletions src/goto-programs/string_abstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class string_abstractiont:public messaget

bool is_char_type(const typet &type) const
{
if(type.id() == ID_struct_tag)
return is_char_type(ns.follow(type));

if(type.id()!=ID_signedbv &&
type.id()!=ID_unsignedbv)
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-programs/vcd_goto_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::string as_vcd_binary(
const exprt &expr,
const namespacet &ns)
{
const typet &type=ns.follow(expr.type());
const typet &type = expr.type();

if(expr.id()==ID_constant)
{
Expand Down