Skip to content

Commit f046844

Browse files
authored
Merge pull request #6504 from tautschnig/modifies-to-assigns
goto-instrument: replace "modifies" by "assigns" terminology
2 parents d0c403a + 171d0c2 commit f046844

14 files changed

+193
-200
lines changed

src/goto-instrument/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ SRC = accelerate/accelerate.cpp \
3838
dump_c.cpp \
3939
full_slicer.cpp \
4040
function.cpp \
41-
function_modifies.cpp \
41+
function_assigns.cpp \
4242
generate_function_bodies.cpp \
4343
goto_instrument_languages.cpp \
4444
goto_instrument_main.cpp \

src/goto-instrument/contracts/assigns.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class assigns_clauset
118118
class havoc_assigns_targetst : public havoc_if_validt
119119
{
120120
public:
121-
havoc_assigns_targetst(const modifiest &mod, const namespacet &ns)
121+
havoc_assigns_targetst(const assignst &mod, const namespacet &ns)
122122
: havoc_if_validt(mod, ns)
123123
{
124124
}

src/goto-instrument/contracts/contracts.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@ void code_contractst::check_apply_loop_contracts(
150150
loop_end = t;
151151

152152
// check for assigns, invariant, and decreases clauses
153-
auto assigns = static_cast<const exprt &>(
153+
auto assigns_clause = static_cast<const exprt &>(
154154
loop_end->get_condition().find(ID_C_spec_assigns));
155155
auto invariant = static_cast<const exprt &>(
156156
loop_end->get_condition().find(ID_C_spec_loop_invariant));
157157
auto decreases_clause = static_cast<const exprt &>(
158158
loop_end->get_condition().find(ID_C_spec_decreases));
159159

160160
assigns_clauset loop_assigns(
161-
assigns.operands(), log, ns, function_name, symbol_table);
161+
assigns_clause.operands(), log, ns, function_name, symbol_table);
162162

163163
loop_assigns.add_static_locals_to_write_set(goto_functions, function_name);
164164

165165
if(invariant.is_nil())
166166
{
167-
if(decreases_clause.is_nil() && assigns.is_nil())
167+
if(decreases_clause.is_nil() && assigns_clause.is_nil())
168168
return;
169169
else
170170
{
@@ -253,12 +253,12 @@ void code_contractst::check_apply_loop_contracts(
253253
add_pragma_disable_assigns_check(generated_code));
254254

255255
// havoc the variables that may be modified
256-
modifiest modifies;
257-
if(assigns.is_nil())
256+
assignst assigns;
257+
if(assigns_clause.is_nil())
258258
{
259259
try
260260
{
261-
get_modifies(local_may_alias, loop, modifies);
261+
get_assigns(local_may_alias, loop, assigns);
262262
}
263263
catch(const analysis_exceptiont &exc)
264264
{
@@ -271,7 +271,8 @@ void code_contractst::check_apply_loop_contracts(
271271
}
272272
else
273273
{
274-
modifies.insert(assigns.operands().cbegin(), assigns.operands().cend());
274+
assigns.insert(
275+
assigns_clause.operands().cbegin(), assigns_clause.operands().cend());
275276

276277
// Create snapshots of write set CARs.
277278
// This must be done before havocing the write set.
@@ -287,13 +288,13 @@ void code_contractst::check_apply_loop_contracts(
287288
function_name, goto_function.body, loop_head, loop_end, loop_assigns);
288289
}
289290

290-
havoc_assigns_targetst havoc_gen(modifies, ns);
291+
havoc_assigns_targetst havoc_gen(assigns, ns);
291292
havoc_gen.append_full_havoc_code(
292293
loop_head->source_location(), generated_code);
293294

294295
// Add the havocing code, but only check against the enclosing scope's
295296
// write set if it was manually specified.
296-
if(assigns.is_nil())
297+
if(assigns_clause.is_nil())
297298
insert_before_swap_and_advance(
298299
goto_function.body,
299300
loop_head,
@@ -624,7 +625,7 @@ bool code_contractst::apply_function_contract(
624625
const auto &type = to_code_with_contract_type(function_symbol.type);
625626

626627
// Isolate each component of the contract.
627-
auto assigns = type.assigns();
628+
auto assigns_clause = type.assigns();
628629
auto requires = conjunction(type.requires());
629630
auto ensures = conjunction(type.ensures());
630631

@@ -740,24 +741,24 @@ bool code_contractst::apply_function_contract(
740741
// ASSIGNS clause should not refer to any quantified variables,
741742
// and only refer to the common symbols to be replaced.
742743
exprt targets;
743-
for(auto &target : assigns)
744+
for(auto &target : assigns_clause)
744745
targets.add_to_operands(std::move(target));
745746
common_replace(targets);
746747

747748
// Create a sequence of non-deterministic assignments...
748749
goto_programt havoc_instructions;
749750

750751
// ...for assigns clause targets
751-
if(!assigns.empty())
752+
if(!assigns_clause.empty())
752753
{
753754
assigns_clauset assigns_clause(
754755
targets.operands(), log, ns, target_function, symbol_table);
755756

756757
// Havoc all targets in the write set
757-
modifiest modifies;
758-
modifies.insert(targets.operands().cbegin(), targets.operands().cend());
758+
assignst assigns;
759+
assigns.insert(targets.operands().cbegin(), targets.operands().cend());
759760

760-
havoc_assigns_targetst havoc_gen(modifies, ns);
761+
havoc_assigns_targetst havoc_gen(assigns, ns);
761762
havoc_gen.append_full_havoc_code(location, havoc_instructions);
762763
}
763764

src/goto-instrument/contracts/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Date: September 2021
2525
class havoc_if_validt : public havoc_utilst
2626
{
2727
public:
28-
havoc_if_validt(const modifiest &mod, const namespacet &ns)
28+
havoc_if_validt(const assignst &mod, const namespacet &ns)
2929
: havoc_utilst(mod), ns(ns)
3030
{
3131
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*******************************************************************\
2+
3+
Module: Compute objects assigned to in a function
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Compute objects assigned to in a function.
11+
12+
#include "function_assigns.h"
13+
14+
#include <util/std_expr.h>
15+
16+
#include <analyses/local_may_alias.h>
17+
18+
#include "loop_utils.h"
19+
20+
void function_assignst::get_assigns(
21+
const local_may_aliast &local_may_alias,
22+
const goto_programt::const_targett i_it,
23+
assignst &assigns)
24+
{
25+
const goto_programt::instructiont &instruction = *i_it;
26+
27+
if(instruction.is_assign())
28+
{
29+
get_assigns_lhs(local_may_alias, i_it, instruction.assign_lhs(), assigns);
30+
}
31+
else if(instruction.is_function_call())
32+
{
33+
const exprt &lhs = instruction.call_lhs();
34+
35+
// return value assignment
36+
if(lhs.is_not_nil())
37+
get_assigns_lhs(local_may_alias, i_it, lhs, assigns);
38+
39+
get_assigns_function(instruction.call_function(), assigns);
40+
}
41+
}
42+
43+
void function_assignst::get_assigns_function(
44+
const exprt &function,
45+
assignst &assigns)
46+
{
47+
if(function.id() == ID_symbol)
48+
{
49+
const irep_idt &identifier = to_symbol_expr(function).get_identifier();
50+
51+
function_mapt::const_iterator fm_it = function_map.find(identifier);
52+
53+
if(fm_it != function_map.end())
54+
{
55+
// already done
56+
assigns.insert(fm_it->second.begin(), fm_it->second.end());
57+
return;
58+
}
59+
60+
goto_functionst::function_mapt::const_iterator f_it =
61+
goto_functions.function_map.find(identifier);
62+
63+
if(f_it == goto_functions.function_map.end())
64+
return;
65+
66+
local_may_aliast local_may_alias(f_it->second);
67+
68+
const goto_programt &goto_program = f_it->second.body;
69+
70+
forall_goto_program_instructions(i_it, goto_program)
71+
get_assigns(local_may_alias, i_it, assigns);
72+
}
73+
else if(function.id() == ID_if)
74+
{
75+
get_assigns_function(to_if_expr(function).true_case(), assigns);
76+
get_assigns_function(to_if_expr(function).false_case(), assigns);
77+
}
78+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*******************************************************************\
2+
3+
Module: Compute objects assigned to in a function
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Compute objects assigned to in a function.
11+
12+
#ifndef CPROVER_GOTO_INSTRUMENT_FUNCTION_ASSIGNS_H
13+
#define CPROVER_GOTO_INSTRUMENT_FUNCTION_ASSIGNS_H
14+
15+
#include <goto-programs/goto_program.h>
16+
17+
#include <map>
18+
19+
class goto_functionst;
20+
class local_may_aliast;
21+
22+
class function_assignst
23+
{
24+
public:
25+
explicit function_assignst(const goto_functionst &_goto_functions)
26+
: goto_functions(_goto_functions)
27+
{
28+
}
29+
30+
typedef std::set<exprt> assignst;
31+
32+
void get_assigns(
33+
const local_may_aliast &local_may_alias,
34+
const goto_programt::const_targett,
35+
assignst &);
36+
37+
void get_assigns_function(const exprt &, assignst &);
38+
39+
void operator()(const exprt &function, assignst &assigns)
40+
{
41+
get_assigns_function(function, assigns);
42+
}
43+
44+
protected:
45+
const goto_functionst &goto_functions;
46+
47+
typedef std::map<irep_idt, assignst> function_mapt;
48+
function_mapt function_map;
49+
};
50+
51+
#endif // CPROVER_GOTO_INSTRUMENT_FUNCTION_ASSIGNS_H

src/goto-instrument/function_modifies.cpp

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/goto-instrument/function_modifies.h

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)