Skip to content

Commit 10f3476

Browse files
committed
Lift alloca's deallocation behaviour out of goto_check_ct
alloca always results in deallocation taking place, and not just when pointer checks are enabled.
1 parent 868a035 commit 10f3476

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

src/ansi-c/goto_check_c.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,28 +2188,6 @@ void goto_check_ct::goto_check(
21882188
std::move(lhs), std::move(rhs), i.source_location()));
21892189
t->code_nonconst().add_source_location() = i.source_location();
21902190
}
2191-
2192-
if(
2193-
variable.type().id() == ID_pointer &&
2194-
function_identifier != "alloca" &&
2195-
(ns.lookup(variable.get_identifier()).base_name ==
2196-
"return_value___builtin_alloca" ||
2197-
ns.lookup(variable.get_identifier()).base_name ==
2198-
"return_value_alloca"))
2199-
{
2200-
// mark pointer to alloca result as dead
2201-
exprt lhs = ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr();
2202-
exprt alloca_result =
2203-
typecast_exprt::conditional_cast(variable, lhs.type());
2204-
if_exprt rhs(
2205-
side_effect_expr_nondett(bool_typet(), i.source_location()),
2206-
std::move(alloca_result),
2207-
lhs);
2208-
goto_programt::targett t =
2209-
new_code.add(goto_programt::make_assignment(
2210-
std::move(lhs), std::move(rhs), i.source_location()));
2211-
t->code_nonconst().add_source_location() = i.source_location();
2212-
}
22132191
}
22142192
}
22152193
else if(i.is_end_function())

src/goto-programs/builtin_functions.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,38 @@ void goto_convertt::do_function_call_symbol(
13891389

13901390
copy(function_call, FUNCTION_CALL, dest);
13911391
}
1392+
else if(identifier == "alloca" || identifier == "__builtin_alloca")
1393+
{
1394+
if(lhs.is_nil())
1395+
{
1396+
// this will trigger a recursive call
1397+
side_effect_expr_function_callt call{
1398+
function, arguments, function.type(), function.source_location()};
1399+
make_temp_symbol(call, "alloca", dest, mode);
1400+
}
1401+
else
1402+
{
1403+
code_function_callt function_call(lhs, function, arguments);
1404+
function_call.add_source_location() = function.source_location();
1405+
copy(function_call, FUNCTION_CALL, dest);
1406+
1407+
exprt new_lhs = lhs;
1408+
make_temp_symbol(new_lhs, "alloca", dest, mode);
1409+
1410+
// mark pointer to alloca result as dead
1411+
symbol_exprt dead_object_sym =
1412+
ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr();
1413+
exprt alloca_result =
1414+
typecast_exprt::conditional_cast(new_lhs, dead_object_sym.type());
1415+
if_exprt rhs{
1416+
side_effect_expr_nondett{bool_typet(), function.source_location()},
1417+
std::move(alloca_result),
1418+
dead_object_sym};
1419+
code_assignt assign{std::move(dead_object_sym), std::move(rhs)};
1420+
assign.add_source_location() = function.source_location();
1421+
targets.destructor_stack.add(assign);
1422+
}
1423+
}
13921424
else
13931425
{
13941426
do_function_call_symbol(*symbol);

0 commit comments

Comments
 (0)