Skip to content

Pointer cleanup #1154

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 5 commits into from
Jul 20, 2017
Merged

Pointer cleanup #1154

merged 5 commits into from
Jul 20, 2017

Conversation

kroening
Copy link
Member

This is in preparation for giving pointers a width (much like integers), using constructors and a service function to produce pointer and reference types whenever appropriate.

Split off PR #970.

@kroening kroening mentioned this pull request Jul 19, 2017
@@ -327,8 +327,7 @@ bool ansi_c_entry_point(
zero_string.type().set(ID_size, "infinity");
exprt index(ID_index, char_type());
index.copy_to_operands(zero_string, from_integer(0, uint_type()));
exprt address_of("address_of", pointer_typet());
address_of.type().subtype()=char_type();
exprt address_of("address_of", pointer_type(char_type()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use address_of_exprt

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Happy to approve once pushed.

address_of.type().subtype()=object_tc.type();
address_of.copy_to_operands(object_tc);
exprt address_of=
address_of_exprt(object_tc, pointer_type(object_tc.type()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

address_of_exprt address_of(object_tc...);

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

address_of.type().subtype()=object.type();
address_of.copy_to_operands(object);
exprt address_of=
address_of_exprt(object, pointer_type(object.type()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

index_exprt index(
expr,
from_integer(0, index_type()),
expr.type().subtype());
Copy link
Collaborator

Choose a reason for hiding this comment

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

The third argument is not necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

expr_pfrom, pto, expr_ptmp, tmp_rank))
// try derived-to-base conversion
exprt expr_pfrom=
address_of_exprt(expr, pointer_type(expr.type()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

addres_of_exprt expr_pfrom...

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -67,7 +67,9 @@ void goto_symext::initialize_auto_object(
// could be NULL nondeterministically

address_of_exprt address_of_expr=
address_of_exprt(make_auto_object(type.subtype()));
address_of_exprt(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use constructor, not assignment

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected]

#include <util/namespace.h>
#include <util/std_expr.h>
#include <util/c_types.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit picking as above

@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected]
#include <util/arith_tools.h>
#include <util/ieee_float.h>
#include <util/simplify_expr.h>
#include <util/c_types.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit picking as above

@@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
#include <util/base_type.h>
#include <util/string2int.h>
#include <util/invariant.h>
#include <util/c_types.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit picking as above


\*******************************************************************/

address_of_exprt::address_of_exprt(const exprt &_op):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this actually being used? Most (all?) calls above appear to use a two-argument constructor

Copy link
Member Author

Choose a reason for hiding this comment

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

Now using it more.

@kroening kroening force-pushed the pointer-cleanup branch 2 times, most recently from 894a5b3 to c73ee7a Compare July 20, 2017 09:54

if(argv_symbol.type.subtype()!=address_of.type())
address_of.make_typecast(argv_symbol.type.subtype());

// assign argv[*] to the address of a string-object
exprt array_of("array_of", argv_symbol.type);
array_of.copy_to_operands(address_of);
exprt array_of=array_of_exprt(address_of, argv_symbol.type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could use array_of_exprt array_of(... here


exprt index_expr(ID_index, arg1.type().subtype());
exprt index_expr(ID_index, pointer_type.subtype());
Copy link
Collaborator

Choose a reason for hiding this comment

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

index_exprt index_expr(...) and the lines below should be eliminated


exprt index_expr(ID_index, arg2.type().subtype());
exprt index_expr(ID_index, pointer_type.subtype());
Copy link
Collaborator

Choose a reason for hiding this comment

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

index_exprt index_expr(... and again code below to be eliminated

@@ -1715,10 +1698,9 @@ bool cpp_typecheckt::const_typecast(
if(new_expr.type()!=type.subtype())
return false;

exprt address_of(ID_address_of, type);
address_of.copy_to_operands(expr);
exprt address_of=address_of_exprt(expr, to_pointer_type(type));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be a candidate for address_of_exprt address_of(...

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately not, as this might turn into a dereference expression.

@@ -825,14 +825,12 @@ void string_instrumentationt::do_strerror(
}

// return a pointer to some magic buffer
exprt index=exprt(ID_index, char_type());
index.copy_to_operands(
exprt index=index_exprt(
Copy link
Collaborator

Choose a reason for hiding this comment

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

index_exprt index(...

@tautschnig tautschnig merged commit f8b8f9e into master Jul 20, 2017
@tautschnig tautschnig deleted the pointer-cleanup branch July 20, 2017 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants