Skip to content

Commit c9eb13a

Browse files
authored
Merge pull request #5360 from danpoe/fixes/nondet-volatile
Fix --nondet-volatile bug
2 parents d58ebd8 + ff4a7b6 commit c9eb13a

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
3+
void main()
4+
{
5+
int a[2] = {0};
6+
7+
volatile int i = 0;
8+
a[i] = 1;
9+
10+
assert(a[1] == 0); // should fail
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
test.c
3+
--nondet-volatile
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
--
7+
--
8+
Check that volatile variables appearing in the lhs of an assignment are
9+
correctly treated as nondet

src/goto-instrument/nondet_volatile.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static bool is_volatile(const namespacet &ns, const typet &src)
3131
return false;
3232
}
3333

34-
void nondet_volatile_rhs(const symbol_tablet &symbol_table, exprt &expr)
34+
static void nondet_volatile_rhs(const symbol_tablet &symbol_table, exprt &expr)
3535
{
3636
Forall_operands(it, expr)
3737
nondet_volatile_rhs(symbol_table, *it);
@@ -52,7 +52,7 @@ void nondet_volatile_rhs(const symbol_tablet &symbol_table, exprt &expr)
5252
}
5353
}
5454

55-
void nondet_volatile_lhs(const symbol_tablet &symbol_table, exprt &expr)
55+
static void nondet_volatile_lhs(const symbol_tablet &symbol_table, exprt &expr)
5656
{
5757
if(expr.id()==ID_if)
5858
{
@@ -75,9 +75,8 @@ void nondet_volatile_lhs(const symbol_tablet &symbol_table, exprt &expr)
7575
}
7676
}
7777

78-
void nondet_volatile(
79-
symbol_tablet &symbol_table,
80-
goto_programt &goto_program)
78+
static void
79+
nondet_volatile(symbol_tablet &symbol_table, goto_programt &goto_program)
8180
{
8281
namespacet ns(symbol_table);
8382

@@ -88,7 +87,7 @@ void nondet_volatile(
8887
if(instruction.is_assign())
8988
{
9089
nondet_volatile_rhs(symbol_table, to_code_assign(instruction.code).rhs());
91-
nondet_volatile_lhs(symbol_table, to_code_assign(instruction.code).rhs());
90+
nondet_volatile_lhs(symbol_table, to_code_assign(instruction.code).lhs());
9291
}
9392
else if(instruction.is_function_call())
9493
{

src/goto-instrument/nondet_volatile.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <goto-programs/goto_model.h>
1616

17-
bool is_volatile(
18-
const symbol_tablet &,
19-
const typet &);
20-
2117
void nondet_volatile(goto_modelt &);
2218

2319
#endif // CPROVER_GOTO_INSTRUMENT_NONDET_VOLATILE_H

0 commit comments

Comments
 (0)