Skip to content

Commit 499ccf1

Browse files
author
Daniel Kroening
authored
Merge pull request #2953 from chrisr-diffblue/cleanup-goto-programs-c
Small cleanup to remove use of assert()
2 parents 13360bf + de0f7d2 commit 499ccf1

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/goto-programs/class_identifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static exprt build_class_identifier(
3030
const typet &type=ns.follow(e.type());
3131
const struct_typet &struct_type=to_struct_type(type);
3232
const struct_typet::componentst &components=struct_type.components();
33-
assert(!components.empty());
33+
INVARIANT(!components.empty(), "class structs cannot be empty");
3434

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

6566
exprt this_expr=this_expr_in;
66-
assert(this_expr.type().id()==ID_pointer &&
67-
"Non-pointer this-arg in remove-virtuals?");
6867
const auto &points_to=this_expr.type().subtype();
6968
if(points_to==empty_typet())
7069
this_expr=typecast_exprt(this_expr, pointer_type(suggested_type));

src/goto-programs/compute_called_functions.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ void compute_address_taken_functions(
2121
forall_operands(it, src)
2222
compute_address_taken_functions(*it, address_taken);
2323

24-
if(src.id()==ID_address_of &&
25-
src.type().id()==ID_pointer &&
26-
src.type().subtype().id()==ID_code)
24+
if(src.id() == ID_address_of)
2725
{
28-
assert(src.operands().size()==1);
29-
const exprt &op=src.op0();
30-
if(op.id()==ID_symbol)
31-
address_taken.insert(to_symbol_expr(op).get_identifier());
26+
const address_of_exprt &address = to_address_of_expr(src);
27+
28+
if(
29+
address.type().id() == ID_pointer &&
30+
address.type().subtype().id() == ID_code)
31+
{
32+
const exprt &target = address.object();
33+
if(target.id() == ID_symbol)
34+
address_taken.insert(to_symbol_expr(target).get_identifier());
35+
}
3236
}
3337
}
3438

0 commit comments

Comments
 (0)