Skip to content

Commit 84d272f

Browse files
committed
goto-instrument: replace "modifies" by "assigns" terminology
All this code collects assignments rather than checking for genuine value changes (modifications). Fixes: #6467
1 parent fd41b5e commit 84d272f

13 files changed

+120
-127
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
256+
assignst assigns;
257257
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,7 @@ void code_contractst::check_apply_loop_contracts(
271271
}
272272
else
273273
{
274-
modifies.insert(
274+
assigns.insert(
275275
assigns_clause.operands().cbegin(), assigns_clause.operands().cend());
276276

277277
// Create snapshots of write set CARs.
@@ -288,7 +288,7 @@ void code_contractst::check_apply_loop_contracts(
288288
function_name, goto_function.body, loop_head, loop_end, loop_assigns);
289289
}
290290

291-
havoc_assigns_targetst havoc_gen(modifies, ns);
291+
havoc_assigns_targetst havoc_gen(assigns, ns);
292292
havoc_gen.append_full_havoc_code(
293293
loop_head->source_location(), generated_code);
294294

@@ -755,10 +755,10 @@ bool code_contractst::apply_function_contract(
755755
targets.operands(), log, ns, target_function, symbol_table);
756756

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

761-
havoc_assigns_targetst havoc_gen(modifies, ns);
761+
havoc_assigns_targetst havoc_gen(assigns, ns);
762762
havoc_gen.append_full_havoc_code(location, havoc_instructions);
763763
}
764764

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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
/*******************************************************************\
22
3-
Module: Modifies
3+
Module: Compute objects assigned to in a function
44
55
Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

99
/// \file
10-
/// Modifies
10+
/// Compute objects assigned to in a function.
1111

12-
#include "function_modifies.h"
12+
#include "function_assigns.h"
1313

1414
#include <util/std_expr.h>
1515

1616
#include <analyses/local_may_alias.h>
1717

1818
#include "loop_utils.h"
1919

20-
void function_modifiest::get_modifies(
20+
void function_assignst::get_assigns(
2121
const local_may_aliast &local_may_alias,
2222
const goto_programt::const_targett i_it,
23-
modifiest &modifies)
23+
assignst &assigns)
2424
{
2525
const goto_programt::instructiont &instruction=*i_it;
2626

2727
if(instruction.is_assign())
2828
{
29-
get_modifies_lhs(local_may_alias, i_it, instruction.assign_lhs(), modifies);
29+
get_assigns_lhs(local_may_alias, i_it, instruction.assign_lhs(), assigns);
3030
}
3131
else if(instruction.is_function_call())
3232
{
3333
const exprt &lhs = instruction.call_lhs();
3434

3535
// return value assignment
3636
if(lhs.is_not_nil())
37-
get_modifies_lhs(local_may_alias, i_it, lhs, modifies);
37+
get_assigns_lhs(local_may_alias, i_it, lhs, assigns);
3838

39-
get_modifies_function(instruction.call_function(), modifies);
39+
get_assigns_function(instruction.call_function(), assigns);
4040
}
4141
}
4242

43-
void function_modifiest::get_modifies_function(
43+
void function_assignst::get_assigns_function(
4444
const exprt &function,
45-
modifiest &modifies)
45+
assignst &assigns)
4646
{
4747
if(function.id()==ID_symbol)
4848
{
@@ -54,7 +54,7 @@ void function_modifiest::get_modifies_function(
5454
if(fm_it!=function_map.end())
5555
{
5656
// already done
57-
modifies.insert(fm_it->second.begin(), fm_it->second.end());
57+
assigns.insert(fm_it->second.begin(), fm_it->second.end());
5858
return;
5959
}
6060

@@ -69,11 +69,11 @@ void function_modifiest::get_modifies_function(
6969
const goto_programt &goto_program=f_it->second.body;
7070

7171
forall_goto_program_instructions(i_it, goto_program)
72-
get_modifies(local_may_alias, i_it, modifies);
72+
get_assigns(local_may_alias, i_it, assigns);
7373
}
7474
else if(function.id()==ID_if)
7575
{
76-
get_modifies_function(to_if_expr(function).true_case(), modifies);
77-
get_modifies_function(to_if_expr(function).false_case(), modifies);
76+
get_assigns_function(to_if_expr(function).true_case(), assigns);
77+
get_assigns_function(to_if_expr(function).false_case(), assigns);
7878
}
7979
}
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.h

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

src/goto-instrument/havoc_loops.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include <goto-programs/remove_skip.h>
1818

19-
#include "function_modifies.h"
19+
#include "function_assigns.h"
2020
#include "havoc_utils.h"
2121
#include "loop_utils.h"
2222

@@ -26,23 +26,23 @@ class havoc_loopst
2626
typedef goto_functionst::goto_functiont goto_functiont;
2727

2828
havoc_loopst(
29-
function_modifiest &_function_modifies,
30-
goto_functiont &_goto_function):
31-
goto_function(_goto_function),
32-
local_may_alias(_goto_function),
33-
function_modifies(_function_modifies),
34-
natural_loops(_goto_function.body)
29+
function_assignst &_function_assigns,
30+
goto_functiont &_goto_function)
31+
: goto_function(_goto_function),
32+
local_may_alias(_goto_function),
33+
function_assigns(_function_assigns),
34+
natural_loops(_goto_function.body)
3535
{
3636
havoc_loops();
3737
}
3838

3939
protected:
4040
goto_functiont &goto_function;
4141
local_may_aliast local_may_alias;
42-
function_modifiest &function_modifies;
42+
function_assignst &function_assigns;
4343
natural_loops_mutablet natural_loops;
4444

45-
typedef std::set<exprt> modifiest;
45+
typedef std::set<exprt> assignst;
4646
typedef const natural_loops_mutablet::natural_loopt loopt;
4747

4848
void havoc_loops();
@@ -51,9 +51,7 @@ class havoc_loopst
5151
const goto_programt::targett loop_head,
5252
const loopt &);
5353

54-
void get_modifies(
55-
const loopt &,
56-
modifiest &);
54+
void get_assigns(const loopt &, assignst &);
5755
};
5856

5957
void havoc_loopst::havoc_loop(
@@ -63,12 +61,12 @@ void havoc_loopst::havoc_loop(
6361
assert(!loop.empty());
6462

6563
// first find out what can get changed in the loop
66-
modifiest modifies;
67-
get_modifies(loop, modifies);
64+
assignst assigns;
65+
get_assigns(loop, assigns);
6866

6967
// build the havocking code
7068
goto_programt havoc_code;
71-
havoc_utilst havoc_gen(modifies);
69+
havoc_utilst havoc_gen(assigns);
7270
havoc_gen.append_full_havoc_code(loop_head->source_location(), havoc_code);
7371

7472
// Now havoc at the loop head. Use insert_swap to
@@ -101,12 +99,10 @@ void havoc_loopst::havoc_loop(
10199
remove_skip(goto_function.body);
102100
}
103101

104-
void havoc_loopst::get_modifies(
105-
const loopt &loop,
106-
modifiest &modifies)
102+
void havoc_loopst::get_assigns(const loopt &loop, assignst &assigns)
107103
{
108104
for(const auto &instruction_it : loop)
109-
function_modifies.get_modifies(local_may_alias, instruction_it, modifies);
105+
function_assigns.get_assigns(local_may_alias, instruction_it, assigns);
110106
}
111107

112108
void havoc_loopst::havoc_loops()
@@ -119,8 +115,8 @@ void havoc_loopst::havoc_loops()
119115

120116
void havoc_loops(goto_modelt &goto_model)
121117
{
122-
function_modifiest function_modifies(goto_model.goto_functions);
118+
function_assignst function_assigns(goto_model.goto_functions);
123119

124120
for(auto &gf_entry : goto_model.goto_functions.function_map)
125-
havoc_loopst(function_modifies, gf_entry.second);
121+
havoc_loopst(function_assigns, gf_entry.second);
126122
}

src/goto-instrument/havoc_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void havoc_utilst::append_full_havoc_code(
2222
const source_locationt location,
2323
goto_programt &dest) const
2424
{
25-
for(const auto &expr : modifies)
25+
for(const auto &expr : assigns)
2626
append_havoc_code_for_expr(location, expr, dest);
2727
}
2828

0 commit comments

Comments
 (0)