Skip to content

Commit 6030b9e

Browse files
author
Daniel Kroening
authored
Merge pull request #3279 from tautschnig/array-is-uniform
Simplify and modernise array-is-uniform code
2 parents 6656cec + 6590a7e commit 6030b9e

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

regression/cbmc/uniform_array1/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main()
2+
{
3+
int A[] = {1, 1};
4+
int i;
5+
__CPROVER_assert(i < 0 || i > 1 || A[i] == 1, "valid access into array of 1");
6+
__CPROVER_assert(A[i] == 1, "possible out-of-bounds access");
7+
return 0;
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\*\* 1 of 2 failed
8+
--
9+
^warning: ignoring

scripts/delete_failing_smt2_solver_tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ rm trace_options_json_extended/non-extended.desc
301301
rm trace_show_code/test.desc
302302
rm trace_show_function_calls/test.desc
303303
rm uncaught_exceptions_analysis1/test.desc
304+
rm uniform_array1/test.desc
304305
rm union11/union_list.desc
305306
rm union3/test.desc
306307
rm union5/test.desc

src/solvers/flattening/boolbv_index.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "boolbv.h"
1010

11-
#include <cassert>
11+
#include <algorithm>
1212

1313
#include <util/arith_tools.h>
1414
#include <util/cprover_prefix.h>
@@ -80,26 +80,16 @@ bvt boolbvt::convert_index(const index_exprt &expr)
8080
// this rather than as a series of individual options.
8181
#define UNIFORM_ARRAY_HACK
8282
#ifdef UNIFORM_ARRAY_HACK
83-
bool is_uniform = false;
83+
bool is_uniform = array.id() == ID_array_of;
8484

85-
if(array.id()==ID_array_of)
85+
if(array.id() == ID_constant || array.id() == ID_array)
8686
{
87-
is_uniform = true;
88-
}
89-
else if(array.id()==ID_constant || array.id()==ID_array)
90-
{
91-
bool found_exception = false;
92-
forall_expr(it, array.operands())
93-
{
94-
if(*it != array.op0())
95-
{
96-
found_exception = true;
97-
break;
98-
}
99-
}
100-
101-
if(!found_exception)
102-
is_uniform = true;
87+
is_uniform =
88+
array.operands().size() <= 1 ||
89+
std::all_of(
90+
++array.operands().begin(),
91+
array.operands().end(),
92+
[&array](const exprt &expr) { return expr == array.op0(); });
10393
}
10494

10595
if(is_uniform && prop.has_set_to())

0 commit comments

Comments
 (0)