Skip to content

Small cleanup to remove use of assert() #2953

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
Sep 18, 2018
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
5 changes: 2 additions & 3 deletions src/goto-programs/class_identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static exprt build_class_identifier(
const typet &type=ns.follow(e.type());
const struct_typet &struct_type=to_struct_type(type);
const struct_typet::componentst &components=struct_type.components();
assert(!components.empty());
INVARIANT(!components.empty(), "class structs cannot be empty");

const auto &first_member_name=components.front().get_name();
member_exprt member_expr(
Expand Down Expand Up @@ -61,10 +61,9 @@ exprt get_class_identifier_field(
// Get a pointer from which we can extract a clsid.
// If it's already a pointer to an object of some sort, just use it;
// if it's void* then use the suggested type.
PRECONDITION(this_expr_in.type().id() == ID_pointer);

exprt this_expr=this_expr_in;
assert(this_expr.type().id()==ID_pointer &&
"Non-pointer this-arg in remove-virtuals?");
const auto &points_to=this_expr.type().subtype();
if(points_to==empty_typet())
this_expr=typecast_exprt(this_expr, pointer_type(suggested_type));
Expand Down
18 changes: 11 additions & 7 deletions src/goto-programs/compute_called_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ void compute_address_taken_functions(
forall_operands(it, src)
compute_address_taken_functions(*it, address_taken);

if(src.id()==ID_address_of &&
src.type().id()==ID_pointer &&
src.type().subtype().id()==ID_code)
if(src.id() == ID_address_of)
{
assert(src.operands().size()==1);
const exprt &op=src.op0();
if(op.id()==ID_symbol)
address_taken.insert(to_symbol_expr(op).get_identifier());
const address_of_exprt &address = to_address_of_expr(src);

if(
address.type().id() == ID_pointer &&
address.type().subtype().id() == ID_code)
{
const exprt &target = address.object();
if(target.id() == ID_symbol)
address_taken.insert(to_symbol_expr(target).get_identifier());
}
}
}

Expand Down