Skip to content

Commit fb583b4

Browse files
committed
Restrict function pointers: update goto program
Maintain goto-program invariants when modifying a program via function-pointer restrictions.
1 parent 79fafbe commit fb583b4

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/goto-programs/restrict_function_pointers.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void for_each_function_call(GotoFunctionT &&goto_function, Handler handler)
3535
handler);
3636
}
3737

38-
static void restrict_function_pointer(
38+
[[nodiscard]] static bool restrict_function_pointer(
3939
message_handlert &message_handler,
4040
symbol_tablet &symbol_table,
4141
goto_programt &goto_program,
@@ -54,7 +54,7 @@ static void restrict_function_pointer(
5454
const auto &original_function = location->call_function();
5555

5656
if(!can_cast_expr<dereference_exprt>(original_function))
57-
return;
57+
return false;
5858

5959
// because we run the label function pointer calls transformation pass before
6060
// this stage a dereference can only dereference a symbol expression
@@ -66,7 +66,7 @@ static void restrict_function_pointer(
6666
restrictions.restrictions.find(pointer_symbol.get_identifier());
6767

6868
if(restriction_iterator == restrictions.restrictions.end())
69-
return;
69+
return false;
7070

7171
const namespacet ns(symbol_table);
7272
std::unordered_set<symbol_exprt, irep_hash> candidates;
@@ -80,6 +80,8 @@ static void restrict_function_pointer(
8080
function_id,
8181
location,
8282
candidates);
83+
84+
return true;
8385
}
8486
} // namespace
8587

@@ -180,15 +182,19 @@ void restrict_function_pointers(
180182
{
181183
goto_functiont &goto_function = function_item.second;
182184

185+
bool did_something = false;
183186
for_each_function_call(goto_function, [&](const goto_programt::targett it) {
184-
restrict_function_pointer(
187+
did_something |= restrict_function_pointer(
185188
message_handler,
186189
goto_model.symbol_table,
187190
goto_function.body,
188191
function_item.first,
189192
restrictions,
190193
it);
191194
});
195+
196+
if(did_something)
197+
goto_function.body.update();
192198
}
193199
}
194200

0 commit comments

Comments
 (0)